1994-08-12 10:52:49 +00:00
# include <stdio.h>
1995-07-04 14:06:19 +00:00
# include <stdlib.h>
1994-08-12 10:52:49 +00:00
# define __ISAM_CPP
1994-09-27 10:19:36 +00:00
# ifndef FOXPRO
1994-11-24 14:01:20 +00:00
# include <applicat.h>
1994-10-04 15:38:57 +00:00
# include <expr.h>
1994-11-24 14:01:20 +00:00
# include <execp.h>
1994-09-27 10:19:36 +00:00
# include <progind.h>
# endif
1994-11-24 14:01:20 +00:00
1994-09-27 10:19:36 +00:00
# include <config.h>
1994-08-12 10:52:49 +00:00
# include <extcdecl.h>
1995-07-03 07:49:30 +00:00
# include <mailbox.h>
1994-11-24 14:01:20 +00:00
# include <prefix.h>
# include <relation.h>
1994-09-27 10:19:36 +00:00
# include <scanner.h>
1995-07-03 07:49:30 +00:00
# include <utility.h>
1995-06-12 10:49:19 +00:00
# include <memo.h>
1995-07-03 07:49:30 +00:00
# include <codeb.h>
1995-04-10 15:28:03 +00:00
# if XVT_OS==XVT_OS_WIN
# include <process.h>
# else
1994-10-14 17:51:32 +00:00
# include <sys/types.h>
# include <sys/stat.h>
# include <unistd.h>
# endif
1994-08-12 10:52:49 +00:00
1995-04-10 15:28:03 +00:00
1994-08-12 10:52:49 +00:00
# define NOT_LINKED(i,f) CHECKS(i != NULL, "Record senza tracciato: impossibile eseguire ", f)
1995-04-10 15:28:03 +00:00
# define NOT_OPEN() CHECKS(_isamfile != NULL, "File chiuso: ", (const char*)name())
1995-07-05 14:38:49 +00:00
//#define INTTLOCK 0x600
1995-07-03 07:49:30 +00:00
# define RECLOCKTYPES 0xFF00
# define READTYPES 0x00FF
isfdptr * openf ;
Str80 cprefix ;
HIDDEN int error_codes_g [ ] = { - 1 , _isnotopen , - 1 , - 1 , - 1 , _islocked , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , _isfilefull ,
- 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , _iskeynotfound , _ispatherr , - 1 , - 1 , _isdupkey } ;
HIDDEN int error_codes_ra [ ] = { NOERR , NOERR , _iskeynotfound , _iseof , _isbof , _isnrecerr } ;
// Codici da 0 a 9
HIDDEN int error_codes_rb [ ] = { - 1 , - 1 , _isreinsert , - 1 , - 1 , _islocked , - 1 , _isalropen , _iskeyerr } ;
// Codici da 10 a ...
extern " C " {
void CUpString ( char * ) ;
void crtrim ( char * ) ;
} ;
1995-04-20 14:35:14 +00:00
HIDDEN char _isam_string [ 257 ] ;
1994-09-12 09:34:05 +00:00
HIDDEN void UNKNOWN_FIELD ( int num , const char * name )
{ yesnofatal_box ( " Il campo '%s' non appartiene al file %d " , name , num ) ; }
1994-08-12 10:52:49 +00:00
# define NOALLOC (char **) -1
1995-07-03 07:49:30 +00:00
HIDDEN bool __autoload = TRUE ;
////////////////////////////////////////////////////////////////////////////////////////////////////
// Funzioni implementate per la gestione file dati tramite Codebase
////////////////////////////////////////////////////////////////////////////////////////////////////
// Inizio(@)
void get_idx_names ( int logicnum , TToken_string & i_names ) // Returns a Token_string with the index names. (Current prefix!)
{
long c = DB_getconf ( ) ;
TDir d ;
TTrec r ;
d . get ( logicnum ) ;
r . get ( logicnum ) ;
TFilename f ( d . name ( ) ) ;
if ( c & 1 ) f . ext ( " cdx " ) ;
if ( c & 4 ) f . ext ( " mdx " ) ;
i_names . cut ( 0 ) ;
i_names . add ( f ) ;
f . ext ( " " ) ;
f . rtrim ( 1 ) ;
if ( c & 2 | | c & 8 ) // DBIII or CLIPPER format, returns f_name + .cgp, f_nameX + .n{d|t}x
for ( int j = 1 ; j < = r . keys ( ) ; j + + )
{
TString xx = f . name ( ) ;
if ( xx . len ( ) < 8 )
f < < ( ' 0 ' + j ) ;
else
f [ 8 ] = ( ' 0 ' + j ) ;
if ( c & 2 ) // CLIPPER
f . ext ( " ndx " ) ;
else // DBIII
f . ext ( " ntx " ) ;
i_names . add ( f ) ;
}
i_names . restart ( ) ;
}
int get_error ( int err )
{
if ( err > 0 )
{
if ( err > = 10 )
{
if ( err > 80 | | error_codes_rb [ err / 10 ] = = - 1 ) return err ;
else
return ( error_codes_rb [ err / 10 ] ) ;
}
else
return ( error_codes_ra [ err ] ) ;
}
else
if ( err < 0 )
{
int ierr = DB_get_error ( ) ;
if ( ierr < 0 ) ierr = - ierr ;
if ( ierr > 340 | | error_codes_g [ ierr / 10 ] = = - 1 ) return ( - ierr ) ;
return ( error_codes_g [ ierr / 10 ] ) ;
}
DB_zero_error ( ) ;
return ( NOERR ) ;
}
HIDDEN void browse_null ( char * start , int nc )
{
for ( int i = nc - 1 ; i > = 0 ; i - - ) // Anche il primo byte(deletion flag) deve essere cambiato. nc comprende il primo byte
if ( start [ i ] = = ' \0 ' ) start [ i ] = ' ' ;
}
HIDDEN void getisfd ( isfdptr & isfd , int logicnum )
{
isfd = new isdef ;
isfd - > r = new RecDes ;
isfd - > d = new FileDes ;
CGetFile ( logicnum , isfd - > d , _nolock , _nordir ) ;
const TFixed_string name ( isfd - > d - > SysName ) ;
1995-07-20 09:10:38 +00:00
if ( name . not_empty ( ) & & name [ 0 ] ! = ' $ ' )
1995-07-03 07:49:30 +00:00
isfd - > ft = _comdir ;
else
isfd - > ft = _nordir ;
COpenFile ( logicnum , isfd - > d , _nolock , isfd - > ft ) ;
CGetRec ( logicnum , isfd - > r , isfd - > ft ) ;
isfd - > ln = logicnum ;
}
HIDDEN void relisfd ( isfdptr & isfd )
{
if ( isfd - > ln > 0 & & isfd - > fhnd > = 0 )
{
TDir d ;
d . get ( isfd - > ln , _lock , ( TDirtype ) isfd - > ft , _sysdirop ) ;
d . eod ( ) = isfd - > d - > EOD ;
d . eox ( ) = isfd - > d - > EOX ;
d . put ( isfd - > ln , ( TDirtype ) isfd - > ft , _sysdirop ) ;
}
delete isfd - > d ;
delete isfd - > r ;
delete isfd ;
}
1995-07-05 11:12:13 +00:00
HIDDEN int CBuildKey ( RecDes * recd , int numkey , RecType recin , char * key , bool build_x_cb )
/* *recd; descrittore record */
/* numkey; numero chiave */
/* recin; buffer contenente il record */
/* *key; valore della chiave */
/* build_x_cb flag di costruzione per codebase */
1995-07-03 07:49:30 +00:00
{
1995-07-05 14:38:49 +00:00
key [ 0 ] = ' \0 ' ;
1995-07-03 07:49:30 +00:00
if ( numkey - - < = recd - > NKeys )
1995-07-05 14:38:49 +00:00
{
int l = 0 ;
for ( int i = 0 ; i < recd - > Ky [ numkey ] . NkFields ; i + + )
{
const KeyDes & kd = recd - > Ky [ numkey ] ;
const bool upp = kd . FieldSeq [ i ] > MaxFields ;
const int nf = upp ? kd . FieldSeq [ i ] - MaxFields : kd . FieldSeq [ i ] ;
const RecFieldDes & rf = recd - > Fd [ nf ] ;
int off , len ;
if ( kd . FromCh [ i ] = = 255 )
1995-07-03 07:49:30 +00:00
{
1995-07-05 14:38:49 +00:00
off = rf . RecOff ;
len = rf . Len ;
1995-07-03 07:49:30 +00:00
}
else
{
1995-07-05 14:38:49 +00:00
off = rf . RecOff + kd . FromCh [ i ] ;
len = kd . ToCh [ i ] - kd . FromCh [ i ] + 1 ;
1995-07-03 07:49:30 +00:00
}
if ( ( l + len ) > 80 )
{
1995-07-05 14:38:49 +00:00
key [ 0 ] = ' \0 ' ;
1995-07-03 07:49:30 +00:00
return ( _iskeylenerr ) ;
}
strncpy ( ( key + l ) , ( recin + off ) , len ) ;
1995-07-05 14:38:49 +00:00
const TFieldtypes f = ( TFieldtypes ) rf . TypeF ;
if ( recin [ off ] = = ' \0 ' )
{
memset ( key + l , ' ' , len ) ;
1995-07-19 09:57:25 +00:00
if ( build_x_cb & & ( ( f = = _intfld ) | | ( f = = _longfld ) | | ( f = = _wordfld ) | |
( f = = _intzerofld ) | | ( f = = _longzerofld ) ) )
1995-07-05 14:38:49 +00:00
key [ l + len - 1 ] = ' 0 ' ;
}
1995-07-03 07:49:30 +00:00
else
1995-07-19 09:57:25 +00:00
if ( ( f = = _intfld ) | | ( f = = _longfld ) | | ( f = = _wordfld ) | | ( f = = _intzerofld ) | | ( f = = _longzerofld ) )
1995-07-05 14:38:49 +00:00
{
1995-07-03 07:49:30 +00:00
int w = l , j = l + len ;
while ( w < j & & key [ w ] = = ' ' ) w + + ;
1995-07-06 15:05:23 +00:00
while ( w < j & & key [ w ] = = ' 0 ' ) key [ w + + ] = ' ' ;
if ( build_x_cb & & ( w = = j ) ) key [ w - 1 ] = ' 0 ' ;
}
1995-07-05 14:38:49 +00:00
if ( upp )
for ( int i = l + len - 1 ; i > = l ; i - - )
key [ i ] = toupper ( key [ i ] ) ;
1995-07-03 07:49:30 +00:00
l + = len ;
}
1995-07-05 14:38:49 +00:00
while ( l > 0 & & key [ l - 1 ] = = ' ' ) l - - ;
1995-07-03 07:49:30 +00:00
key [ l ] = ' \0 ' ;
1995-07-05 14:38:49 +00:00
1995-07-03 07:49:30 +00:00
return ( NOERR ) ;
}
return ( _ispatherr ) ;
}
HIDDEN int cisstart ( isfdptr isfd , int keynum , TRectype & record , unsigned int mode )
{
// It seems quite unuseful... Quando cambio la chiave con setkey, la d4tagselect
// seleziona gia' l'indice, rendendo inutile il senso della cisstart
return NOERR ;
}
HIDDEN int cisread ( isfdptr isfd , TRectype & record , int mode )
{
1995-07-05 14:38:49 +00:00
int rmode = ( mode & READTYPES ) , lmode = ( mode & RECLOCKTYPES ) ;
1995-07-03 07:49:30 +00:00
// Non usare mai _isnextn o _isprevn, usare il metodo skip!
1995-07-05 14:38:49 +00:00
CHECK ( rmode ! = _isnextn & & rmode ! = _isprevn , " _isnextn and _isprevn not supported in cisread " ) ;
1995-07-03 07:49:30 +00:00
1995-07-05 14:38:49 +00:00
// BOOLEAN nolock = (lmode == _nolock);
// BOOLEAN unlock = (lmode == _unlock);
// BOOLEAN tlock = (lmode == INTTLOCK);
1995-07-03 07:49:30 +00:00
char key [ 128 ] ;
int err = NOERR ;
1995-07-05 14:38:49 +00:00
// if (nolock || unlock /* || tlock */) lmode = 0;
1995-07-03 07:49:30 +00:00
do
{
if ( rmode > = _isequal & & rmode < = _isgteq )
{
1995-07-05 14:38:49 +00:00
err = CBuildKey ( isfd - > r , isfd - > knum , record . string ( ) , key , TRUE ) ;
1995-07-03 07:49:30 +00:00
if ( err = = NOERR )
{
err = DB_seek ( isfd - > fhnd , key ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
}
if ( rmode ! = _isequal & & err = = _iskeynotfound ) err = NOERR ;
}
1995-07-05 14:38:49 +00:00
else
{
if ( rmode = = _isfirst )
err = DB_first ( isfd - > fhnd ) ; else
if ( rmode = = _islast )
err = DB_last ( isfd - > fhnd ) ; else
if ( rmode = = _isnext )
err = DB_next ( isfd - > fhnd ) ; else
if ( rmode = = _isprev )
err = DB_prev ( isfd - > fhnd ) ; else
if ( rmode = = _iscurr )
err = DB_go ( isfd - > fhnd , DB_recno ( isfd - > fhnd ) ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
}
1995-07-04 14:06:19 +00:00
if ( err = = _iseof )
1995-07-03 07:49:30 +00:00
DB_last ( isfd - > fhnd ) ;
1995-07-04 07:31:04 +00:00
if ( err = = NOERR & & ( lmode = = _lock | | lmode = = _testandlock ) ) // _lock e _testandlock
{
err = DB_lock ( isfd - > fhnd ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
if ( err = = _islocked & & lmode = = _testandlock ) break ;
}
1995-07-05 14:38:49 +00:00
if ( /* !tlock && */ err = = _islocked )
1995-07-03 07:49:30 +00:00
{
1995-07-05 14:38:49 +00:00
memcpy ( record . string ( ) , DB_getrecord ( isfd - > fhnd ) , DB_reclen ( isfd - > fhnd ) ) ;
CBuildKey ( isfd - > r , isfd - > knum , record . string ( ) , key , TRUE ) ;
1995-07-03 07:49:30 +00:00
message_box ( " Codice %s in uso da parte \n di un altro utente. " , key ) ;
}
1995-07-05 14:38:49 +00:00
} while ( /* !tlock && */ err = = _islocked ) ;
if ( err = = NOERR & & lmode = = _unlock )
1995-07-03 07:49:30 +00:00
{
err = DB_unlock ( isfd - > fhnd ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
}
1995-07-05 14:38:49 +00:00
1995-07-05 08:03:00 +00:00
memcpy ( record . string ( ) , DB_getrecord ( isfd - > fhnd ) , DB_reclen ( isfd - > fhnd ) ) ;
1995-07-03 07:49:30 +00:00
isfd - > RecNo = DB_recno ( isfd - > fhnd ) ;
return err ;
}
HIDDEN int delkeys ( isfdptr fd , char * record , long recno )
{
1995-07-05 14:38:49 +00:00
int rt = NOERR , oldkey = fd - > knum ;
1995-07-03 07:49:30 +00:00
for ( int i = 1 ; i < = fd - > r - > NKeys ; i + + )
{
char key [ 128 ] ;
DB_tagselect ( fd - > fhnd , i ) ;
1995-07-05 11:12:13 +00:00
rt = CBuildKey ( fd - > r , i , record , key , TRUE ) ;
1995-07-03 07:49:30 +00:00
if ( rt ! = NOERR ) break ;
rt = DB_delkey ( fd - > fhnd , key , recno ) ;
if ( rt ! = NOERR ) break ;
}
DB_tagselect ( fd - > fhnd , oldkey ) ;
return ( rt ) ;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Funzioni implementate per la gestione file dati tramite Codebase
////////////////////////////////////////////////////////////////////////////////////////////////////
// Fine(@)
1994-10-31 16:24:26 +00:00
void set_autoload_new_files ( bool on )
{
__autoload = on ;
}
1995-02-10 17:42:33 +00:00
///////////////////////////////////////////////////////////
// TExtrectype
///////////////////////////////////////////////////////////
1994-08-12 10:52:49 +00:00
class TExtrectype : public TRectype
1995-04-10 15:28:03 +00:00
{
RecDes * _rd ;
protected : // TRectype
virtual RecDes * rec_des ( ) const { return _rd ; }
1994-08-22 11:10:49 +00:00
public :
// FPUB
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
TExtrectype ( const TTrec & r ) ; // Costruisce il record a partire da r
virtual ~ TExtrectype ( ) ;
1994-08-12 10:52:49 +00:00
} ;
1994-09-12 09:34:05 +00:00
TExtrectype : : TExtrectype ( const TTrec & r ) : TRectype ( 6 )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
delete _rec ;
_length = r . len ( ) ;
_rec = new char [ _length ] ;
1995-04-10 15:28:03 +00:00
// _i = new isdef;
// _i->r = r.rec();
_rd = r . rec ( ) ;
1994-08-22 11:10:49 +00:00
zero ( ) ;
1994-08-12 10:52:49 +00:00
}
TExtrectype : : ~ TExtrectype ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-07-03 07:49:30 +00:00
// delete _rec;
1995-04-10 15:28:03 +00:00
// delete _i;
1994-08-12 10:52:49 +00:00
}
1995-02-10 17:42:33 +00:00
///////////////////////////////////////////////////////////
// TBaseisamfile
///////////////////////////////////////////////////////////
1994-08-12 10:52:49 +00:00
TBaseisamfile : : TBaseisamfile ( int logicnum , bool linkrecinst )
{
1994-08-22 11:10:49 +00:00
_isamfile = NULL ;
_logicnum = logicnum ;
_lasterr = NOERR ;
_delopenrec = FALSE ;
if ( ( openrec [ _logicnum - 1 ] = = NULL ) | | ( ! linkrecinst ) )
{
_current = new TRectype ( this ) ;
1994-08-12 10:52:49 +00:00
if ( openrec [ _logicnum - 1 ] = = NULL )
1994-08-22 11:10:49 +00:00
{
openrec [ _logicnum - 1 ] = _current ;
_delopenrec = TRUE ;
}
1994-08-12 10:52:49 +00:00
_delrec = TRUE ;
}
1994-08-22 11:10:49 +00:00
else
{
1994-08-12 10:52:49 +00:00
_current = openrec [ _logicnum - 1 ] ;
_delrec = FALSE ;
}
1995-07-03 07:49:30 +00:00
// _historicfile = ((r.field(RFLD_SYS_DATE) != FIELDERR) &&
// (r.field(RFLD_SYS_FIRST) != FIELDERR) &&
// (r.field(RFLD_SYS_LAST) != FIELDERR));
1994-12-28 15:01:04 +00:00
_historicfile = FALSE ;
1994-08-12 10:52:49 +00:00
}
TBaseisamfile : : ~ TBaseisamfile ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
if ( _delrec )
{
if ( _delopenrec )
1994-08-12 10:52:49 +00:00
openrec [ _logicnum - 1 ] = NULL ;
delete _current ;
}
1994-08-22 11:10:49 +00:00
if ( _isamfile ! = NULL )
delete _isamfile ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : gethr ( TRectype & rec , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
TRecfield fd0 ( rec , RFLD_SYS_DATE ) ;
TDate d0 ( ( const TDate & ) fd0 ) ;
if ( d0 < atdate )
{
1994-08-12 10:52:49 +00:00
atdate = eotime ;
return NOERR ;
}
1994-12-28 15:01:04 +00:00
TRectype wr ( rec ) ;
1994-08-22 11:10:49 +00:00
TRecfield flf ( wr , RFLD_SYS_FIRST ) ,
fll ( wr , RFLD_SYS_LAST ) ,
fd1 ( wr , RFLD_SYS_DATE ) ;
1994-12-28 15:01:04 +00:00
1994-08-22 11:10:49 +00:00
TDate d1 ;
TRecnotype wr0 = - 1L , wr1 = - 1L ;
if ( ( wr0 = = flf . ptr ( ) ) = = - 1L ) return _iskeynotfound ;
_hf . read ( wr . string ( ) , wr0 ) ;
if ( ( d1 = ( const TDate & ) fd1 ) > atdate )
{
1994-08-12 10:52:49 +00:00
rec = wr ;
1994-08-22 11:10:49 +00:00
atdate = d0 - 1L ;
1994-08-12 10:52:49 +00:00
return _iskeynotfound ;
}
1994-08-22 11:10:49 +00:00
while ( ( d1 < atdate ) & & ( wr0 > 0 ) )
{
1994-08-12 10:52:49 +00:00
rec = wr ;
1994-08-22 11:10:49 +00:00
wr1 = wr0 ;
1994-08-12 10:52:49 +00:00
if ( ( wr0 = fll . ptr ( ) ) > 0 )
1994-08-22 11:10:49 +00:00
{
_hf . read ( wr . string ( ) , wr0 ) ;
d1 = ( const TDate & ) fd1 ;
}
1994-08-12 10:52:49 +00:00
}
1994-08-22 11:10:49 +00:00
if ( wr0 < = 0 )
atdate = d0 - 1L ;
else
atdate = d1 - 1L ;
return NOERR ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : addhr ( const TRectype & rec , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
return NOERR ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : rewhr ( const TRectype & rec , TDate & atdate )
{
1994-08-22 11:10:49 +00:00
return NOERR ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : delhr ( const TRectype & rec , TDate & atdate )
{
1994-08-22 11:10:49 +00:00
return NOERR ;
1994-08-12 10:52:49 +00:00
}
long TBaseisamfile : : items ( ) const
{
1995-07-03 07:49:30 +00:00
return ( DB_reccount ( filehnd ( ) - > fhnd ) ) ;
1994-08-12 10:52:49 +00:00
}
const char * TBaseisamfile : : name ( ) const
1995-04-10 15:28:03 +00:00
{
1995-04-20 14:35:14 +00:00
sprintf ( _isam_string , " %d " , num ( ) ) ;
1995-04-10 15:28:03 +00:00
return _isam_string ;
1994-08-12 10:52:49 +00:00
}
const char * TBaseisamfile : : filename ( ) const
{
1994-12-27 14:59:25 +00:00
if ( _isamfile = = NULL )
{
TDir d ;
d . get ( num ( ) ) ;
1995-07-17 16:58:43 +00:00
strcpy ( _isam_string , d . filename ( ) ) ;
}
else
{
strcpy ( _isam_string , _isamfile - > d - > SysName ) ;
strcat ( _isam_string , " .dbf " ) ;
1994-12-27 14:59:25 +00:00
}
1995-07-17 16:58:43 +00:00
return _isam_string ;
1994-08-12 10:52:49 +00:00
}
1994-10-03 08:47:32 +00:00
const char * TBaseisamfile : : description ( ) const
{
1994-12-27 14:59:25 +00:00
if ( _isamfile = = NULL )
{
TDir d ;
d . get ( num ( ) ) ;
1995-04-20 14:35:14 +00:00
strcpy ( _isam_string , d . des ( ) ) ;
1995-04-10 15:28:03 +00:00
return _isam_string ;
1994-12-27 14:59:25 +00:00
}
1994-10-03 08:47:32 +00:00
return _isamfile - > d - > Des ;
}
1995-07-03 07:49:30 +00:00
TRecnotype TBaseisamfile : : eod ( ) const
{
NOT_OPEN ( ) ;
return ( DB_reccount ( _isamfile - > fhnd ) ) ;
}
1994-10-03 08:47:32 +00:00
1994-08-12 10:52:49 +00:00
void TBaseisamfile : : setkey ( int nkey )
{
1995-04-10 15:28:03 +00:00
CHECKD ( nkey > 0 & & nkey - 1 < = _isamfile - > r - > NKeys , " Chiave non valida " , nkey ) ;
NOT_OPEN ( ) ;
1995-07-03 07:49:30 +00:00
int rt = DB_tagselect ( _isamfile - > fhnd , nkey ) ;
if ( rt > = 0 ) _isamfile - > knum = nkey ;
if ( rt ! = NOERR ) rt = get_error ( rt ) ;
if ( _lasterr = = NOERR ) setstatus ( rt ) ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : getkey ( ) const
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1995-07-05 14:38:49 +00:00
CHECK ( DB_tagget ( _isamfile - > fhnd ) = = _isamfile - > knum , " Chiave inconsistente " ) ;
return _isamfile - > knum ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : first ( word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1994-08-22 11:10:49 +00:00
curr ( ) . setdirty ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = cisread ( _isamfile , curr ( ) , _isfirst + lockop ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
1994-08-22 11:10:49 +00:00
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : last ( word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1994-08-22 11:10:49 +00:00
curr ( ) . setdirty ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = cisread ( _isamfile , curr ( ) , _islast + lockop ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
1994-08-22 11:10:49 +00:00
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : next ( word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1994-08-22 11:10:49 +00:00
curr ( ) . setdirty ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = cisread ( _isamfile , curr ( ) , _isnext + lockop ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
1994-08-22 11:10:49 +00:00
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : next ( TDate & atdate )
1994-08-22 11:10:49 +00:00
1995-07-03 07:49:30 +00:00
{
error_box ( " TBaseisamfile::next(TDate&) is no more available " ) ;
1994-08-22 11:10:49 +00:00
return NOERR ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : prev ( word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1994-08-22 11:10:49 +00:00
curr ( ) . setdirty ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = cisread ( _isamfile , curr ( ) , _isprev + lockop ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
1994-08-22 11:10:49 +00:00
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : prev ( TDate & atdate )
1994-08-22 11:10:49 +00:00
1995-07-03 07:49:30 +00:00
{
error_box ( " TBaseisamfile::prev(TDate&) is no more available " ) ;
1994-08-22 11:10:49 +00:00
return NOERR ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : reread ( word lockop , TDate & atdate )
1994-08-22 11:10:49 +00:00
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1994-08-22 11:10:49 +00:00
curr ( ) . setdirty ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = cisread ( _isamfile , curr ( ) , _iscurr + lockop ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
1994-08-22 11:10:49 +00:00
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : reread ( TRectype & rec , word lockop , TDate & atdate )
1994-08-22 11:10:49 +00:00
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1994-08-22 11:10:49 +00:00
rec . setdirty ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = cisread ( _isamfile , rec , _iscurr + lockop ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
1994-08-22 11:10:49 +00:00
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : skip ( TRecnotype nrec , word lockop )
1994-08-22 11:10:49 +00:00
1995-07-03 07:49:30 +00:00
{
int rmode = ( lockop & READTYPES ) , lmode = ( lockop & RECLOCKTYPES ) ;
1995-07-05 14:38:49 +00:00
// BOOLEAN nolock = (lmode == _nolock);
// BOOLEAN unlock = (lmode == _unlock);
// BOOLEAN tlock = (lmode == INTTLOCK);
1995-07-03 07:49:30 +00:00
char key [ 128 ] ;
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1994-08-22 11:10:49 +00:00
if ( ! nrec ) return NOERR ;
1995-07-03 07:49:30 +00:00
curr ( ) . setdirty ( ) ;
_lasterr = DB_skip ( _isamfile - > fhnd , nrec ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
do {
1995-07-05 14:38:49 +00:00
if ( /* !tlock && */ _lasterr = = _islocked )
1995-07-03 07:49:30 +00:00
{
1995-07-05 11:12:13 +00:00
CBuildKey ( _isamfile - > r , DB_tagget ( _isamfile - > fhnd ) , curr ( ) . string ( ) , key , TRUE ) ;
1995-07-03 07:49:30 +00:00
message_box ( " Codice %s in uso da parte \n di un altro utente. " , key ) ;
}
_lasterr = cisread ( _isamfile , curr ( ) , _iscurr + lockop ) ;
1995-07-05 14:38:49 +00:00
} while ( /* !tlock && */ _lasterr = = _islocked ) ;
1995-07-03 07:49:30 +00:00
_recno = _isamfile - > RecNo = DB_recno ( _isamfile - > fhnd ) ;
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : read ( word op , word lockop , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
CHECKD ( op > = _iscurr & & op < = _isgteq , " Invalid read operation : " , op ) ;
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1994-08-22 11:10:49 +00:00
curr ( ) . setdirty ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = cisread ( _isamfile , curr ( ) , op + lockop ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
1994-08-22 11:10:49 +00:00
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : read ( TRectype & rec , word op , word lockop , TDate & atdate )
1994-08-22 11:10:49 +00:00
{
CHECKD ( op > = _iscurr & & op < = _isgteq , " Invalid read operation : " , op ) ;
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1994-08-22 11:10:49 +00:00
rec . setdirty ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = cisread ( _isamfile , rec , op + lockop ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
1994-08-22 11:10:49 +00:00
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : readat ( TRecnotype nrec , word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1994-08-22 11:10:49 +00:00
curr ( ) . setdirty ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = DB_go ( _isamfile - > fhnd , nrec ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
else
memcpy ( curr ( ) . string ( ) , DB_getrecord ( _isamfile - > fhnd ) , DB_reclen ( _isamfile - > fhnd ) ) ;
_recno = _isamfile - > RecNo = DB_recno ( _isamfile - > fhnd ) ;
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : readat ( TRectype & rec , TRecnotype nrec , word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1994-08-22 11:10:49 +00:00
rec . setdirty ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = DB_go ( _isamfile - > fhnd , nrec ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
else
memcpy ( rec . string ( ) , DB_getrecord ( _isamfile - > fhnd ) , DB_reclen ( _isamfile - > fhnd ) ) ;
1994-08-22 11:10:49 +00:00
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : write ( TDate & atdate )
1995-07-07 14:43:41 +00:00
{
CHECK ( ! curr ( ) . empty ( ) , " Can't write an empty record " ) ;
1995-07-04 07:31:04 +00:00
NOT_OPEN ( ) ;
int oldkey = getkey ( ) ;
1995-07-04 14:06:19 +00:00
browse_null ( curr ( ) . string ( ) , DB_reclen ( _isamfile - > fhnd ) ) ;
TRectype r ( curr ( ) ) ;
1995-07-04 07:31:04 +00:00
setkey ( 1 ) ;
1995-07-07 15:18:35 +00:00
// if (cisread(_isamfile, r, _isequal + _nolock) != NOERR)
// {
memcpy ( DB_getrecord ( _isamfile - > fhnd ) , curr ( ) . string ( ) , DB_reclen ( _isamfile - > fhnd ) ) ;
_lasterr = DB_add ( _isamfile - > fhnd ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
// }
// else
// _lasterr=_isreinsert;
1995-07-04 07:31:04 +00:00
setkey ( oldkey ) ;
1995-07-03 07:49:30 +00:00
_recno = _isamfile - > RecNo = DB_recno ( _isamfile - > fhnd ) ;
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : write ( const TRectype & rec , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-07-07 14:43:41 +00:00
CHECK ( ! rec . empty ( ) , " Can't write an empty record " ) ;
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1995-07-04 07:31:04 +00:00
int oldkey = getkey ( ) ;
1995-07-03 07:49:30 +00:00
browse_null ( rec . string ( ) , DB_reclen ( _isamfile - > fhnd ) ) ;
1995-07-04 14:06:19 +00:00
TRectype r ( rec ) ;
1995-07-04 07:31:04 +00:00
setkey ( 1 ) ;
1995-07-07 15:18:35 +00:00
// if (cisread(_isamfile, r, _isequal + _nolock) != NOERR)
// {
memcpy ( DB_getrecord ( _isamfile - > fhnd ) , rec . string ( ) , DB_reclen ( _isamfile - > fhnd ) ) ;
_lasterr = DB_add ( _isamfile - > fhnd ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
// }
// else
// _lasterr=_isreinsert;
1995-07-04 07:31:04 +00:00
setkey ( oldkey ) ;
1995-07-03 07:49:30 +00:00
_recno = _isamfile - > RecNo = DB_recno ( _isamfile - > fhnd ) ;
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : rewrite ( TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-07-07 14:43:41 +00:00
CHECK ( ! curr ( ) . empty ( ) , " Can't rewrite an empty record " ) ;
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1995-07-03 07:49:30 +00:00
TRectype save_rec ( curr ( ) ) ;
1995-07-05 16:58:15 +00:00
_lasterr = cisread ( _isamfile , save_rec , _isequal + _nolock ) ; // Si Posiziona per sicurezza...
1995-07-03 07:49:30 +00:00
if ( _lasterr = = NOERR )
1995-07-04 14:06:19 +00:00
{
1995-07-05 16:58:15 +00:00
memcpy ( DB_getrecord ( _isamfile - > fhnd ) , curr ( ) . string ( ) , DB_reclen ( _isamfile - > fhnd ) ) ;
1995-07-03 07:49:30 +00:00
_lasterr = DB_rewrite ( _isamfile - > fhnd ) ;
1995-07-04 14:06:19 +00:00
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
_recno = _isamfile - > RecNo = DB_recno ( _isamfile - > fhnd ) ;
}
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : rewrite ( const TRectype & rec , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-07-07 14:43:41 +00:00
CHECK ( ! rec . empty ( ) , " Can't write an empty record " ) ;
1995-07-03 07:49:30 +00:00
NOT_OPEN ( ) ;
TRectype save_rec ( rec ) ;
1995-07-05 16:58:15 +00:00
_lasterr = cisread ( _isamfile , save_rec , _isequal + _nolock ) ; // Si Posiziona per sicurezza...
1995-07-03 07:49:30 +00:00
if ( _lasterr = = NOERR )
1995-07-04 14:06:19 +00:00
{
1995-07-05 16:58:15 +00:00
memcpy ( DB_getrecord ( _isamfile - > fhnd ) , rec . string ( ) , DB_reclen ( _isamfile - > fhnd ) ) ;
1995-07-03 07:49:30 +00:00
_lasterr = DB_rewrite ( _isamfile - > fhnd ) ;
1995-07-04 14:06:19 +00:00
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
_recno = _isamfile - > RecNo = DB_recno ( _isamfile - > fhnd ) ;
}
1994-08-22 11:10:49 +00:00
return _lasterr ;
}
int TBaseisamfile : : rewriteat ( TRecnotype nrec )
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1995-07-03 07:49:30 +00:00
if ( ( _lasterr = DB_go ( _isamfile - > fhnd , nrec ) ) = = NOERR )
{
memcpy ( DB_getrecord ( _isamfile - > fhnd ) , curr ( ) . string ( ) , DB_reclen ( _isamfile - > fhnd ) ) ;
_lasterr = DB_rewrite ( _isamfile - > fhnd ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
} else
_lasterr = get_error ( _lasterr ) ;
_recno = _isamfile - > RecNo = DB_recno ( _isamfile - > fhnd ) ;
return _lasterr ;
1994-08-22 11:10:49 +00:00
}
int TBaseisamfile : : rewriteat ( const TRectype & rec , TRecnotype nrec )
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1995-07-03 07:49:30 +00:00
if ( ( _lasterr = DB_go ( _isamfile - > fhnd , nrec ) ) = = NOERR )
{
memcpy ( DB_getrecord ( _isamfile - > fhnd ) , rec . string ( ) , DB_reclen ( _isamfile - > fhnd ) ) ;
_lasterr = DB_rewrite ( _isamfile - > fhnd ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
} else
_lasterr = get_error ( _lasterr ) ;
_recno = _isamfile - > RecNo = DB_recno ( _isamfile - > fhnd ) ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : remove ( TDate & atdate )
{
1995-07-07 14:43:41 +00:00
CHECK ( ! curr ( ) . empty ( ) , " Can't remove empty record " ) ;
1995-07-03 07:49:30 +00:00
NOT_OPEN ( ) ;
1995-06-12 10:49:19 +00:00
1995-07-03 07:49:30 +00:00
// rimozione campi memo
# ifndef FOXPRO
1995-06-13 08:23:45 +00:00
TMemo_file * memo = NULL ;
1995-06-12 10:49:19 +00:00
1995-06-13 08:23:45 +00:00
for ( int i = 0 ; i < curr ( ) . items ( ) ; i + + )
{
if ( curr ( ) . type ( curr ( ) . fieldname ( i ) ) = = _memofld )
{
long val = curr ( ) . get_long ( curr ( ) . fieldname ( i ) ) ;
if ( val > 0l )
{
if ( memo = = NULL )
memo = new TMemo_file ( filename ( ) ) ;
memo - > remove_field ( val ) ;
}
}
}
if ( memo ! = NULL ) delete memo ;
1995-07-03 07:49:30 +00:00
# endif
1995-06-12 10:49:19 +00:00
1995-07-03 07:49:30 +00:00
if ( ( _lasterr = cisread ( _isamfile , curr ( ) , _isequal + _lock ) ) = = NOERR )
{
_lasterr = DB_delete ( _isamfile - > fhnd ) ; // Put only deletion flag on record, must remove keys too!
if ( _lasterr ! = NOERR )
_lasterr = get_error ( _lasterr ) ;
else
{
_lasterr = delkeys ( _isamfile , curr ( ) . string ( ) , _isamfile - > RecNo ) ;
if ( _lasterr ! = NOERR )
{
DB_recall ( _isamfile - > fhnd ) ;
_lasterr = get_error ( _lasterr ) ;
}
}
}
_recno = _isamfile - > RecNo = DB_recno ( _isamfile - > fhnd ) ;
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : remove ( const TRectype & rec , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-07-07 14:43:41 +00:00
CHECK ( ! rec . empty ( ) , " Can't remove an empty record " ) ;
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1995-07-03 07:49:30 +00:00
memcpy ( DB_getrecord ( _isamfile - > fhnd ) , rec . string ( ) , DB_reclen ( _isamfile - > fhnd ) ) ;
if ( ( _lasterr = cisread ( _isamfile , ( TRectype & ) rec , _isequal + _lock ) ) = = NOERR )
{
_lasterr = DB_delete ( _isamfile - > fhnd ) ; // Put only deletion flag on record, must remove keys too!
if ( _lasterr ! = NOERR )
_lasterr = get_error ( _lasterr ) ;
else
{
_lasterr = delkeys ( _isamfile , rec . string ( ) , _isamfile - > RecNo ) ;
if ( _lasterr ! = NOERR )
{
DB_recall ( _isamfile - > fhnd ) ;
_lasterr = get_error ( _lasterr ) ;
}
}
}
_recno = _isamfile - > RecNo = DB_recno ( _isamfile - > fhnd ) ;
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : lock ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = DB_lockfile ( _isamfile - > fhnd ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : unlock ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1995-07-03 07:49:30 +00:00
_lasterr = DB_unlock ( _isamfile - > fhnd ) ;
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
return ( _lasterr ) ;
1994-08-12 10:52:49 +00:00
}
void TBaseisamfile : : indexon ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
}
bool TBaseisamfile : : empty ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-07-03 07:49:30 +00:00
return ( DB_reccount ( _isamfile - > fhnd ) = = 0 ) ;
1994-08-12 10:52:49 +00:00
}
void TBaseisamfile : : indexoff ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
}
int TBaseisamfile : : _open ( unsigned int mode )
1994-08-22 11:10:49 +00:00
{
1995-04-10 15:28:03 +00:00
CHECKS ( filehnd ( ) = = NULL , " File already open " , ( const char * ) filename ( ) ) ;
1994-08-22 11:10:49 +00:00
1995-07-03 07:49:30 +00:00
getisfd ( _isamfile , num ( ) ) ;
if ( ( filehnd ( ) - > fhnd = DB_open ( filehnd ( ) - > d - > SysName , mode = = _excllock ) ) > = 0 )
{
TRecnotype n = DB_reccount ( filehnd ( ) - > fhnd ) ;
TDir d ;
1995-07-04 07:31:04 +00:00
// d.get(num());
d . get ( num ( ) , _nolock , _nordir , _sysdirop ) ;
if ( d . is_com ( ) ) d . get ( num ( ) , _nolock , _comdir ) ;
1995-07-03 07:49:30 +00:00
if ( ( filehnd ( ) - > d - > EOD ! = n & & n > 0 ) | | ( n > = d . eox ( ) ) )
1994-08-22 11:10:49 +00:00
{
1995-07-03 07:49:30 +00:00
filehnd ( ) - > d - > EOD = d . eod ( ) = n ;
filehnd ( ) - > d - > EOX = d . eox ( ) = ( TRecnotype ) ( n * 1.2 ) ;
1995-07-04 07:31:04 +00:00
if ( d . is_com ( ) )
d . put ( num ( ) , _comdir ) ;
else
d . put ( num ( ) ) ;
1994-08-22 11:10:49 +00:00
}
1995-07-03 07:49:30 +00:00
filehnd ( ) - > ln = num ( ) ;
openf [ num ( ) - 1 ] = filehnd ( ) ;
_recno = - 1L ;
1995-07-03 16:19:39 +00:00
CHECKD ( filehnd ( ) - > r - > NKeys > 0 , " File senza indici: " , num ( ) ) ;
1995-07-05 14:38:49 +00:00
setkey ( 1 ) ;
1995-07-03 07:49:30 +00:00
_lasterr = NOERR ;
1995-07-03 16:19:39 +00:00
}
else
1995-07-03 07:49:30 +00:00
{
_lasterr = get_error ( filehnd ( ) - > fhnd ) ;
relisfd ( _isamfile ) ;
fatal_box ( " Il file %d non puo' essere aperto, errore %d " , num ( ) , _lasterr ) ;
1994-08-12 10:52:49 +00:00
}
1995-07-03 07:49:30 +00:00
return ( _lasterr ) ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : _close ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
int err = NOERR ;
if ( filehnd ( ) ! = NULL )
{
1995-07-03 07:49:30 +00:00
if ( num ( ) > 0 )
{
TDir d ;
TRecnotype n = DB_reccount ( filehnd ( ) - > fhnd ) ;
1995-07-04 07:31:04 +00:00
//d.get(num());
d . get ( num ( ) , _nolock , _nordir , _sysdirop ) ;
if ( d . is_com ( ) ) d . get ( num ( ) , _nolock , _comdir ) ;
1995-07-03 07:49:30 +00:00
if ( ( filehnd ( ) - > d - > EOD ! = n & & n > 0 ) | | ( n > = d . eox ( ) ) )
{
filehnd ( ) - > d - > EOD = d . eod ( ) = n ;
filehnd ( ) - > d - > EOX = d . eox ( ) = ( TRecnotype ) ( n * 1.2 ) ;
1995-07-04 07:31:04 +00:00
if ( d . is_com ( ) )
d . put ( num ( ) , _comdir ) ;
else
d . put ( num ( ) ) ;
1995-07-03 07:49:30 +00:00
}
CHECK ( openf [ num ( ) - 1 ] ! = NULL , " Open file array corrupted " ) ;
err = DB_close ( filehnd ( ) - > fhnd ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
if ( ( err = = NOERR ) & & ( num ( ) > 0 ) )
openf [ num ( ) - 1 ] = NULL ;
}
else
if ( filehnd ( ) = = NULL )
{
err = _isnotopen ;
error_box ( " File n. %d close : Error n. %d " , num ( ) , err ) ;
}
if ( err = = NOERR )
{
relisfd ( _isamfile ) ;
clearfilehnd ( ) ;
}
1994-08-12 10:52:49 +00:00
}
1995-04-10 15:28:03 +00:00
// _current->_i = NULL;
1994-08-22 11:10:49 +00:00
setstatus ( err ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
1995-02-10 17:42:33 +00:00
///////////////////////////////////////////////////////////
// TLocalisamfile
///////////////////////////////////////////////////////////
1995-02-22 14:21:34 +00:00
// Attenzione linkrecinst puo' valere 0, 1, 2.
// Se vale 2 significa che si sta costruendo un file temporaneo
1995-07-03 07:49:30 +00:00
// per cui linkrecinst va' considerato FALSE
1995-02-22 14:21:34 +00:00
1994-08-12 10:52:49 +00:00
TLocalisamfile : : TLocalisamfile ( int logicnum , bool linkrecinst )
1995-02-22 14:21:34 +00:00
: TBaseisamfile ( logicnum , linkrecinst = = TRUE )
1995-02-10 17:42:33 +00:00
{
if ( linkrecinst < = TRUE )
{
open ( ) ;
1995-07-03 16:19:39 +00:00
if ( _was_open )
1995-02-10 17:42:33 +00:00
_oldkey = getkey ( ) ;
setkey ( 1 ) ;
}
else _was_open = FALSE ;
1994-08-12 10:52:49 +00:00
}
TLocalisamfile : : ~ TLocalisamfile ( )
1995-01-04 15:39:38 +00:00
{
1995-01-05 17:50:40 +00:00
if ( _was_open )
1995-01-04 15:39:38 +00:00
setkey ( _oldkey ) ;
1994-08-12 10:52:49 +00:00
close ( ) ;
}
int TLocalisamfile : : close ( )
{
int err = NOERR ;
if ( ! _was_open )
{
clearfilehnd ( ) ;
}
else
{
if ( _isamfile )
1995-07-03 07:49:30 +00:00
{
TRecnotype n = DB_reccount ( filehnd ( ) - > fhnd ) ;
TDir d ;
1995-07-04 07:31:04 +00:00
//d.get(num());
d . get ( num ( ) , _nolock , _nordir , _sysdirop ) ;
if ( d . is_com ( ) ) d . get ( num ( ) , _nolock , _comdir ) ;
1995-07-03 07:49:30 +00:00
if ( ( filehnd ( ) - > d - > EOD ! = n & & n > 0 ) | | ( n > d . eox ( ) ) )
{
filehnd ( ) - > d - > EOD = d . eod ( ) = n ;
filehnd ( ) - > d - > EOX = d . eox ( ) = n ;
1995-07-04 07:31:04 +00:00
if ( d . is_com ( ) )
d . put ( num ( ) , _comdir ) ;
else
d . put ( num ( ) ) ;
1995-07-03 07:49:30 +00:00
}
err = DB_close ( _isamfile - > fhnd ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
relisfd ( _isamfile ) ;
_isamfile = NULL ;
}
openf [ num ( ) - 1 ] = NULL ;
1994-08-12 10:52:49 +00:00
}
setstatus ( err ) ;
return err ;
}
int TLocalisamfile : : open ( unsigned int mode )
{
int err = NOERR ;
const int logicnum = num ( ) ;
if ( openf [ logicnum - 1 ] ! = NULL )
{
_was_open = FALSE ;
_isamfile = openf [ logicnum - 1 ] ;
1994-08-22 11:10:49 +00:00
}
else
{
err = _open ( ) ;
_was_open = TRUE ;
}
1995-04-10 15:28:03 +00:00
// _current->_i = filehnd();
1995-03-22 09:07:04 +00:00
1994-08-22 11:10:49 +00:00
setstatus ( err ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
int TLocalisamfile : : operator + = ( const TRecnotype npos )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
skip ( npos ) ;
return status ( ) ;
}
int TLocalisamfile : : operator - = ( const TRecnotype npos )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
skip ( - npos ) ;
return status ( ) ;
1994-08-12 10:52:49 +00:00
}
int TLocalisamfile : : operator + + ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
next ( ) ;
return status ( ) ;
1994-08-12 10:52:49 +00:00
}
int TLocalisamfile : : operator - - ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
prev ( ) ;
return status ( ) ;
1994-08-12 10:52:49 +00:00
}
TIsamfile : : TIsamfile ( int logicnum , bool linkrecinst ) : TBaseisamfile ( logicnum , linkrecinst ) { }
TIsamfile : : ~ TIsamfile ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
close ( ) ;
1994-08-12 10:52:49 +00:00
}
int TIsamfile : : flags ( bool updateeod )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-07-03 07:49:30 +00:00
TDir d ;
int err = NOERR ;
if ( filehnd ( ) - > ln < = 0 ) return NOERR ;
1995-04-10 15:28:03 +00:00
NOT_OPEN ( ) ;
1995-07-03 07:49:30 +00:00
const TDirtype dirtype = ( TDirtype ) filehnd ( ) - > ft ;
d . get ( num ( ) , _lock , dirtype ) ;
if ( ( err = d . status ( dirtype ) ) = = NOERR )
{
d . flags ( ) = filehnd ( ) - > d - > Flags ;
if ( updateeod ) d . eod ( ) = filehnd ( ) - > d - > EOD ;
d . put ( num ( ) , dirtype ) ;
}
1994-08-22 11:10:49 +00:00
setstatus ( err ) ;
1995-07-03 07:49:30 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
1995-02-10 17:42:33 +00:00
///////////////////////////////////////////////////////////
// TIsamtempfile
///////////////////////////////////////////////////////////
1994-08-12 10:52:49 +00:00
1995-02-10 17:42:33 +00:00
TIsamtempfile : : TIsamtempfile ( int logicnum , const char * radix , bool create )
: TLocalisamfile ( logicnum , 2 )
{
TRecnotype eod = 0 ;
TRecnotype eox = 100 ;
1995-03-24 11:16:17 +00:00
TFilename n ;
if ( radix & & * radix )
{
if ( * radix = = ' % ' )
n = radix ;
else
{
n . tempdir ( ) ;
n < < ' / ' < < radix ;
}
}
1995-02-10 17:42:33 +00:00
1995-07-03 07:49:30 +00:00
n . ext ( " dbf " ) ;
1995-02-10 17:42:33 +00:00
if ( ! create )
{
TDir dir ; dir . get ( logicnum ) ;
1995-03-24 11:16:17 +00:00
const word & len = dir . len ( ) ;
// Tolgo il % senno' che fa la fopen ?
if ( n [ 0 ] = = ' % ' )
n = n . sub ( 1 ) ;
1995-02-10 17:42:33 +00:00
FILE * f = fopen ( n , " r " ) ;
1995-03-24 11:16:17 +00:00
1995-04-10 15:28:03 +00:00
# if XVT_OS == XVT_OS_WIN
1995-03-24 11:16:17 +00:00
CHECKS ( f , " Can't open temporary file " , ( const char * ) strerror ( NULL ) ) ;
# else
1995-02-10 17:42:33 +00:00
CHECKS ( f , " Can't open temporary file " , ( const char * ) n ) ;
1995-03-24 11:16:17 +00:00
# endif
1995-02-10 17:42:33 +00:00
fseek ( f , 0 , SEEK_END ) ;
eod = eox = ftell ( f ) / len ;
fclose ( f ) ;
}
_autodel = create > TRUE ;
1995-02-15 17:02:44 +00:00
1995-03-24 11:16:17 +00:00
n . ext ( " " ) ;
// Ci rimetto il % se prima l'avevo tolto, senno' che fa la open ?
// if (*radix == '%')
if ( n [ 0 ] ! = ' % ' )
n . insert ( " % " , 0 ) ;
1995-02-10 17:42:33 +00:00
open ( n , create , eod , eox ) ;
}
1994-08-12 10:52:49 +00:00
TIsamtempfile : : ~ TIsamtempfile ( )
{
1994-08-22 11:10:49 +00:00
close ( ) ;
1994-08-12 10:52:49 +00:00
}
1995-02-10 17:42:33 +00:00
int TIsamtempfile : : open ( const char * radix , bool create , TRecnotype eod , TRecnotype eox )
1994-08-22 11:10:49 +00:00
{
1995-07-03 07:49:30 +00:00
int err = NOERR ;
TFilename tmpname ;
1995-04-10 15:28:03 +00:00
CHECKS ( filehnd ( ) = = NULL , " File already open " , ( const char * ) filename ( ) ) ;
1994-08-22 11:10:49 +00:00
1995-07-03 07:49:30 +00:00
if ( radix [ 0 ] = = ' % ' )
tmpname < < & radix [ 1 ] ;
else
tmpname . temp ( radix ) ;
getisfd ( _isamfile , num ( ) ) ;
strcpy ( filehnd ( ) - > d - > SysName , ( const char * ) tmpname ) ;
filehnd ( ) - > d - > EOX = eox ;
if ( create )
{
err = DB_build ( filehnd ( ) - > d - > SysName , filehnd ( ) - > r ) ;
if ( err = = NOERR )
filehnd ( ) - > d - > EOD = 0L ;
else
{
err = get_error ( err ) ;
relisfd ( _isamfile ) ;
fatal_box ( " Create temporary file: Error n. %d " , errno ) ;
1994-08-22 11:10:49 +00:00
}
1995-07-03 07:49:30 +00:00
}
else
filehnd ( ) - > d - > EOD = eod ;
filehnd ( ) - > fhnd = DB_open ( filehnd ( ) - > d - > SysName , 0 ) ;
if ( filehnd ( ) - > fhnd < 0 ) err = get_error ( filehnd ( ) - > fhnd ) ;
if ( err ! = NOERR )
{
relisfd ( _isamfile ) ;
fatal_box ( " Open temporary file: Error n. %d " , errno ) ;
}
else
{
filehnd ( ) - > ln = - num ( ) ;
filehnd ( ) - > knum = 1 ;
1994-08-12 10:52:49 +00:00
}
1995-04-10 15:28:03 +00:00
// _current->_i = filehnd();
1994-08-22 11:10:49 +00:00
_recno = - 1L ;
setstatus ( err ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
1995-02-10 17:42:33 +00:00
int TIsamtempfile : : close ( )
1994-08-12 10:52:49 +00:00
{
1995-02-10 17:42:33 +00:00
int err = NOERR ;
1994-08-22 11:10:49 +00:00
if ( filehnd ( ) ! = NULL )
{
1995-07-03 07:49:30 +00:00
err = DB_close ( filehnd ( ) - > fhnd ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
if ( _autodel & & err = = NOERR )
{
TFilename f ( filehnd ( ) - > d - > SysName ) ;
long c = DB_getconf ( ) ;
f . ext ( " dbf " ) ;
: : remove ( ( const char * ) f ) ;
if ( c & 1 ) // FOXPRO format
f . ext ( " cdx " ) ;
if ( c & 4 ) // DBIV format
f . ext ( " mdx " ) ;
if ( c & 8 | | c & 2 ) // CLIPPER and DBIII format
{
f . ext ( " cgp " ) ;
FILE * fp = fopen ( ( const char * ) f , " r " ) ;
char in [ 16 ] ;
while ( fgets ( in , 16 , fp ) ! = NULL )
{
TFilename a ( in ) ;
if ( c & 8 ) // DBIII format
a . ext ( " ndx " ) ;
else
a . ext ( " ntx " ) ; // CLIPPER format
: : remove ( ( const char * ) a ) ;
}
fclose ( fp ) ;
}
: : remove ( ( const char * ) f ) ;
}
relisfd ( _isamfile ) ;
1994-08-12 10:52:49 +00:00
clearfilehnd ( ) ;
}
1995-04-10 15:28:03 +00:00
// _current->_i = NULL;
1994-08-22 11:10:49 +00:00
setstatus ( err ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
1995-02-10 17:42:33 +00:00
///////////////////////////////////////////////////////////
// TSystemsamfile
///////////////////////////////////////////////////////////
1994-08-12 10:52:49 +00:00
int TSystemisamfile : : build ( TRecnotype eox )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-04-10 15:28:03 +00:00
CHECKS ( filehnd ( ) = = NULL , " Can't build open file " , ( const char * ) filename ( ) ) ;
1995-07-03 07:49:30 +00:00
int err = NOERR ;
1994-10-14 17:51:32 +00:00
TDir d ;
1995-07-03 07:49:30 +00:00
TTrec r ;
1994-10-14 17:51:32 +00:00
d . get ( num ( ) ) ;
1995-07-03 07:49:30 +00:00
r . get ( num ( ) ) ;
1995-07-20 09:10:38 +00:00
CHECK ( r . len ( ) ! = 0 , " Can't create a file with empty field info " ) ;
1995-07-03 07:49:30 +00:00
1994-10-14 17:51:32 +00:00
TFilename f ( d . name ( ) ) ;
1995-04-28 13:14:15 +00:00
f = f . path ( ) ; if ( ! is_not_slash ( f . right ( 1 ) [ 0 ] ) ) f . rtrim ( 1 ) ;
1994-10-14 17:51:32 +00:00
if ( ! fexist ( f ) )
1995-04-10 15:28:03 +00:00
make_dir ( f ) ;
1995-07-20 09:10:38 +00:00
if ( r . len ( ) ! = 0 )
{
err = DB_build ( d . name ( ) , r . rec ( ) ) ;
if ( err = = NOERR )
{
isfdptr i ;
getisfd ( i , num ( ) ) ;
1995-08-03 15:07:29 +00:00
i - > d - > EOX = eox ;
i - > fhnd = 0 ; // So relisfd() will record the EOX just set
1995-07-20 09:10:38 +00:00
relisfd ( i ) ;
}
else
err = get_error ( err ) ;
setstatus ( err ) ;
clearfilehnd ( ) ;
1994-11-24 14:01:20 +00:00
# ifndef FOXPRO
1995-07-20 09:10:38 +00:00
if ( err = = NOERR & & __autoload )
{
TFilename lf ;
lf . format ( " %sstd/lf%04d.txt " , __ptprf , num ( ) ) ;
if ( fexist ( lf ) )
load ( lf , ' | ' , ' \0 ' , ' \n ' , TRUE , TRUE ) ;
}
1994-11-24 14:01:20 +00:00
# endif
1995-07-20 09:10:38 +00:00
}
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
int TSystemisamfile : : extend ( TRecnotype eox )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-07-03 07:49:30 +00:00
int err = NOERR ;
isfdptr i ;
1995-04-10 15:28:03 +00:00
CHECKS ( filehnd ( ) = = NULL , " Can't extend open file " , ( const char * ) filename ( ) ) ;
1995-07-03 07:49:30 +00:00
getisfd ( i , num ( ) ) ;
if ( num ( ) > 0 )
{
if ( eox < i - > d - > EOD )
err = _ispathfull ;
1995-08-03 15:07:29 +00:00
else
{
1995-07-03 07:49:30 +00:00
i - > d - > EOX = eox ;
1995-08-03 15:07:29 +00:00
i - > fhnd = 0 ; // So relisfd() will write the EOX just set.
}
1995-07-03 07:49:30 +00:00
}
relisfd ( i ) ;
1994-08-22 11:10:49 +00:00
setstatus ( err ) ;
clearfilehnd ( ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
long TSystemisamfile : : size ( TRecnotype eox )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-07-03 07:49:30 +00:00
const long size = ( 100 * ( unsigned ) 512 ) ;
1994-08-22 11:10:49 +00:00
return size ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
1994-11-18 17:39:45 +00:00
bool TSystemisamfile : : exec_convapp ( long flev , const bool before )
{
const char * const v = before ? " BCNV " : " ACNV " ;
if ( flev = = 0 ) flev = 199401 ;
else flev + + ;
1995-03-22 09:07:04 +00:00
for ( long l = flev ; l < = get_std_level ( ) ; l + + )
1994-11-18 17:39:45 +00:00
{
TString16 paragraph ( format ( " %06ld " , l ) ) ;
TConfig conv ( CONFIG_FCONV , paragraph ) ;
if ( ! conv . new_paragraph ( ) & & conv . exist ( v , num ( ) ) )
{
int err = 0 ;
TString80 s ( conv . get ( v , NULL , num ( ) ) ) ; s < < " " < < main_app ( ) . get_firm ( ) ;
1994-11-24 14:01:20 +00:00
TExternal_app app ( s ) ;
1994-11-18 17:39:45 +00:00
if ( app . can_run ( ) )
{
app . run ( ) ;
err = app . error ( ) ;
TMailbox mail ;
TMessage * msg = mail . next ( TRUE ) ;
if ( err = = 0 & & msg ! = NULL )
err = atoi ( msg - > body ( ) ) ;
}
else err = 16 ;
if ( err )
1995-04-10 15:28:03 +00:00
return error_box ( " Impossibile eseguire il programma di %sconversione \n del livello %ld/%ld \n Errore n.ro %d " , before ? " pre " : " post " , l / 100 , l % 100 , err ) ;
1994-11-18 17:39:45 +00:00
}
}
return TRUE ;
}
1994-08-12 10:52:49 +00:00
1994-09-28 10:36:08 +00:00
bool TSystemisamfile : : getlcf ( long flev )
1994-09-27 10:19:36 +00:00
{
_flds . destroy ( ) ;
_exps . destroy ( ) ;
if ( flev = = 0 ) flev = 199401 ;
else flev + + ;
1995-03-22 09:07:04 +00:00
for ( long l = flev ; l < = get_std_level ( ) ; l + + )
1994-09-27 10:19:36 +00:00
{
TString16 paragraph ( format ( " %06ld " , l ) ) ;
TConfig conv ( CONFIG_FCONV , paragraph ) ;
1994-11-18 17:39:45 +00:00
if ( ! conv . new_paragraph ( ) & & conv . exist ( " F " , num ( ) ) )
1994-09-27 10:19:36 +00:00
{
TToken_string exprline ( conv . get ( " F " , NULL , num ( ) ) ) ;
if ( exprline . empty ( ) ) return FALSE ;
TToken_string w ( " " , ' = ' ) ;
const char * wexprs = exprline . get ( ) ;
while ( wexprs ! = NULL )
{
w = wexprs ;
TFixed_string fld ( w . get ( ) ) ;
_flds . add ( new TFieldref ( fld , 0 ) ) ;
_exps . add ( new TExpression ( w . get ( ) , _strexpr ) ) ;
wexprs = exprline . get ( ) ;
}
}
}
return _flds . items ( ) > 0 ;
}
void TSystemisamfile : : makelc ( TRectype & rec )
{
for ( int i = 0 ; i < _flds . items ( ) ; i + + )
{
TFieldref & f = ( TFieldref & ) _flds [ i ] ;
TExpression & e = ( TExpression & ) _exps [ i ] ;
for ( int k = 0 ; k < e . numvar ( ) ; k + + )
e . setvar ( k , get ( e . varname ( k ) ) ) ;
f . write ( e , rec ) ;
}
}
1994-08-12 10:52:49 +00:00
int TSystemisamfile : : update ( TTrec & newrec , bool vis )
1994-08-22 11:10:49 +00:00
1995-04-10 15:28:03 +00:00
{
CHECKS ( filehnd ( ) = = NULL , " Can't update open file " , ( const char * ) filename ( ) ) ;
1995-07-20 09:10:38 +00:00
CHECK ( newrec . len ( ) ! = 0 , " Can't update to file with empty field info " ) ;
1994-08-22 11:10:49 +00:00
TDir dir ;
1994-10-31 16:24:26 +00:00
1995-04-28 13:14:15 +00:00
dir . get ( num ( ) , _unlock , _nordir , _sysdirop ) ;
1994-10-31 16:24:26 +00:00
const char p = * dir . name ( ) ;
1995-03-22 09:07:04 +00:00
const bool is_com = prefix ( ) . is_com ( ) ;
1995-02-02 18:08:50 +00:00
const bool toconvert = is_com ? dir . is_com ( ) : dir . is_firm ( ) ;
1994-10-31 16:24:26 +00:00
int err = NOERR ;
1994-08-22 11:10:49 +00:00
TTrec oldrec ;
oldrec . get ( num ( ) ) ;
1995-07-20 09:10:38 +00:00
if ( newrec . len ( ) ! = 0 )
1994-11-18 17:39:45 +00:00
{
1995-07-20 09:10:38 +00:00
const long lev = prefix ( ) . filelevel ( ) ;
const bool lcf = getlcf ( lev ) ;
exec_convapp ( lev , TRUE ) ;
1995-07-03 07:49:30 +00:00
1995-07-20 09:10:38 +00:00
if ( ! lcf & & newrec = = oldrec )
1994-08-22 11:10:49 +00:00
{
1995-07-20 09:10:38 +00:00
exec_convapp ( lev , FALSE ) ;
return NOERR ;
1994-08-22 11:10:49 +00:00
}
1995-07-20 09:10:38 +00:00
const TRecnotype nitems = dir . eod ( ) ;
const unsigned int lenr = newrec . len ( ) ;
if ( ! toconvert & & dir . eox ( ) > 0L )
1994-08-22 11:10:49 +00:00
{
1995-07-20 09:10:38 +00:00
dir . eod ( ) = 0L ;
dir . eox ( ) = 0L ;
1994-08-22 11:10:49 +00:00
}
1995-07-20 09:10:38 +00:00
if ( toconvert & & dir . eox ( ) > 0L )
{
TRecnotype ni = 0L ;
isfdptr i0 ;
TFilename tmpfname ( " tmpf " ) ;
open ( _excllock ) ;
getisfd ( i0 , num ( ) ) ;
err = DB_build ( ( const char * ) tmpfname , newrec . rec ( ) ) ;
if ( err ! = NOERR )
{
err = get_error ( err ) ;
return ( err ) ;
}
i0 - > fhnd = DB_open ( ( const char * ) tmpfname , 0 ) ;
if ( i0 - > fhnd < 0 ) err = get_error ( i0 - > fhnd ) ;
TFilename fname ( filename ( ) ) ;
TString s ( 80 ) ;
s . format ( " Aggiornamento archivio %s " , ( const char * ) fname ) ;
TProgind p ( nitems ? nitems : 1 , s , TRUE , TRUE , 70 ) ;
int nflds = curr ( ) . items ( ) ;
TArray fld ( nflds ) ;
TExtrectype nrec ( newrec ) ;
TRecnotype i = 0 ;
for ( int j = 0 ; j < nflds ; j + + )
fld . add ( TString ( curr ( ) . fieldname ( j ) ) , j ) ;
for ( first ( ) ; good ( ) ; next ( ) )
{
if ( ( i + + % 50 ) = = 0 ) p . setstatus ( i + 1 ) ;
nrec . zero ( ) ;
ni + + ;
for ( j = 0 ; j < nflds ; j + + )
if ( nrec . exist ( ( const TString & ) fld [ j ] ) )
nrec . put ( ( const TString & ) fld [ j ] , get ( ( const TString & ) fld [ j ] ) ) ;
if ( lcf )
makelc ( ( TRectype & ) nrec ) ;
memcpy ( DB_getrecord ( i0 - > fhnd ) , nrec . string ( ) , DB_reclen ( i0 - > fhnd ) ) ;
err = DB_add ( i0 - > fhnd ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
setstatus ( err ) ;
}
err = DB_close ( i0 - > fhnd ) ;
close ( ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
relisfd ( i0 ) ;
p . setstatus ( nitems ) ;
if ( err = = NOERR )
{
long c = DB_getconf ( ) ;
fname . ext ( " dbf " ) ;
tmpfname . ext ( " dbf " ) ;
fcopy ( ( const char * ) tmpfname , ( const char * ) fname ) ;
: : remove ( ( const char * ) tmpfname ) ;
if ( c & 1 ) // FOXPRO format
tmpfname . ext ( " cdx " ) ;
if ( c & 4 ) // DBIV format
tmpfname . ext ( " mdx " ) ;
if ( c & 8 | | c & 2 )
{
tmpfname . ext ( " cgp " ) ;
char in [ 16 ] ;
FILE * fp = fopen ( ( const char * ) tmpfname , " r " ) ;
while ( fgets ( in , 16 , fp ) ! = NULL )
{
TFilename a ( in ) ;
a . rtrim ( 1 ) ; // Cut \n
if ( c & 8 ) // DBIII format
a . ext ( " ndx " ) ;
else
a . ext ( " ntx " ) ; // CLIPPER format
: : remove ( ( const char * ) a ) ;
}
fclose ( fp ) ;
1995-07-03 07:49:30 +00:00
}
1995-07-20 09:10:38 +00:00
: : remove ( ( const char * ) tmpfname ) ;
dir . eod ( ) = ni ;
1995-07-03 07:49:30 +00:00
}
}
1995-07-20 09:10:38 +00:00
dir . set_len ( lenr ) ;
dir . put ( num ( ) , _nordir , _sysdirop ) ;
newrec . put ( num ( ) ) ;
if ( toconvert & & dir . eox ( ) > 0L ) packindex ( ) ;
exec_convapp ( lev , FALSE ) ;
1994-08-22 11:10:49 +00:00
}
1995-07-03 07:49:30 +00:00
setstatus ( err ) ;
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
int TSystemisamfile : : packfile ( bool vis )
1994-08-22 11:10:49 +00:00
1995-07-03 07:49:30 +00:00
{
int err = NOERR ;
TDir d ;
1995-07-20 09:10:38 +00:00
d . get ( num ( ) , _nolock , _nordir , _sysdirop ) ;
d . get ( num ( ) , _nolock , ( d . is_com ( ) ) ? _comdir : _nordir ) ;
1995-04-10 15:28:03 +00:00
CHECKS ( filehnd ( ) = = NULL , " Can't pack open file " , ( const char * ) filename ( ) ) ;
1995-07-03 07:49:30 +00:00
err = DB_packfile ( vis , d . name ( ) , d . eod ( ) ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
if ( err ! = NOERR ) error_box ( " Errore in compattamento dati. \n File %d : %d " , num ( ) , err ) ;
setstatus ( err ) ;
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
int TSystemisamfile : : packindex ( bool vis )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-07-03 07:49:30 +00:00
int err = NOERR ;
TRecnotype peod ;
TTrec r ;
TDir d ;
1995-04-10 15:28:03 +00:00
CHECKS ( filehnd ( ) = = NULL , " Can't pack index of open file " , ( const char * ) filename ( ) ) ;
1995-07-03 07:49:30 +00:00
r . get ( num ( ) ) ;
1995-08-03 15:07:29 +00:00
d . get ( num ( ) , _nolock , _nordir , _sysdirop ) ;
bool is_com = d . is_com ( ) ;
d . get ( num ( ) , _nolock , is_com ? _comdir : _nordir ) ;
1995-07-03 07:49:30 +00:00
err = DB_packindex ( vis , d . name ( ) , r . rec ( ) , & peod ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
if ( err ! = NOERR ) error_box ( " Errore in compattamento indici. \n File %d : %d " , num ( ) , err ) ;
else
if ( peod > = 0 & & peod ! = d . eod ( ) )
{
d . eod ( ) = peod ;
1995-08-03 15:07:29 +00:00
d . put ( num ( ) , is_com ? _comdir : _nordir ) ;
1995-07-03 07:49:30 +00:00
}
setstatus ( err ) ;
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
1995-07-03 07:49:30 +00:00
int TSystemisamfile : : pack ( bool vis )
{
int err = NOERR ;
if ( ( err = packfile ( vis ) ) = = NOERR )
err = packindex ( vis ) ;
setstatus ( err ) ;
return err ;
}
1994-08-12 10:52:49 +00:00
1994-12-02 13:06:39 +00:00
int TSystemisamfile : : load ( const char * from , char fs , char fd , char rs , bool vis , bool extended )
1994-08-22 11:10:49 +00:00
{
1995-08-03 15:07:29 +00:00
FILE * fl = fopen ( from , " r " ) ;
int err ;
if ( fl ! = NULL )
err = ferror ( fl ) ;
else
{
error_box ( " Non riesco ad aprire il file %s " , from ) ;
return 2 ;
}
1994-09-27 10:19:36 +00:00
TRecnotype r = 0 , e = 0 , nitems = 0 , nread = 0 ;
1994-12-02 13:06:39 +00:00
TString16 firm , year , attprev ( " 00000 " ) ;
if ( extended )
{
TDate d ( TODAY ) ;
TLocalisamfile ditte ( LF_NDITTE ) ;
firm . format ( " %05ld " , main_app ( ) . get_firm ( ) ) ;
year . format ( " %04d " , d . year ( ) ) ;
ditte . zero ( ) ;
ditte . put ( " CODDITTA " , firm ) ;
if ( ditte . read ( ) = = NOERR )
attprev = ditte . get ( " CODATTPREV " ) ;
}
1994-09-27 10:19:36 +00:00
if ( fl = = NULL )
1994-08-22 11:10:49 +00:00
{
1994-09-27 10:19:36 +00:00
clearerr ( fl ) ;
1994-08-22 11:10:49 +00:00
setstatus ( err ) ;
return err ;
}
1994-09-27 10:19:36 +00:00
char w [ 80 ] ;
while ( ( fgets ( w , 80 , fl ) ! = NULL ) )
{
if ( strncmp ( w , " [Data] " , 6 ) = = 0 )
{
nitems = ftell ( fl ) ;
break ;
}
}
fseek ( fl , 0L , SEEK_END ) ;
nitems = ftell ( fl ) - nitems ;
fclose ( fl ) ;
TScanner f ( from ) ;
1994-08-22 11:10:49 +00:00
open ( ) ;
1994-09-27 10:19:36 +00:00
1994-08-22 11:10:49 +00:00
TToken_string s ( 1024 , fs ) ;
bool fixedlen = ( fs = = ' \0 ' ) ;
int nflds = curr ( ) . items ( ) ;
TArray fld ( nflds ) ;
1994-09-27 10:19:36 +00:00
int len [ MaxFields ] ;
1994-08-22 11:10:49 +00:00
TString sfd ( 3 ) ;
TString s1 ( 64 ) ;
1994-09-27 10:19:36 +00:00
bool lcf = FALSE ;
if ( f . paragraph ( " Header " ) )
{
f . equal ( ) ;
const long level = atol ( f . line ( ) ) ;
1995-03-22 09:07:04 +00:00
if ( level > get_std_level ( ) )
error_box ( " L'archivio %s e' stato generato con gli archivi di livello %ld%/%ld. \n Il livello attuale e' %ld/%ld. \n Convertire gli archivi e ripetere l' operazione. " ,
from , level / 100 , level % 100 , get_std_level ( ) / 100 , get_std_level ( ) % 100 ) ;
1994-09-27 10:19:36 +00:00
lcf = getlcf ( level ) ;
nflds = 0 ;
TToken_string s2 ( f . line ( ) ) ;
int p = s2 . find ( ' = ' ) ;
if ( p > 0 )
{
s1 = s2 . left ( p ) ;
s2 . ltrim ( p + 1 ) ;
}
else s1 . cut ( 0 ) ;
while ( s1 = = " Fields " )
{
for ( const char * fd = s2 . get ( ) ; fd ! = NULL ; fd = s2 . get ( ) )
{
TToken_string wfd ( fd , ' , ' ) ;
fld . add ( new TString ( wfd . get ( ) ) ) ;
len [ nflds ] = wfd . get_int ( ) ;
nflds + + ;
}
s2 = f . line ( ) ;
p = s2 . find ( ' = ' ) ;
if ( p > 0 )
{
s1 = s2 . left ( p ) ;
s2 . ltrim ( p + 1 ) ;
}
else s1 . cut ( 0 ) ;
}
}
else
1994-08-22 11:10:49 +00:00
{
1994-09-27 10:19:36 +00:00
for ( int j = 0 ; j < nflds ; j + + )
{
fld . add ( TString ( curr ( ) . fieldname ( j ) ) , j ) ;
const TString & wfld = ( const TString & ) fld [ j ] ;
len [ j ] = ( curr ( ) . type ( wfld ) = = _datefld ) ? 10 : curr ( ) . length ( wfld ) ;
}
1994-08-22 11:10:49 +00:00
}
1994-09-27 10:19:36 +00:00
if ( ! f . paragraph ( " Data " ) )
{
error_box ( " Formato dei dati non valido " ) ;
close ( ) ;
1994-11-10 14:15:41 +00:00
err = 1 ;
setstatus ( err ) ;
return err ;
1994-09-27 10:19:36 +00:00
}
1994-08-22 11:10:49 +00:00
if ( fd ) sfd < < fd ;
int last = NOERR ;
1994-11-11 18:04:29 +00:00
s1 . format ( " Imp. archivio %s \n %6ld records %6ld errori - %3d " , filename ( ) , r , e , last ) ;
1994-09-27 10:19:36 +00:00
TProgind p ( nitems , s1 , TRUE , TRUE , 70 ) ;
s = f . line ( ) ;
while ( s . not_empty ( ) & & ! p . iscancelled ( ) )
1994-08-22 11:10:49 +00:00
{
1994-12-02 13:06:39 +00:00
if ( extended )
{
int p , i ;
while ( ( p = s . find ( " %yr% " ) ) > = 0 )
for ( i = 0 ; i < 4 ; i + + ) s [ p + i ] = year [ i ] ;
while ( ( p = s . find ( " %frm% " ) ) > = 0 )
for ( i = 0 ; i < 5 ; i + + ) s [ p + i ] = firm [ i ] ;
while ( ( p = s . find ( " %att% " ) ) > = 0 )
for ( i = 0 ; i < 5 ; i + + ) s [ p + i ] = attprev [ i ] ;
}
1994-08-22 11:10:49 +00:00
if ( ( r + e ) % 50 = = 0 )
{
1994-11-11 18:04:29 +00:00
s1 . format ( " Imp. archivio %s \n %6ld records %6ld errori - %3d " , filename ( ) , r , e , last ) ;
1994-08-22 11:10:49 +00:00
p . set_text ( s1 ) ;
}
p . setstatus ( nread + 1 ) ;
nread + = s . len ( ) + 1 ;
zero ( ) ;
if ( fixedlen )
{
int pos = 0 ;
1994-09-27 10:19:36 +00:00
for ( int j = 0 ; j < nflds ; j + + )
1994-08-22 11:10:49 +00:00
{
1994-09-27 10:19:36 +00:00
s1 = s . mid ( pos , len [ j ] ) ;
s1 . rtrim ( ) ;
put ( ( const TString & ) fld [ j ] , s1 ) ;
1994-08-22 11:10:49 +00:00
pos + = len [ j ] ;
}
}
else
{
s . restart ( ) ;
1994-09-27 10:19:36 +00:00
for ( int j = 0 ; j < nflds ; j + + )
1994-08-22 11:10:49 +00:00
{
char * s2 = ( char * ) s . get ( ) ;
if ( fd )
{
s2 + + ;
s2 [ strlen ( s2 ) - 1 ] = ' \0 ' ;
}
put ( ( const TString & ) fld [ j ] , s2 ) ;
}
}
if ( write ( ) = = NOERR ) r + + ;
else
{
e + + ;
last = status ( ) ;
}
1994-09-27 10:19:36 +00:00
s = f . line ( ) ;
1994-08-22 11:10:49 +00:00
}
1994-11-11 18:04:29 +00:00
s1 . format ( " Imp. archivio %s \n %6ld records %6ld errori - %3d " , filename ( ) , r , e , last ) ;
1994-08-22 11:10:49 +00:00
p . set_text ( s1 ) ;
close ( ) ;
1994-11-10 14:15:41 +00:00
setstatus ( err ) ;
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
int TSystemisamfile : : dump ( const char * to , int nkey , char fs , char fd , char rs , bool vis , bool withdeleted )
{
1994-08-22 11:10:49 +00:00
FILE * f = fopen ( to , " w " ) ;
int err = ferror ( f ) ;
if ( withdeleted ) nkey = 0 ;
if ( f = = NULL )
{
clearerr ( f ) ;
setstatus ( err ) ;
return err ;
}
open ( ) ;
TString s ( 512 ) ;
bool fixedlen = ( fs = = ' \0 ' ) ;
int nflds = curr ( ) . items ( ) ;
TArray fld ( nflds ) ;
TBit_array rjust ( nflds ) ;
1994-09-27 10:19:36 +00:00
int len [ MaxFields ] ;
1994-08-22 11:10:49 +00:00
for ( int j = 0 ; j < nflds ; j + + )
{
fld . add ( TString ( curr ( ) . fieldname ( j ) ) , j ) ;
1994-09-27 10:19:36 +00:00
const TString & wfld = ( const TString & ) fld [ j ] ;
const TFieldtypes t = curr ( ) . type ( wfld ) ;
rjust . set ( j , t = = _intfld | | t = = _longfld | | t = = _realfld | |
t = = _wordfld | | t = = _intzerofld | | t = = _longzerofld ) ;
len [ j ] = ( t = = _datefld ) ? 10 : curr ( ) . length ( wfld ) ;
1994-08-22 11:10:49 +00:00
}
TRecnotype i = 0 ;
1994-09-01 13:28:55 +00:00
const TRecnotype nitems = nkey ? items ( ) : filehnd ( ) - > d - > EOD ;
1994-08-22 11:10:49 +00:00
s . format ( " Esportazione archivio %s " , filename ( ) ) ;
1994-10-31 16:24:26 +00:00
TProgind p ( nitems , s , TRUE , TRUE , 70 ) ;
1994-08-22 11:10:49 +00:00
TString s1 ;
1994-09-27 10:19:36 +00:00
1995-03-22 09:07:04 +00:00
fprintf ( f , " [Header] \n Version=%ld " , prefix ( ) . filelevel ( ) ) ;
1994-09-27 10:19:36 +00:00
for ( int k = 0 ; k < nflds ; k + + )
{
if ( ( k % 10 ) = = 0 ) fprintf ( f , " \n Fields= " ) ;
else fprintf ( f , " | " ) ;
fprintf ( f , " %s,%d " , ( const char * ) ( const TString & ) fld [ k ] , len [ k ] ) ;
}
fprintf ( f , " \n \n [Data] \n " ) ;
1994-08-22 11:10:49 +00:00
if ( nkey )
{
setkey ( nkey ) ;
for ( first ( ) ; status ( ) = = NOERR & & ! p . iscancelled ( ) ; next ( ) , i + + )
{
p . setstatus ( i + 1 ) ;
s = " " ;
for ( j = 0 ; j < nflds ; j + + )
{
if ( fixedlen )
{
s1 = get ( ( const TString & ) fld [ j ] ) ;
if ( rjust [ j ] ) s1 . right_just ( len [ j ] ) ;
else s1 . left_just ( len [ j ] ) ;
}
else
{
s1 = " " ;
if ( j & & fs ) s1 < < fs ;
if ( fd ) s1 < < fd ;
s1 < < get ( ( const TString & ) fld [ j ] ) ;
if ( fd ) s1 < < fd ;
}
s < < s1 ;
}
fprintf ( f , " %s%c " , ( const char * ) s , rs ) ;
}
}
else
{
for ( i = 0 ; i < nitems & & ! p . iscancelled ( ) ; i + + )
{
1994-11-10 14:15:41 +00:00
zero ( ) ;
1994-08-22 11:10:49 +00:00
p . setstatus ( i + 1 ) ;
readat ( i + 1 ) ;
s = " " ;
if ( withdeleted | | curr ( ) . valid ( ) )
{
for ( j = 0 ; j < nflds ; j + + )
{
if ( fixedlen )
{
s1 = get ( ( const TString & ) fld [ j ] ) ;
if ( rjust [ j ] ) s1 . right_just ( len [ j ] ) ;
else s1 . left_just ( len [ j ] ) ;
}
else
{
s1 = " " ;
if ( j & & fs ) s1 < < fs ;
if ( fd ) s1 < < fd ;
s1 < < get ( ( const TString & ) fld [ j ] ) ;
if ( fd ) s1 < < fd ;
}
s < < s1 ;
}
fprintf ( f , " %s%c " , ( const char * ) s , rs ) ;
}
}
}
1994-09-27 10:19:36 +00:00
p . setstatus ( nitems ) ;
1994-08-22 11:10:49 +00:00
close ( ) ;
fclose ( f ) ;
1994-09-27 10:19:36 +00:00
setstatus ( err ) ;
1994-08-22 11:10:49 +00:00
return err ;
1994-11-24 14:01:20 +00:00
}
1994-08-12 10:52:49 +00:00
# endif // FOXPRO
1994-11-24 14:01:20 +00:00
void TBaseisamfile : : recover ( )
{
}
1994-08-12 10:52:49 +00:00
////////////////////////////////////////////////////////////
// TRectype
////////////////////////////////////////////////////////////
1995-04-10 15:28:03 +00:00
TRectype : : TRectype ( int logicnum ) : _cod ( NULL )
1994-08-22 11:10:49 +00:00
1995-07-03 07:49:30 +00:00
{
1994-08-22 11:10:49 +00:00
_logicnum = logicnum ;
1995-07-03 07:49:30 +00:00
// _i = openf[_logicnum - 1];
if ( openf [ _logicnum - 1 ] ! = NULL )
_length = DB_reclen ( openf [ logicnum - 1 ] - > fhnd ) ;
else
{
TDir wdir ;
wdir . get ( _logicnum , _nolock , _nordir , _sysdirop ) ;
1995-07-20 09:10:38 +00:00
if ( wdir . is_com ( ) )
1995-07-03 07:49:30 +00:00
wdir . get ( _logicnum , _nolock , _comdir , _sysdirop ) ;
_length = wdir . len ( ) ;
}
1994-08-22 11:10:49 +00:00
_rec = new char [ _length ] ;
1994-09-27 10:19:36 +00:00
* _tab = ' \0 ' ;
1995-08-03 13:54:45 +00:00
if ( _length )
zero ( ) ;
else
setempty ( TRUE ) ;
1994-08-12 10:52:49 +00:00
}
1995-07-03 07:49:30 +00:00
TRectype : : TRectype ( const TBaseisamfile * i ) : _cod ( NULL )
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
_logicnum = i - > num ( ) ;
if ( i - > filehnd ( ) ! = NULL )
1995-07-03 07:49:30 +00:00
_length = DB_reclen ( i - > filehnd ( ) - > fhnd ) ;
1994-08-22 11:10:49 +00:00
else
{
TDir wdir ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
wdir . get ( _logicnum , _nolock , _nordir , _sysdirop ) ;
1995-07-20 09:10:38 +00:00
if ( wdir . is_com ( ) )
1994-08-22 11:10:49 +00:00
wdir . get ( _logicnum , _nolock , _comdir , _sysdirop ) ;
_length = wdir . len ( ) ;
}
1995-07-03 07:49:30 +00:00
* _tab = ' \0 ' ;
1994-08-22 11:10:49 +00:00
_rec = new char [ _length ] ;
1995-08-03 13:54:45 +00:00
// _i = i->filehnd();
if ( _length )
zero ( ) ;
else
setempty ( TRUE ) ;
1994-08-12 10:52:49 +00:00
}
TRectype : : TRectype ( const TRectype & r )
1994-09-27 10:19:36 +00:00
: _cod ( NULL )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
_logicnum = r . _logicnum ;
_length = r . len ( ) ;
_rec = new char [ _length ] ;
_rec [ 0 ] = r . _rec [ 0 ] ;
memcpy ( _rec + 1 , r . _rec + 1 , _length - 1 ) ;
1995-04-10 15:28:03 +00:00
// _i = r._i;
1994-09-27 10:19:36 +00:00
strcpy ( _tab , r . _tab ) ;
if ( r . _cod ! = NULL )
_cod = new TRecfield ( * this , " COD " ) ;
1994-08-22 11:10:49 +00:00
setempty ( r . empty ( ) ) ;
1994-08-12 10:52:49 +00:00
}
TRectype : : ~ TRectype ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-09-27 10:19:36 +00:00
if ( _cod ! = NULL ) delete _cod ;
1994-08-22 11:10:49 +00:00
delete _rec ;
1994-08-12 10:52:49 +00:00
}
1994-09-27 10:19:36 +00:00
void TRectype : : settab ( const char * tab )
{
if ( _cod ! = NULL )
{
delete _cod ;
_cod = NULL ;
}
strcpy ( _tab , tab ) ;
if ( * _tab ! = ' \0 ' )
1994-09-28 15:52:37 +00:00
_cod = new TRecfield ( * this , " COD " ) ;
zero ( ) ;
1994-09-27 10:19:36 +00:00
}
1994-08-12 10:52:49 +00:00
TObject * TRectype : : dup ( ) const
{
1994-08-22 11:10:49 +00:00
TRectype * o = new TRectype ( * this ) ;
return o ;
1994-08-12 10:52:49 +00:00
}
HIDDEN bool fld_empty ( const char * s , int len , bool number )
{
1994-08-22 11:10:49 +00:00
/*if (number)
{
for ( ; len ; s + + , len - - )
if ( strchr ( " 0. " , * s ) = = NULL ) return FALSE ;
}
else */
if ( * s )
{
for ( ; len ; s + + , len - - )
if ( * s ! = ' ' ) return FALSE ;
}
return TRUE ;
1994-08-12 10:52:49 +00:00
}
HIDDEN int fld_cmp ( const char * a , const char * b , int len , bool number )
{
1994-08-22 11:10:49 +00:00
for ( int i = 0 ; i < len & & * a = = * b ; b + + , a + + , i + + ) ;
if ( i = = len ) return 0 ;
int res = * a - * b ;
if ( number )
{
b - = i ;
i = 0 ;
}
return fld_empty ( b , len - i , number ) ? 0 : res ;
1994-08-12 10:52:49 +00:00
}
///////////////////////////////////////////////////////////
// TRectype (record di un file)
///////////////////////////////////////////////////////////
1995-04-10 15:28:03 +00:00
RecDes * TRectype : : rec_des ( ) const
{
const isdef * i = openf [ _logicnum - 1 ] ;
NOT_LINKED ( i , " Record description " ) ;
RecDes * r = i - > r ;
CHECK ( r , " Missing record description " ) ;
return r ;
}
1994-08-12 10:52:49 +00:00
int TRectype : : items ( ) const
{
1995-04-10 15:28:03 +00:00
return rec_des ( ) - > NFields ;
1994-08-12 10:52:49 +00:00
}
const char * TRectype : : start ( int nf ) const
{
1995-04-10 15:28:03 +00:00
return string ( ) + rec_des ( ) - > Fd [ nf ] . RecOff ;
1994-08-12 10:52:49 +00:00
}
int TRectype : : compare ( const TSortable & s ) const
{
const TRectype & br = ( const TRectype & ) s ;
1994-08-22 11:10:49 +00:00
int res = 0 ;
1994-08-12 10:52:49 +00:00
if ( br . empty ( ) ) return UNDEFINED ;
for ( int i = 0 ; i < items ( ) ; i + + )
1994-08-22 11:10:49 +00:00
{
const char * b = br . start ( i ) ;
const char * a = start ( i ) ;
1995-04-10 15:28:03 +00:00
const byte typ = rec_des ( ) - > Fd [ i ] . TypeF ;
1994-08-22 11:10:49 +00:00
/* if (typ == _boolfld) res = *a - *b;
else
{ */
1995-04-10 15:28:03 +00:00
const int sz = rec_des ( ) - > Fd [ i ] . Len ;
1994-08-22 11:10:49 +00:00
const bool number = ( typ = = _intfld ) | | ( typ = = _realfld ) | |
( typ = = _longfld ) | | ( typ = = _wordfld ) | |
( typ = = _intzerofld ) | | ( typ = = _longzerofld )
| | ( typ = = _datefld ) ;
if ( fld_empty ( b , sz , number ) ) continue ;
res = : : fld_cmp ( a , b , sz , number ) ;
/* } */
if ( res ) return res ;
}
1994-08-12 10:52:49 +00:00
return 0 ;
}
TFieldtypes TRectype : : type ( const char * fieldname ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "type");
return ( TFieldtypes ) CFieldType ( ( char * ) fieldname , rec_des ( ) ) ;
1994-08-12 10:52:49 +00:00
}
int TRectype : : length ( const char * fieldname ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "length");
return CFieldSize ( ( char * ) fieldname , rec_des ( ) ) ;
1994-08-12 10:52:49 +00:00
}
int TRectype : : ndec ( const char * fieldname ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "dec");
return CFieldDec ( ( char * ) fieldname , rec_des ( ) ) ;
1994-08-12 10:52:49 +00:00
}
bool TRectype : : exist ( const char * fieldname ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "exist");
return findfld ( rec_des ( ) , ( char * ) fieldname ) ! = - 1 ;
1994-08-12 10:52:49 +00:00
}
const char * TRectype : : fieldname ( int i ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "fieldname");
RecDes * rd = rec_des ( ) ;
return i > = 0 & & i < rd - > NFields ? rd - > Fd [ i ] . Name : NULL ;
1994-08-12 10:52:49 +00:00
}
1995-04-20 14:35:14 +00:00
const char * TRectype : : get_str ( const char * fieldname ) const
{
RecDes * rd = rec_des ( ) ;
if ( CFieldType ( ( char * ) fieldname , rd ) = = _datefld )
{
const TRecfield f ( ( TRectype & ) * this , fieldname ) ;
strcpy ( _isam_string , ( const char * ) f ) ;
}
else
1995-07-03 07:49:30 +00:00
{
1995-04-20 14:35:14 +00:00
if ( CGetFieldBuff ( ( char * ) fieldname , rd , _rec , _isam_string ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1995-07-03 07:49:30 +00:00
if ( CFieldType ( ( char * ) fieldname , rd ) = = _boolfld )
{
if ( toupper ( * _isam_string ) = = ' T ' | | toupper ( * _isam_string ) = = ' Y '
| | toupper ( * _isam_string ) = = ' S ' | | toupper ( * _isam_string ) = = ' X ' )
strcpy ( _isam_string , " X " ) ;
else
strcpy ( _isam_string , " " ) ;
}
}
1995-04-20 14:35:14 +00:00
return _isam_string ;
}
1994-08-12 10:52:49 +00:00
# ifndef FOXPRO
1995-04-20 14:35:14 +00:00
const TString & TRectype : : get ( const char * fieldname ) const
{
static TFixed_string tmp ( _isam_string , sizeof ( _isam_string ) ) ;
get_str ( fieldname ) ;
return tmp ;
}
1994-08-12 10:52:49 +00:00
int TRectype : : get_int ( const char * fieldname ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "get_int");
1995-04-20 14:35:14 +00:00
if ( CGetFieldBuff ( ( char * ) fieldname , rec_des ( ) , _rec , _isam_string ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1995-04-10 15:28:03 +00:00
return atoi ( _isam_string ) ;
1994-08-12 10:52:49 +00:00
}
long TRectype : : get_long ( const char * fieldname ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "get_long");
1995-04-20 14:35:14 +00:00
if ( CGetFieldBuff ( ( char * ) fieldname , rec_des ( ) , _rec , _isam_string ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1995-04-10 15:28:03 +00:00
return atol ( _isam_string ) ;
1994-08-12 10:52:49 +00:00
}
word TRectype : : get_word ( const char * fieldname ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "get_word");
1995-04-20 14:35:14 +00:00
if ( CGetFieldBuff ( ( char * ) fieldname , rec_des ( ) , _rec , _isam_string ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1995-04-10 15:28:03 +00:00
return ( word ) atoi ( _isam_string ) ;
1994-08-12 10:52:49 +00:00
}
real TRectype : : get_real ( const char * fieldname ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "get_real");
1995-04-20 14:35:14 +00:00
if ( CGetFieldBuff ( ( char * ) fieldname , rec_des ( ) , _rec , _isam_string ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1995-04-10 15:28:03 +00:00
real r ( _isam_string ) ;
1994-08-22 11:10:49 +00:00
return r ;
1994-08-12 10:52:49 +00:00
}
char TRectype : : get_char ( const char * fieldname ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "get_char");
1994-08-22 11:10:49 +00:00
1995-04-20 14:35:14 +00:00
if ( CGetFieldBuff ( ( char * ) fieldname , rec_des ( ) , _rec , _isam_string ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1995-04-10 15:28:03 +00:00
return * _isam_string ;
1994-08-12 10:52:49 +00:00
}
bool TRectype : : get_bool ( const char * fieldname ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "get_bool");
1995-04-20 14:35:14 +00:00
if ( CGetFieldBuff ( ( char * ) fieldname , rec_des ( ) , _rec , _isam_string ) = = - 1 )
1994-08-22 11:10:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1995-07-03 07:49:30 +00:00
if ( toupper ( * _isam_string ) = = ' T ' | | toupper ( * _isam_string ) = = ' Y '
| | toupper ( * _isam_string ) = = ' S ' | | toupper ( * _isam_string ) = = ' X ' )
return TRUE ;
else
return FALSE ;
1994-08-12 10:52:49 +00:00
}
1995-06-12 10:49:19 +00:00
bool TRectype : : get_memo ( const char * fieldname , TTextfile & txt ) const
{
long val = get_long ( fieldname ) ;
bool ok = FALSE ;
if ( ok = ( val ! = 0l ) )
{
TLocalisamfile f ( _logicnum ) ;
TMemo_file memo ( f . filename ( ) ) ;
ok | = memo . get_field ( txt , val ) ;
}
return ok ;
}
1994-08-12 10:52:49 +00:00
# endif // FOXPRO
TDate TRectype : : get_date ( const char * fieldname ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "get_date");
1994-08-22 11:10:49 +00:00
const TRecfield f ( ( TRectype & ) * this , fieldname ) ;
return ( TDate ) f ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
void TRectype : : put ( const char * fieldname , int val )
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "put");
if ( CPutField ( ( char * ) fieldname , rec_des ( ) , & val , _rec ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
}
void TRectype : : put ( const char * fieldname , long val )
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "put");
if ( CPutField ( ( char * ) fieldname , rec_des ( ) , & val , _rec ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
}
1995-06-13 08:23:45 +00:00
void TRectype : : put ( const char * fieldname , TTextfile & txt )
1995-06-12 10:49:19 +00:00
{
long val = get_long ( fieldname ) ;
1995-06-12 16:04:15 +00:00
bool isnew = val = = 0 ;
1995-06-12 10:49:19 +00:00
TLocalisamfile f ( _logicnum ) ;
TMemo_file memo ( f . filename ( ) ) ;
long id = memo . set_field ( txt , isnew ? - 1 : val ) ;
1995-06-22 09:30:05 +00:00
if ( isnew ) val = id ;
TString16 str ; str < < val ;
1995-06-12 10:49:19 +00:00
1995-06-22 09:30:05 +00:00
if ( CPutFieldBuff ( ( char * ) fieldname , rec_des ( ) , ( char * ) ( const char * ) str , _rec ) = = - 1 )
1995-06-12 10:49:19 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
}
1994-08-12 10:52:49 +00:00
void TRectype : : put ( const char * fieldname , word val )
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "put");
if ( CPutField ( ( char * ) fieldname , rec_des ( ) , & val , _rec ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1994-08-22 11:10:49 +00:00
setempty ( FALSE ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : put ( const char * fieldname , const real & val )
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "put");
if ( CPutField ( ( char * ) fieldname , rec_des ( ) , val . ptr ( ) , _rec ) = = - 1 )
1994-08-22 11:10:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : put ( const char * fieldname , const TDate & val )
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "put");
1994-08-22 11:10:49 +00:00
TRecfield f ( * this , fieldname ) ;
1995-05-09 09:12:26 +00:00
f = val . string ( full ) ;
1994-08-22 11:10:49 +00:00
setempty ( FALSE ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : put ( const char * fieldname , char val )
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "put");
1994-08-12 10:52:49 +00:00
char w [ 2 ] = { val , ' \0 ' } ;
1995-04-10 15:28:03 +00:00
if ( CPutFieldBuff ( ( char * ) fieldname , rec_des ( ) , w , _rec ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
}
void TRectype : : put ( const char * fieldname , bool val )
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "put");
1995-07-03 07:49:30 +00:00
char * s = val ? " T " : " F " ;
1995-04-10 15:28:03 +00:00
if ( CPutFieldBuff ( ( char * ) fieldname , rec_des ( ) , s , _rec ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
}
# endif // FOXPRO
void TRectype : : put ( const char * fieldname , const char * val )
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "put");
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
if ( val = = NULL | | * val = = ' \0 ' ) // Da provare
{
TRecfield f ( * this , fieldname ) ;
if ( * f . pos ( ) = = ' \0 ' ) return ;
}
1994-08-12 10:52:49 +00:00
1995-04-10 15:28:03 +00:00
if ( CFieldType ( ( char * ) fieldname , rec_des ( ) ) = = _datefld )
1994-08-22 11:10:49 +00:00
{
TRecfield f ( * this , fieldname ) ;
f = val ;
}
else
1995-07-03 07:49:30 +00:00
{
TString wval ;
wval = val ;
if ( CFieldType ( ( char * ) fieldname , rec_des ( ) ) = = _boolfld )
{
if ( toupper ( * val ) = = ' T ' | | toupper ( * val ) = = ' Y '
| | toupper ( * val ) = = ' S ' | | toupper ( * val ) = = ' X ' )
wval = " T " ;
else
wval = " F " ;
}
if ( CPutFieldBuff ( ( char * ) fieldname , rec_des ( ) , ( char * ) ( const char * ) wval , _rec ) = = - 1 )
1994-08-22 11:10:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1995-07-03 07:49:30 +00:00
}
1994-08-22 11:10:49 +00:00
setempty ( FALSE ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : zero ( const char * fieldname )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "zero");
1994-09-27 10:19:36 +00:00
if ( _cod ! = NULL & & strcmp ( fieldname , " COD " ) = = 0 )
* _cod = _tab ;
else
1995-06-15 10:30:27 +00:00
{
if ( CFieldType ( ( char * ) fieldname , rec_des ( ) ) = = _datefld )
{
TRecfield f ( * this , fieldname ) ;
f = " " ;
}
else
if ( CZeroField ( ( char * ) fieldname , rec_des ( ) , _rec ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
}
1994-08-12 10:52:49 +00:00
}
void TRectype : : zero ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
zero ( ' \0 ' ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : zero ( char c )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "zero");
1994-08-22 11:10:49 +00:00
recall ( ) ;
memset ( _rec + 1 , c , len ( ) - 1 ) ;
1994-12-28 15:01:04 +00:00
1994-09-27 10:19:36 +00:00
if ( _cod ! = NULL )
1994-12-28 15:01:04 +00:00
* _cod = _tab ;
1994-08-22 11:10:49 +00:00
setempty ( TRUE ) ;
1994-08-12 10:52:49 +00:00
}
// Certified 99%
TRectype & TRectype : : operator = ( const TRectype & rec )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-09-27 10:19:36 +00:00
CHECK ( num ( ) = = rec . num ( ) , " Can't assign records of different file " ) ;
1994-08-12 10:52:49 +00:00
1995-04-10 15:28:03 +00:00
// _i = rec._i; // Copy filehndl
1994-08-12 10:52:49 +00:00
memcpy ( _rec , rec . _rec , _length ) ; // Copy contents
setempty ( rec . empty ( ) ) ; // Copy emptiness status
return * this ;
}
// Certified 100%
TRectype & TRectype : : operator = ( const TBaseisamfile & f )
{
1994-08-22 11:10:49 +00:00
return * this = f . curr ( ) ;
1994-08-12 10:52:49 +00:00
}
// Certified 99%
TRectype & TRectype : : operator = ( const char * rec )
{
memcpy ( _rec , rec , _length ) ;
setempty ( FALSE ) ;
return * this ;
}
const char * TRectype : : key ( int numkey ) const
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(_i, "key");
1995-07-05 11:12:13 +00:00
CBuildKey ( rec_des ( ) , numkey , _rec , _isam_string , FALSE ) ;
1995-04-10 15:28:03 +00:00
return _isam_string ;
1994-08-12 10:52:49 +00:00
}
///////////////////////////////////////////////////////////
// TRecfield (campo/sottocampo di un record)
///////////////////////////////////////////////////////////
void TRecfield : : set ( int from , int to )
{
1994-08-22 11:10:49 +00:00
int nf ;
1995-04-10 15:28:03 +00:00
RecDes * rd = _rec - > rec_des ( ) ;
1994-08-22 11:10:49 +00:00
1995-04-10 15:28:03 +00:00
if ( ( nf = findfld ( rd , _name ) ) = = - 1 )
1994-08-22 11:10:49 +00:00
{
_p = NULL ;
_len = 0 ;
_dec = 0 ;
_type = _nullfld ;
yesnofatal_box ( " File n. %d unknown field %s " , _rec - > num ( ) , _name ) ;
}
else
{
CHECK ( from > = 0 , " Invalid Start " ) ;
1995-04-10 15:28:03 +00:00
_p = _rec - > string ( ) + rd - > Fd [ nf ] . RecOff + from ;
_dec = rd - > Fd [ nf ] . Dec ;
_type = rd - > Fd [ nf ] . TypeF ;
1994-08-22 11:10:49 +00:00
if ( to > = 0 )
{
1995-04-10 15:28:03 +00:00
CHECK ( from < = to & & to < = rd - > Fd [ nf ] . Len ,
1994-08-22 11:10:49 +00:00
" Invalid Range " ) ;
_len = to - from + 1 ;
}
1995-04-10 15:28:03 +00:00
else _len = rd - > Fd [ nf ] . Len - from ;
1994-08-22 11:10:49 +00:00
}
1994-08-12 10:52:49 +00:00
}
TRecfield : : TRecfield ( TRectype & rec , const char * name , int from , int to )
{
1995-04-10 15:28:03 +00:00
// NOT_LINKED(rec.filehnd(), "TRecfield");
1994-08-22 11:10:49 +00:00
strcpy ( _name , name ) ;
_rec = & rec ;
set ( from , to ) ;
1994-08-12 10:52:49 +00:00
}
HIDDEN void __getfieldbuff ( byte l , byte t , const char * recin , char * s )
{
1994-08-22 11:10:49 +00:00
if ( recin = = NULL )
{
* s = ' \0 ' ;
return ;
}
1995-07-19 09:57:25 +00:00
if ( t ! = _alfafld & & t ! = _datefld )
{
if ( t = = _intzerofld | | t = = _longzerofld )
{
byte i = 0 ;
for ( char * c = ( char * ) recin ; i < l ; c + + , i + + )
if ( * c = = ' ' ) * c = ' 0 ' ;
else break ;
if ( i = = l )
l = 0 ;
1994-08-22 11:10:49 +00:00
}
1995-07-19 09:57:25 +00:00
else
1994-08-22 11:10:49 +00:00
{
1995-07-19 09:57:25 +00:00
while ( ( * recin = = ' ' ) & & ( l ) )
1994-08-22 11:10:49 +00:00
{
recin + + ;
l - - ;
}
1995-07-19 09:57:25 +00:00
if ( ( t ! = _realfld ) & & ( t ! = _charfld ) )
{
while ( ( * recin = = ' 0 ' ) & & ( l ) )
{
recin + + ;
l - - ;
}
}
}
1994-08-22 11:10:49 +00:00
}
1995-07-19 09:57:25 +00:00
1994-08-22 11:10:49 +00:00
if ( l )
{
strncpy ( s , recin , l ) ;
1995-02-09 14:47:31 +00:00
for ( int i = l - 1 ; i > = 0 & & s [ i ] = = ' ' ; i - - ) ;
l = byte ( i + 1 ) ;
1994-08-22 11:10:49 +00:00
}
1995-07-19 09:57:25 +00:00
s [ l ] = ' \0 ' ;
if ( * s )
1995-07-04 07:31:04 +00:00
{
1995-07-19 09:57:25 +00:00
if ( t = = _datefld )
{
const TDate dt ( atol ( s ) ) ;
strcpy ( s , dt . string ( full ) ) ;
} else
if ( t = = _boolfld )
{
const char ok = toupper ( * s ) ;
if ( ok = = ' T ' | | ok = = ' Y ' | | ok = = ' S ' | | ok = = ' X ' )
strcpy ( s , " X " ) ;
else
strcpy ( s , " " ) ;
}
1995-07-04 07:31:04 +00:00
}
1994-08-12 10:52:49 +00:00
}
HIDDEN void __putfieldbuff ( byte l , byte d , byte t , const char * s , char * recout )
{
1994-08-22 11:10:49 +00:00
int len , i ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
if ( recout = = NULL ) return ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
char s2 [ 256 ] ;
strcpy ( s2 , s ) ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
if ( t = = _datefld )
{
if ( * s2 )
{
1995-07-19 09:57:25 +00:00
const TDate dt ( s2 ) ;
1995-07-03 07:49:30 +00:00
sprintf ( s2 , " %8s " , dt . string ( ANSI ) ) ;
1994-08-22 11:10:49 +00:00
}
1995-07-04 07:31:04 +00:00
}
else
if ( t = = _boolfld )
1995-07-19 09:57:25 +00:00
{
const char ok = toupper ( * s2 ) ;
if ( ok = = ' T ' | | ok = = ' Y ' | | ok = = ' S ' | | ok = = ' X ' )
strcpy ( s2 , " T " ) ;
1995-07-04 07:31:04 +00:00
else
1995-07-19 09:57:25 +00:00
strcpy ( s2 , " F " ) ;
1995-07-04 07:31:04 +00:00
}
else
if ( t = = _realfld ) setdec ( s2 , d ) ;
1994-08-22 11:10:49 +00:00
len = strlen ( s2 ) ;
1995-07-19 09:57:25 +00:00
if ( len > l )
{
yesnofatal_box ( " Impossibile scrivere %d caratteri su di un campo di %d " , ( int ) len , ( int ) l ) ;
return ;
}
if ( ( t = = _intfld ) | |
( t = = _longfld ) | |
( t = = _wordfld ) | |
( t = = _realfld ) | |
( t = = _intzerofld ) | |
( t = = _longzerofld )
)
1994-08-22 11:10:49 +00:00
{
if ( len = = 0 )
{
strcpy ( s2 , " 0 " ) ;
len = 1 ;
1995-07-19 09:57:25 +00:00
}
const char c = ( t = = _intzerofld | | t = = _longzerofld ) ? ' 0 ' : ' ' ;
1994-08-22 11:10:49 +00:00
i = 0 ;
1995-07-19 09:57:25 +00:00
while ( i < l - len - 1 ) recout [ i + + ] = c ;
1994-08-22 11:10:49 +00:00
strncpy ( & recout [ l - len - 1 ] , s2 , len ) ;
}
else
{
strncpy ( recout , s2 , len ) ;
while ( len < l ) recout [ len + + ] = ' ' ;
}
1994-08-12 10:52:49 +00:00
}
int TRecfield : : operator = ( int i )
{
1994-08-22 11:10:49 +00:00
if ( _type = = _intzerofld )
1995-04-20 14:35:14 +00:00
sprintf ( _isam_string , " %0*d " , _len , i ) ;
1994-08-22 11:10:49 +00:00
else
1995-04-20 14:35:14 +00:00
sprintf ( _isam_string , " %d " , i ) ;
1995-04-10 15:28:03 +00:00
__putfieldbuff ( _len , _dec , _type , _isam_string , _p ) ;
1994-08-22 11:10:49 +00:00
_rec - > setempty ( FALSE ) ;
return i ;
1994-08-12 10:52:49 +00:00
}
long TRecfield : : operator = ( long l )
{
1994-08-22 11:10:49 +00:00
if ( _type = = _longzerofld )
1995-04-20 14:35:14 +00:00
sprintf ( _isam_string , " %0*ld " , _len , l ) ;
1994-08-22 11:10:49 +00:00
else
1995-04-20 14:35:14 +00:00
sprintf ( _isam_string , " %ld " , l ) ;
1995-04-10 15:28:03 +00:00
__putfieldbuff ( _len , _dec , _type , _isam_string , _p ) ;
1994-08-22 11:10:49 +00:00
_rec - > setempty ( FALSE ) ;
return l ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
1995-05-09 13:33:34 +00:00
1994-08-12 10:52:49 +00:00
const real & TRecfield : : operator = ( const real & r )
{
1995-04-20 14:35:14 +00:00
strcpy ( _isam_string , r . string ( ) ) ;
1995-04-10 15:28:03 +00:00
__putfieldbuff ( _len , _dec , _type , _isam_string , _p ) ;
1994-08-22 11:10:49 +00:00
_rec - > setempty ( FALSE ) ;
return r ;
1994-08-12 10:52:49 +00:00
}
1995-04-20 14:35:14 +00:00
1994-08-12 10:52:49 +00:00
# endif // FOXPRO
const TDate & TRecfield : : operator = ( const TDate & d )
{
1995-04-20 14:35:14 +00:00
strcpy ( _isam_string , ( const char * ) d ) ;
1995-04-10 15:28:03 +00:00
__putfieldbuff ( _len , _dec , _type , _isam_string , _p ) ;
1994-08-22 11:10:49 +00:00
_rec - > setempty ( FALSE ) ;
return d ;
1994-08-12 10:52:49 +00:00
}
const char * TRecfield : : operator = ( const char * s )
{
1994-08-22 11:10:49 +00:00
__putfieldbuff ( _len , _dec , _type , s , _p ) ;
_rec - > setempty ( FALSE ) ;
return s ;
1994-08-12 10:52:49 +00:00
}
void TRecfield : : setptr ( TRecnotype r )
{
1994-08-22 11:10:49 +00:00
if ( _p = = NULL ) return ;
bool n = r < 0 ;
unsigned char * wp = ( unsigned char * ) _p ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
if ( n ) r = - r ;
while ( wp - ( unsigned char * ) _p < = 3 )
{
* wp = r & & 0x000000FF ;
r > > = 8 ;
wp + + ;
}
if ( n ) * wp + = 128 ;
1994-08-12 10:52:49 +00:00
}
TRecfield : : operator int ( ) const
{
1995-04-20 14:35:14 +00:00
__getfieldbuff ( _len , _type , _p , _isam_string ) ;
1995-04-10 15:28:03 +00:00
return atoi ( _isam_string ) ;
1994-08-12 10:52:49 +00:00
}
TRecfield : : operator long ( ) const
{
1995-04-20 14:35:14 +00:00
__getfieldbuff ( _len , _type , _p , _isam_string ) ;
1995-04-10 15:28:03 +00:00
return atol ( _isam_string ) ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
1995-05-09 13:33:34 +00:00
TRecfield : : operator const real ( ) const
1994-08-12 10:52:49 +00:00
{
1995-04-20 14:35:14 +00:00
__getfieldbuff ( _len , _type , _p , _isam_string ) ;
1995-04-10 15:28:03 +00:00
real r ( _isam_string ) ;
1994-08-22 11:10:49 +00:00
return r ;
1994-08-12 10:52:49 +00:00
}
1995-05-09 13:33:34 +00:00
1994-08-12 10:52:49 +00:00
# endif // FOXPRO
TRecfield : : operator TDate ( ) const
{
1994-08-22 11:10:49 +00:00
static TDate d ;
1995-04-20 14:35:14 +00:00
__getfieldbuff ( _len , _type , _p , _isam_string ) ;
1995-04-10 15:28:03 +00:00
d = _isam_string ;
1994-08-22 11:10:49 +00:00
return d ;
1994-08-12 10:52:49 +00:00
}
TRecfield : : operator const char * ( ) const
{
1995-04-20 14:35:14 +00:00
__getfieldbuff ( _len , _type , _p , _isam_string ) ;
1995-04-10 15:28:03 +00:00
return _isam_string ;
1994-08-12 10:52:49 +00:00
}
TRecnotype TRecfield : : ptr ( ) const
{
1994-08-22 11:10:49 +00:00
if ( _p = = NULL ) return ( - 1L ) ;
unsigned char * wp = ( unsigned char * ) _p + 3 ;
TRecnotype r = * wp ;
bool n = r > 127 ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
if ( n ) r - = 128 ;
while ( wp - - > ( unsigned char * ) _p ) r = r < < 8 + * wp ;
return n ? - r : r ;
1994-08-12 10:52:49 +00:00
}
void TTransaction : : begin ( )
{
}
void TTransaction : : end ( bool success )
{
1995-07-03 07:49:30 +00:00
if ( success ) ;
else ;
1994-08-12 10:52:49 +00:00
}