Aggiunti campi memo

git-svn-id: svn://10.65.10.50/trunk@2195 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
matteo 1995-11-22 13:46:11 +00:00
parent cc7a4e7aaa
commit 588c70089f
2 changed files with 337 additions and 69 deletions

View File

@ -124,6 +124,22 @@ int get_error(int err)
return(NOERR);
}
HIDDEN bool lf_has_memo( const int lffile )
{
TTrec r;
r.get( lffile );
bool ret = FALSE;
int nfields = r.fields( );
for( int i = 0; i < nfields && !ret; i ++ )
{
TToken_string s( r.fielddef( i ) );
if ( s.get_int( 1 ) == _memofld )
ret = TRUE;
}
return ret;
}
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
@ -344,6 +360,101 @@ void set_autoload_new_files(bool on)
__autoload = on;
}
void TMemo_info::put( const char * fieldname, const char * data )
{
int index( findfld( rec_des( ), ( char * ) fieldname ) );
_dirty.set( index );
_data.add( data, index );
}
TMemo_info::TMemo_info( const int lfid, const TRecnotype recno )
{
_lfid = lfid;
_recno = recno;
}
TMemo_info::~TMemo_info( )
{
}
TString& TMemo_info::get( const char * fieldname )
{
TLocalisamfile posfile( _lfid );
int index( findfld( posfile.curr( ).rec_des( ), ( char * )( const char * )fieldname ) );
if ( _data.objptr( index ) )
{
if( _dirty[ index ] )
return _data.row( index );
}
if( _recno >= 0 )
{
isdef * def = posfile.filehnd( );
DB_go( def->fhnd, _recno );
_data.add( DB_memoptr( def->fhnd, fieldname ), index );
}
else
_data.add( "", index );
return _data.row( index );
}
RecDes * TMemo_info::rec_des( ) const
{
const isdef* i = openf[ _lfid - 1 ];
CHECKD(i, "Can't use a record of closed file ", _lfid );
RecDes* r = i->r;
CHECKD(r, "Missing record description of file", _lfid );
return r;
}
void TMemo_info::write_data( )
{
TLocalisamfile posfile( _lfid );
isdef * def = posfile.filehnd( );
CHECK( _recno > 0, "Maiale! Non fare le GO con _recno < 0 " );
DB_go( def->fhnd, _recno );
RecDes *r = rec_des( );
for( int i = _data.last( ); i > 0; i = _data.pred( i ) )
DB_memowrite( def->fhnd, r->Fd[ i ].Name, ( char * )( const char * )_data.row( i ) );
reset( );
}
bool TMemo_info::memo_loaded( const char * fieldname )
{
TLocalisamfile posfile( _lfid );
int index( findfld( posfile.curr( ).rec_des( ), ( char * )( const char * )fieldname ) );
return ( _data.objptr( index ) != NULL );
}
TMemo_info::TMemo_info( TMemo_info& memoinfo )
{
_lfid = memoinfo._lfid;
_recno = memoinfo._recno;
_data = memoinfo._data;
_dirty = memoinfo._dirty;
}
void TMemo_info::reset( )
{
_data.destroy( );
_dirty.reset( );
}
void TRectype::init_memo_info( const int lf, const TRecnotype recnum )
{
if( _memoinfo )
delete _memoinfo;
_memoinfo = new TMemo_info( lf, recnum );
}
void TRectype::write_memo_info( ) const
{
CHECK( _memoinfo, "Tentativo di registrare una TMemo_info vuota," );
_memoinfo->write_data( );
}
///////////////////////////////////////////////////////////
// TExtrectype
///////////////////////////////////////////////////////////
@ -403,7 +514,8 @@ TBaseisamfile::TBaseisamfile(int logicnum, bool linkrecinst)
// _historicfile = ((r.field(RFLD_SYS_DATE) != FIELDERR) &&
// (r.field(RFLD_SYS_FIRST) != FIELDERR) &&
// (r.field(RFLD_SYS_LAST) != FIELDERR));
_historicfile = FALSE;
_historicfile = FALSE;
_has_memo = lf_has_memo( _logicnum );
}
@ -439,9 +551,9 @@ int TBaseisamfile::gethr(TRectype& rec, TDate& atdate)
fd1(wr, RFLD_SYS_DATE);
TDate d1;
TRecnotype wr0 = -1L, wr1 = -1L;
TRecnotype wr0 = RECORD_NON_FISICO, wr1 = RECORD_NON_FISICO;
if ((wr0 == flf.ptr()) == -1L) return _iskeynotfound;
if ((wr0 == flf.ptr()) == RECORD_NON_FISICO) return _iskeynotfound;
_hf.read(wr.string(), wr0);
if ((d1 = (const TDate&) fd1) > atdate)
{
@ -526,6 +638,11 @@ const char* TBaseisamfile::description() const
return _isamfile->d->Des;
}
bool TBaseisamfile::has_memo( )
{
return _has_memo;
}
TRecnotype TBaseisamfile::eod() const
{
NOT_OPEN();
@ -560,6 +677,10 @@ int TBaseisamfile::first(word lockop)
_lasterr=cisread(_isamfile, curr(), _isfirst + lockop);
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
_recno = _isamfile->RecNo;
if( has_memo( ) )
{
curr( ).init_memo_info( _logicnum, _recno );
}
return _lasterr;
}
@ -572,6 +693,10 @@ int TBaseisamfile::last(word lockop)
_lasterr=cisread(_isamfile, curr(), _islast + lockop );
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
_recno = _isamfile->RecNo;
if( has_memo( ) )
{
curr( ).init_memo_info( _logicnum, _recno );
}
return _lasterr;
}
@ -593,10 +718,14 @@ int TBaseisamfile::next(word lockop)
}
else
{
_lasterr=cisread(_isamfile, curr(), _isnext + lockop);
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
}
_lasterr=cisread(_isamfile, curr(), _isnext + lockop);
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
}
_recno = _isamfile->RecNo;
if( has_memo( ) )
{
curr( ).init_memo_info( _logicnum, _recno );
}
return _lasterr;
}
@ -627,6 +756,10 @@ int TBaseisamfile::prev(word lockop)
_lasterr=cisread(_isamfile, curr(), _isprev + lockop);
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
_recno = _isamfile->RecNo;
if( has_memo( ) )
{
curr( ).init_memo_info( _logicnum, _recno );
}
return _lasterr;
}
@ -647,6 +780,10 @@ int TBaseisamfile::reread(word lockop, TDate& atdate)
_lasterr=cisread(_isamfile, curr(), _iscurr + lockop);
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
_recno = _isamfile->RecNo;
if( has_memo( ) )
{
curr( ).init_memo_info( _logicnum, _recno );
}
return _lasterr;
}
@ -659,6 +796,10 @@ int TBaseisamfile::reread(TRectype& rec, word lockop, TDate& atdate)
_lasterr=cisread(_isamfile, rec, _iscurr + lockop);
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
_recno = _isamfile->RecNo;
if( has_memo( ) )
{
rec.init_memo_info( _logicnum, _recno );
}
return _lasterr;
}
@ -692,6 +833,10 @@ int TBaseisamfile::skip(TRecnotype nrec, word lockop)
_lasterr=cisread(_isamfile,curr(),_iscurr + lockop);
} while (_lasterr ==_islocked);
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
if( has_memo( ) )
{
curr( ).init_memo_info( _logicnum, _recno );
}
return _lasterr;
}
@ -705,6 +850,10 @@ int TBaseisamfile::read(word op, word lockop, TDate& atdate)
_lasterr=cisread(_isamfile, curr(), op + lockop);
if (_lasterr != NOERR) _lasterr=get_error(_lasterr);
_recno = _isamfile->RecNo;
if( has_memo( ) )
{
curr( ).init_memo_info( _logicnum, _recno );
}
return _lasterr;
}
@ -715,9 +864,13 @@ int TBaseisamfile::read(TRectype& rec, word op, word lockop, TDate& atdate)
CHECKD(op >= _iscurr && op <= _isgteq, "Invalid read operation : ", op);
NOT_OPEN();
rec.setdirty();
_lasterr=cisread(_isamfile, rec, op + lockop);
_lasterr=cisread(_isamfile, rec, op + lockop);
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
_recno = _isamfile->RecNo;
if( has_memo( ) )
{
rec.init_memo_info( _logicnum, _recno );
}
return _lasterr;
}
@ -732,6 +885,10 @@ int TBaseisamfile::readat(TRecnotype nrec, word lockop)
else
memcpy(curr().string(),DB_getrecord(_isamfile->fhnd),DB_reclen(_isamfile->fhnd));
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
if( has_memo( ) )
{
curr( ).init_memo_info( _logicnum, _recno );
}
return _lasterr;
}
@ -746,6 +903,10 @@ int TBaseisamfile::readat(TRectype& rec, TRecnotype nrec, word lockop)
else
memcpy(rec.string(),DB_getrecord(_isamfile->fhnd),DB_reclen(_isamfile->fhnd));
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
if( has_memo( ) )
{
rec.init_memo_info( _logicnum, _recno );
}
return _lasterr;
}
@ -764,6 +925,11 @@ int TBaseisamfile::write(TDate& atdate)
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
setkey(oldkey);
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
if( has_memo( ) )
{
curr( ).memo_info( ).recno( _recno );
curr( ).write_memo_info( );
}
return _lasterr;
}
@ -782,7 +948,15 @@ int TBaseisamfile::write(const TRectype& rec, TDate& atdate)
_lasterr = DB_add(_isamfile->fhnd);
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
setkey(oldkey);
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
if (_lasterr != NOERR )
{
if( has_memo( ) )
{
rec.memo_info( ).recno( _recno );
rec.write_memo_info( );
}
}
return _lasterr;
}
@ -803,6 +977,11 @@ int TBaseisamfile::rewrite(TDate& atdate)
_lasterr = DB_rewrite(_isamfile->fhnd);
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
if( has_memo( ) )
{
curr( ).memo_info( ).recno( _recno );
curr( ).write_memo_info( );
}
}
return _lasterr;
}
@ -823,6 +1002,11 @@ int TBaseisamfile::rewrite(const TRectype& rec, TDate& atdate)
_lasterr = DB_rewrite(_isamfile->fhnd);
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
if( has_memo( ) )
{
rec.memo_info( ).recno( _recno );
rec.write_memo_info( );
}
}
return _lasterr;
}
@ -841,6 +1025,11 @@ int TBaseisamfile::rewriteat(TRecnotype nrec)
} else
_lasterr = get_error(_lasterr);
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
if( has_memo( ) )
{
curr( ).memo_info( ).recno( _recno );
curr( ).write_memo_info( );
}
return _lasterr;
}
@ -857,6 +1046,11 @@ int TBaseisamfile::rewriteat(const TRectype& rec, TRecnotype nrec)
} else
_lasterr = get_error(_lasterr);
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
if( has_memo( ) )
{
rec.memo_info( ).recno( _recno );
rec.write_memo_info( );
}
return _lasterr;
}
@ -867,26 +1061,26 @@ int TBaseisamfile::remove(TDate& atdate)
NOT_OPEN();
// rimozione campi memo
#ifndef FOXPRO
TMemo_file* memo = NULL;
for (int i = 0; i < curr().items(); i++)
{
if (curr().type(curr().fieldname(i)) == _memofld)
/*// rimozione campi memo
#ifndef FOXPRO
TMemo_file* memo = NULL;
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);
}
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;
#endif
}
}
if (memo != NULL) delete memo;
#endif
*/
if ((_lasterr=cisread(_isamfile, curr(), _isequal + _nolock)) == NOERR)
{
_lasterr = DB_delete(_isamfile->fhnd); // Put only deletion flag on record, must remove keys too!
@ -903,6 +1097,7 @@ int TBaseisamfile::remove(TDate& atdate)
}
}
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
curr( ).memo_info( ).recno( RECORD_NON_FISICO );
return _lasterr;
}
@ -929,6 +1124,7 @@ int TBaseisamfile::remove(const TRectype& rec, TDate& atdate)
}
}
}
curr( ).memo_info( ).recno( RECORD_NON_FISICO );
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
return _lasterr;
}
@ -996,7 +1192,7 @@ int TBaseisamfile::_open(unsigned int mode)
}
filehnd()->ln = num();
openf[num() - 1] = filehnd();
_recno = -1L;
_recno = RECORD_NON_FISICO;
CHECKD(filehnd()->r->NKeys > 0, "File senza indici: ", num());
setkey(1);
@ -1331,7 +1527,7 @@ int TIsamtempfile::open(const char* radix, bool create, TRecnotype eod, TRecnoty
filehnd()->ln = -num();
filehnd()->knum = 1;
}
_recno = -1L;
_recno = RECORD_NON_FISICO;
setstatus(err);
return err;
}
@ -2034,6 +2230,7 @@ TRectype::TRectype(int logicnum) : _cod(NULL)
{
_logicnum = logicnum;
_memoinfo = NULL;
if (openf[_logicnum - 1] != NULL)
_length = DB_reclen(openf[logicnum - 1]->fhnd);
else
@ -2049,12 +2246,13 @@ TRectype::TRectype(int logicnum) : _cod(NULL)
if (_length)
zero();
else
setempty(TRUE);
setempty(TRUE);
}
TRectype::TRectype(const TBaseisamfile* i): _cod(NULL)
{
_logicnum = i->num();
_memoinfo = NULL;
if (i->filehnd() != NULL)
_length = DB_reclen(i->filehnd()->fhnd);
else
@ -2071,7 +2269,7 @@ TRectype::TRectype(const TBaseisamfile* i): _cod(NULL)
if (_length)
zero();
else
setempty(TRUE);
setempty(TRUE);
}
@ -2080,6 +2278,12 @@ TRectype::TRectype(const TRectype& r)
{
_logicnum = r._logicnum;
if ( r._memoinfo )
{
_memoinfo = new TMemo_info( *r._memoinfo );
}
else
_memoinfo = NULL;
_length = r.len();
_rec = new char [ _length ];
_rec[0] = r._rec[0];
@ -2095,6 +2299,7 @@ TRectype::~TRectype()
{
if (_cod != NULL) delete _cod;
if (_rec != NULL) delete _rec;
if (_memoinfo != NULL ) delete _memoinfo;
}
void TRectype::settab(const char *tab)
@ -2263,7 +2468,7 @@ int TRectype::ndec(const char* fieldname) const
bool TRectype::exist(const char* fieldname) const
{
return findfld(rec_des(), (char*)fieldname) != -1;
return findfld(rec_des(), (char*)fieldname) != FIELDERR;
}
@ -2284,7 +2489,7 @@ const char* TRectype::get_str(const char* fieldname) const
}
else
{
if (CGetFieldBuff((char*) fieldname, rd, _rec, _isam_string) == -1)
if (CGetFieldBuff((char*) fieldname, rd, _rec, _isam_string) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
if (CFieldType((char*) fieldname,rd) == _boolfld)
{
@ -2303,13 +2508,18 @@ const char* TRectype::get_str(const char* fieldname) const
const TString& TRectype::get(const char* fieldname) const
{
static TFixed_string tmp(_isam_string, sizeof(_isam_string));
if( _memoinfo && type( fieldname ) == _memofld )
{
const TString16 fn( fieldname );
return _memoinfo->get( fn );
}
get_str(fieldname);
return tmp;
}
int TRectype::get_int(const char* fieldname) const
{
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1)
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
return atoi(_isam_string);
}
@ -2317,7 +2527,7 @@ int TRectype::get_int(const char* fieldname) const
long TRectype::get_long(const char* fieldname) const
{
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1)
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
return atol(_isam_string);
}
@ -2326,7 +2536,7 @@ long TRectype::get_long(const char* fieldname) const
word TRectype::get_word(const char* fieldname) const
{
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1)
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
return (word)atoi(_isam_string);
}
@ -2334,7 +2544,7 @@ word TRectype::get_word(const char* fieldname) const
real TRectype::get_real(const char* fieldname) const
{
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1)
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
real r(_isam_string);
return r;
@ -2344,7 +2554,7 @@ real TRectype::get_real(const char* fieldname) const
char TRectype::get_char(const char* fieldname) const
{
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1)
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
return *_isam_string;
}
@ -2353,7 +2563,7 @@ char TRectype::get_char(const char* fieldname) const
bool TRectype::get_bool(const char* fieldname) const
{
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1)
if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
if (toupper(*_isam_string) == 'T' || toupper(*_isam_string) == 'Y'
|| toupper(*_isam_string) == 'S' || toupper(*_isam_string) == 'X')
@ -2365,16 +2575,11 @@ bool TRectype::get_bool(const char* fieldname) const
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;
TToken_string memo( get( fieldname ), '\n' );
int last = memo.items( );
for( int i = 0; i < items( ); i ++ )
txt.append( memo.get( i ) );
return TRUE;
}
#endif // FOXPRO
@ -2394,7 +2599,7 @@ TDate TRectype::get_date(const char* fieldname) const
void TRectype::put(const char* fieldname, int val)
{
if (CPutField((char*) fieldname, rec_des(), &val, _rec) == -1)
if (CPutField((char*) fieldname, rec_des(), &val, _rec) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
setempty(FALSE);
}
@ -2403,7 +2608,7 @@ void TRectype::put(const char* fieldname, int val)
void TRectype::put(const char* fieldname, long val)
{
if (CPutField((char*) fieldname, rec_des(), &val, _rec) == -1)
if (CPutField((char*) fieldname, rec_des(), &val, _rec) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
setempty(FALSE);
}
@ -2416,11 +2621,11 @@ void TRectype::put(const char* fieldname, TTextfile& txt)
TMemo_file memo(f.filename());
long id = memo.set_field(txt, isnew ? -1 : val);
long id = memo.set_field(txt, isnew ? FIELDERR : val);
if (isnew) val = id;
TString16 str; str << val;
if (CPutFieldBuff((char*) fieldname, rec_des(), (char*)(const char*)str, _rec) == -1)
if (CPutFieldBuff((char*) fieldname, rec_des(), (char*)(const char*)str, _rec) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
setempty(FALSE);
}
@ -2429,14 +2634,14 @@ void TRectype::put(const char* fieldname, TTextfile& txt)
void TRectype::put(const char* fieldname, word val)
{
if (CPutField((char*) fieldname, rec_des(), &val, _rec) == -1)
if (CPutField((char*) fieldname, rec_des(), &val, _rec) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
setempty(FALSE);
}
void TRectype::put(const char* fieldname, const real& val)
{
if (CPutFieldBuff((char*) fieldname, rec_des(), (char*)(const char*)val.string(), _rec) == -1)
if (CPutFieldBuff((char*) fieldname, rec_des(), (char*)(const char*)val.string(), _rec) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
setempty(FALSE);
}
@ -2453,7 +2658,7 @@ void TRectype::put(const char* fieldname, char val)
{
char w[2] = {val, '\0'};
if (CPutFieldBuff((char*) fieldname, rec_des(), w, _rec) == -1)
if (CPutFieldBuff((char*) fieldname, rec_des(), w, _rec) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
setempty(FALSE);
}
@ -2463,7 +2668,7 @@ void TRectype::put(const char* fieldname, bool val)
{
char* s = val ? "T" : "F";
if (CPutFieldBuff((char*) fieldname, rec_des(), s, _rec) == -1)
if (CPutFieldBuff((char*) fieldname, rec_des(), s, _rec) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
setempty(FALSE);
}
@ -2484,6 +2689,14 @@ void TRectype::put(const char* fieldname, const char* val)
{
TRecfield f(*this, fieldname);
f = val;
return;
}
if(CFieldType((char*) fieldname, rec_des()) == _memofld)
{
// Qui registro il campo memo
CHECK( _memoinfo, "La struttura TMemo_info non è stata allocata!" );
_memoinfo->put( fieldname, val );
}
else
{
@ -2498,7 +2711,7 @@ void TRectype::put(const char* fieldname, const char* val)
else
wval="F";
}
if (CPutFieldBuff((char*) fieldname, rec_des(), (char*) (const char*)wval, _rec) == -1)
if (CPutFieldBuff((char*) fieldname, rec_des(), (char*) (const char*)wval, _rec) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
}
setempty(FALSE);
@ -2518,9 +2731,13 @@ void TRectype::zero(const char* fieldname)
f = "";
}
else
if (CZeroField((char*) fieldname, rec_des(), _rec) == -1)
if (CZeroField((char*) fieldname, rec_des(), _rec) == FIELDERR)
UNKNOWN_FIELD(num(), fieldname);
}
}
if( lf_has_memo( _logicnum ) )
{
init_memo_info( _logicnum, RECORD_NON_FISICO );
}
}
@ -2538,8 +2755,12 @@ void TRectype::zero(char c)
memset(_rec + 1, c, len() - 1);
if (_cod != NULL)
*_cod = _tab;
*_cod = _tab;
if( lf_has_memo( _logicnum ) )
{
init_memo_info( _logicnum, RECORD_NON_FISICO );
}
setempty(TRUE);
}
@ -2620,7 +2841,7 @@ void TRecfield::set(int from, int to)
int nf;
RecDes* rd = _rec->rec_des();
if ((nf = findfld(rd, _name)) == -1)
if ((nf = findfld(rd, _name)) == FIELDERR)
{
_p = NULL;
_len = 0;
@ -2900,7 +3121,7 @@ TRecfield::operator const char*() const
TRecnotype TRecfield::ptr() const
{
if (_p == NULL) return(-1L);
if (_p == NULL) return(RECORD_NON_FISICO);
unsigned char* wp = (unsigned char*) _p + 3;
TRecnotype r = *wp;
bool n = r > 127;

View File

@ -5,6 +5,18 @@
#include <sysfld.h>
#endif
#ifndef __ARRAY_H
#include <array.h>
#endif
#ifndef __ASSOC_H
#include <assoc.h>
#endif
#ifndef __SYSFLD_H
#include <sysfld.h>
#endif
#ifndef FOXPRO
#ifndef __REAL_H
@ -36,9 +48,37 @@ class TTextfile;
// @M
#define FIELDERR -1
#define RECORD_NON_FISICO (-1L)
const int MAX_KEYS = 8;
// @END
class TLocalisamfile;
class TMemo_info : public TObject
{
protected:
TBit_array _dirty;
TString_array _data;
int _lfid;
TRecnotype _recno;
public:
TRecnotype recno( ){ return _recno; }
void recno( TRecnotype r ){ _recno = r; }
RecDes * rec_des( ) const;
void put( const char * fieldname, const char * data );
TString& get( const char * fieldname );
void write_data( );
bool memo_loaded( const char * fieldname );
void reset( );
TMemo_info( const int lfid, const TRecnotype recno );
TMemo_info( TMemo_info& memoinfo );
virtual ~TMemo_info( );
};
// @C
// Classe TRectype : public TObject
//
@ -61,6 +101,7 @@ class TRectype : public TSortable
bool _isempty; // Se il record e' vuoto
char _tab[5]; // identificatore della tabella
TRecfield * _cod; // campo "COD" della tabella
TMemo_info * _memoinfo;
// @END
protected: // TObject
@ -69,7 +110,7 @@ protected: // TObject
protected:
const char* start(int nf) const;
void setempty(bool val) { _isempty = val;} // Rende vero is_empty
void setempty(bool val) { _isempty = val;} // Rende vero is_empty
public: // TObject
virtual TObject* dup() const; // Duplica record
@ -106,7 +147,6 @@ public:
const char* get_str(const char* fieldname) const ;
#ifndef FOXPRO
const TString& get(const char* fieldname) const ;
TString sget(const char* fieldname) const { return ((TString)get(fieldname)); }
int get_int(const char* fieldname) const ;
long get_long(const char* fieldname) const ;
word get_word(const char* fieldname) const ;
@ -158,6 +198,11 @@ public:
TRectype(const TRectype& r); // Costruisce il record a partire da r
virtual ~TRectype();
void init_memo_info( const int lf, const TRecnotype recnum );
TMemo_info& memo_info( ) const { CHECK( _memoinfo, "Tentativo di accesso ad una memoinfo vuota!" ); return *_memoinfo; }
void write_memo_info( ) const;
};
@ -182,7 +227,8 @@ class TBaseisamfile : public TObject
bool _historicfile; // Vero se il file e' archivio storico
TRecnotype _lasthf;
TRecnotype _recno;
bool _has_memo;
friend class TRectype;
friend class TLocalisamfile;
friend class TIsamfile;
@ -209,6 +255,7 @@ protected:
void recover();
int _open(unsigned int mode = _manulock); // Apre isam file con lock
int _close();
const char* filename() const;
public:
@ -284,8 +331,6 @@ public:
#ifndef FOXPRO
const TString& get(const char* fieldname) const
{ return curr().get(fieldname);}
TString sget(const char* fieldname) const
{ return ((TString)get(fieldname)); }
void put(const char* fieldname, int val)
{ curr().put(fieldname, val);}
void put(const char* fieldname, long val)
@ -317,6 +362,8 @@ public:
void zero(char c) { curr().zero(c);}
void blank(const char * fieldname) { curr().blank(fieldname); }
TRectype& operator =(const TRectype& rec) { return curr() = rec;}
bool has_memo( );
TBaseisamfile(int logicnum, bool linkrecinst = FALSE);
virtual ~TBaseisamfile();
@ -409,7 +456,7 @@ public:
//
// File isam temporaneo
//
// @END
// @END TTrec
class TIsamtempfile : public TLocalisamfile
{