Corretti campi memo e aggiunto pack dei file memo
git-svn-id: svn://10.65.10.50/trunk@2247 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
ce29d53f19
commit
f283eea0cb
148
include/isam.cpp
148
include/isam.cpp
@ -124,6 +124,21 @@ int get_error(int err)
|
||||
return(NOERR);
|
||||
}
|
||||
|
||||
HIDDEN bool lf_has_memo( const TTrec& r )
|
||||
{
|
||||
|
||||
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 bool lf_has_memo( const int lffile )
|
||||
{
|
||||
TDir d;
|
||||
@ -372,21 +387,28 @@ void TMemo_info::put( const char * fieldname, const char * data )
|
||||
_data.add( data, index );
|
||||
}
|
||||
|
||||
TMemo_info::TMemo_info( const int lfid, const TRecnotype recno )
|
||||
{
|
||||
_lfid = lfid;
|
||||
_recno = recno;
|
||||
TMemo_info::TMemo_info( const TRectype * owner, const TRecnotype recno )
|
||||
: _owner(owner), _recno(recno)
|
||||
{
|
||||
}
|
||||
|
||||
TMemo_info::~TMemo_info( )
|
||||
{
|
||||
}
|
||||
|
||||
RecDes * TMemo_info::rec_des( ) const
|
||||
{
|
||||
return _owner->rec_des() ;
|
||||
}
|
||||
|
||||
int TMemo_info::num() const
|
||||
{
|
||||
return _owner->num() ;
|
||||
}
|
||||
|
||||
TString& TMemo_info::get( const char * fieldname )
|
||||
{
|
||||
TLocalisamfile posfile( _lfid );
|
||||
int index( findfld( posfile.curr( ).rec_des( ), ( char * )( const char * )fieldname ) );
|
||||
int index( findfld( rec_des( ), ( char * )fieldname ) );
|
||||
if ( _data.objptr( index ) )
|
||||
{
|
||||
if( _dirty[ index ] )
|
||||
@ -394,6 +416,7 @@ TString& TMemo_info::get( const char * fieldname )
|
||||
}
|
||||
if( _recno >= 0 )
|
||||
{
|
||||
TLocalisamfile posfile( num() );
|
||||
isdef * def = posfile.filehnd( );
|
||||
DB_go( def->fhnd, _recno );
|
||||
_data.add( DB_memoptr( def->fhnd, fieldname ), index );
|
||||
@ -403,20 +426,8 @@ TString& TMemo_info::get( const char * fieldname )
|
||||
return _data.row( index );
|
||||
}
|
||||
|
||||
RecDes * TMemo_info::rec_des( ) const
|
||||
void TMemo_info::write_data( isdef * def )
|
||||
{
|
||||
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( );
|
||||
@ -427,14 +438,13 @@ void TMemo_info::write_data( )
|
||||
|
||||
bool TMemo_info::memo_loaded( const char * fieldname )
|
||||
{
|
||||
TLocalisamfile posfile( _lfid );
|
||||
int index( findfld( posfile.curr( ).rec_des( ), ( char * )( const char * )fieldname ) );
|
||||
int index( findfld( rec_des( ), ( char * )( const char * )fieldname ) );
|
||||
return ( _data.objptr( index ) != NULL );
|
||||
}
|
||||
|
||||
TMemo_info::TMemo_info( TMemo_info& memoinfo )
|
||||
TMemo_info::TMemo_info( const TRectype * owner, TMemo_info& memoinfo)
|
||||
: _owner(owner)
|
||||
{
|
||||
_lfid = memoinfo._lfid;
|
||||
_recno = memoinfo._recno;
|
||||
_data = memoinfo._data;
|
||||
_dirty = memoinfo._dirty;
|
||||
@ -446,17 +456,22 @@ void TMemo_info::reset( )
|
||||
_dirty.reset( );
|
||||
}
|
||||
|
||||
void TRectype::init_memo_info( const int lf, const TRecnotype recnum )
|
||||
void TRectype::init_memo_info(const TRecnotype recnum )
|
||||
{
|
||||
if( _memoinfo )
|
||||
delete _memoinfo;
|
||||
_memoinfo = new TMemo_info( lf, recnum );
|
||||
{
|
||||
_memoinfo->reset();
|
||||
_memoinfo->recno( recnum);
|
||||
// delete _memoinfo;
|
||||
}
|
||||
else
|
||||
_memoinfo = new TMemo_info( this, recnum );
|
||||
}
|
||||
|
||||
void TRectype::write_memo_info( ) const
|
||||
void TRectype::write_memo_info( isdef * def ) const
|
||||
{
|
||||
CHECK( _memoinfo, "Tentativo di registrare una TMemo_info vuota," );
|
||||
_memoinfo->write_data( );
|
||||
_memoinfo->write_data( def );
|
||||
}
|
||||
|
||||
|
||||
@ -485,6 +500,8 @@ TExtrectype::TExtrectype(const TTrec& r) : TRectype(6)
|
||||
_length = r.len();
|
||||
_rec = new char [ _length ];
|
||||
_rd = r.rec();
|
||||
if( lf_has_memo(r))
|
||||
init_memo_info(RECORD_NON_FISICO );
|
||||
zero();
|
||||
}
|
||||
|
||||
@ -684,9 +701,7 @@ int TBaseisamfile::first(word lockop)
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
_recno = _isamfile->RecNo;
|
||||
if( has_memo( ) )
|
||||
{
|
||||
curr( ).init_memo_info( _logicnum, _recno );
|
||||
}
|
||||
curr( ).init_memo_info(_recno);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
@ -700,9 +715,7 @@ int TBaseisamfile::last(word lockop)
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
_recno = _isamfile->RecNo;
|
||||
if( has_memo( ) )
|
||||
{
|
||||
curr( ).init_memo_info( _logicnum, _recno );
|
||||
}
|
||||
curr( ).init_memo_info(_recno);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
@ -729,9 +742,7 @@ int TBaseisamfile::next(word lockop)
|
||||
}
|
||||
_recno = _isamfile->RecNo;
|
||||
if( has_memo( ) )
|
||||
{
|
||||
curr( ).init_memo_info( _logicnum, _recno );
|
||||
}
|
||||
curr( ).init_memo_info(_recno );
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
@ -763,9 +774,7 @@ int TBaseisamfile::prev(word lockop)
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
_recno = _isamfile->RecNo;
|
||||
if( has_memo( ) )
|
||||
{
|
||||
curr( ).init_memo_info( _logicnum, _recno );
|
||||
}
|
||||
curr( ).init_memo_info(_recno);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
@ -787,9 +796,7 @@ int TBaseisamfile::reread(word lockop, TDate& atdate)
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
_recno = _isamfile->RecNo;
|
||||
if( has_memo( ) )
|
||||
{
|
||||
curr( ).init_memo_info( _logicnum, _recno );
|
||||
}
|
||||
curr( ).init_memo_info(_recno);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
@ -803,9 +810,7 @@ int TBaseisamfile::reread(TRectype& rec, word lockop, TDate& atdate)
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
_recno = _isamfile->RecNo;
|
||||
if( has_memo( ) )
|
||||
{
|
||||
rec.init_memo_info( _logicnum, _recno );
|
||||
}
|
||||
rec.init_memo_info(_recno);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
@ -840,9 +845,7 @@ int TBaseisamfile::skip(TRecnotype nrec, word lockop)
|
||||
} while (_lasterr ==_islocked);
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
if( has_memo( ) )
|
||||
{
|
||||
curr( ).init_memo_info( _logicnum, _recno );
|
||||
}
|
||||
curr( ).init_memo_info(_recno);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
@ -857,9 +860,7 @@ int TBaseisamfile::read(word op, word lockop, TDate& atdate)
|
||||
if (_lasterr != NOERR) _lasterr=get_error(_lasterr);
|
||||
_recno = _isamfile->RecNo;
|
||||
if( has_memo( ) )
|
||||
{
|
||||
curr( ).init_memo_info( _logicnum, _recno );
|
||||
}
|
||||
curr( ).init_memo_info(_recno);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
@ -874,9 +875,7 @@ int TBaseisamfile::read(TRectype& rec, word op, word lockop, TDate& atdate)
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
_recno = _isamfile->RecNo;
|
||||
if( has_memo( ) )
|
||||
{
|
||||
rec.init_memo_info( _logicnum, _recno );
|
||||
}
|
||||
rec.init_memo_info(_recno);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
@ -892,9 +891,7 @@ int TBaseisamfile::readat(TRecnotype nrec, word lockop)
|
||||
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 );
|
||||
}
|
||||
curr( ).init_memo_info(_recno);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
@ -910,9 +907,7 @@ int TBaseisamfile::readat(TRectype& rec, TRecnotype nrec, word lockop)
|
||||
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 );
|
||||
}
|
||||
rec.init_memo_info( _recno );
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
@ -934,7 +929,7 @@ int TBaseisamfile::write(TDate& atdate)
|
||||
if( has_memo( ) )
|
||||
{
|
||||
curr( ).memo_info( ).recno( _recno );
|
||||
curr( ).write_memo_info( );
|
||||
curr( ).write_memo_info( _isamfile);
|
||||
}
|
||||
return _lasterr;
|
||||
}
|
||||
@ -960,7 +955,7 @@ int TBaseisamfile::write(const TRectype& rec, TDate& atdate)
|
||||
if( has_memo( ) )
|
||||
{
|
||||
rec.memo_info( ).recno( _recno );
|
||||
rec.write_memo_info( );
|
||||
rec.write_memo_info( _isamfile );
|
||||
}
|
||||
}
|
||||
return _lasterr;
|
||||
@ -986,7 +981,7 @@ int TBaseisamfile::rewrite(TDate& atdate)
|
||||
if( has_memo( ) )
|
||||
{
|
||||
curr( ).memo_info( ).recno( _recno );
|
||||
curr( ).write_memo_info( );
|
||||
curr( ).write_memo_info( _isamfile );
|
||||
}
|
||||
}
|
||||
return _lasterr;
|
||||
@ -1011,7 +1006,7 @@ int TBaseisamfile::rewrite(const TRectype& rec, TDate& atdate)
|
||||
if( has_memo( ) )
|
||||
{
|
||||
rec.memo_info( ).recno( _recno );
|
||||
rec.write_memo_info( );
|
||||
rec.write_memo_info( _isamfile );
|
||||
}
|
||||
}
|
||||
return _lasterr;
|
||||
@ -1034,7 +1029,7 @@ int TBaseisamfile::rewriteat(TRecnotype nrec)
|
||||
if( has_memo( ) )
|
||||
{
|
||||
curr( ).memo_info( ).recno( _recno );
|
||||
curr( ).write_memo_info( );
|
||||
curr( ).write_memo_info( _isamfile );
|
||||
}
|
||||
return _lasterr;
|
||||
}
|
||||
@ -1055,7 +1050,7 @@ int TBaseisamfile::rewriteat(const TRectype& rec, TRecnotype nrec)
|
||||
if( has_memo( ) )
|
||||
{
|
||||
rec.memo_info( ).recno( _recno );
|
||||
rec.write_memo_info( );
|
||||
rec.write_memo_info( _isamfile );
|
||||
}
|
||||
return _lasterr;
|
||||
}
|
||||
@ -1830,6 +1825,11 @@ int TSystemisamfile::update(TTrec& newrec, bool vis)
|
||||
browse_null(nrec.string(),DB_reclen(i0->fhnd));
|
||||
memcpy(DB_getrecord(i0->fhnd),nrec.string(),DB_reclen(i0->fhnd));
|
||||
err=DB_add(i0->fhnd);
|
||||
if ( nrec.has_memo())
|
||||
{
|
||||
nrec.memo_info( ).recno( DB_recno(i0->fhnd) );
|
||||
nrec.write_memo_info( i0);
|
||||
}
|
||||
if (err != NOERR) err=get_error(err);
|
||||
setstatus(err);
|
||||
}
|
||||
@ -1898,6 +1898,8 @@ int TSystemisamfile::packfile(bool vis)
|
||||
d.get(num(),_nolock, (d.is_com()) ? _comdir : _nordir);
|
||||
CHECKS(filehnd() == NULL, "Can't pack open file", (const char*)filename());
|
||||
err=DB_packfile(vis,d.name(),d.eod());
|
||||
if (err == NOERR && has_memo())
|
||||
err = DB_packmemo(vis,d.name());
|
||||
if (err != NOERR) err = get_error(err);
|
||||
if (err != NOERR) error_box("Errore in compattamento dati.\nFile %d : %d", num(),err);
|
||||
setstatus(err);
|
||||
@ -2295,9 +2297,7 @@ TRectype::TRectype(const TRectype& r)
|
||||
{
|
||||
_logicnum = r._logicnum;
|
||||
if ( r._memoinfo )
|
||||
{
|
||||
_memoinfo = new TMemo_info( *r._memoinfo );
|
||||
}
|
||||
_memoinfo = new TMemo_info( this, *r._memoinfo);
|
||||
else
|
||||
_memoinfo = NULL;
|
||||
_length = r.len();
|
||||
@ -2751,9 +2751,7 @@ void TRectype::zero(const char* fieldname)
|
||||
UNKNOWN_FIELD(num(), fieldname);
|
||||
}
|
||||
if( lf_has_memo( _logicnum ) )
|
||||
{
|
||||
init_memo_info( _logicnum, RECORD_NON_FISICO );
|
||||
}
|
||||
init_memo_info(RECORD_NON_FISICO );
|
||||
}
|
||||
|
||||
|
||||
@ -2774,9 +2772,7 @@ void TRectype::zero(char c)
|
||||
*_cod = _tab;
|
||||
|
||||
if( lf_has_memo( _logicnum ) )
|
||||
{
|
||||
init_memo_info( _logicnum, RECORD_NON_FISICO );
|
||||
}
|
||||
init_memo_info( RECORD_NON_FISICO );
|
||||
setempty(TRUE);
|
||||
}
|
||||
|
||||
|
@ -54,28 +54,31 @@ const int MAX_KEYS = 8;
|
||||
// @END
|
||||
|
||||
class TLocalisamfile;
|
||||
class TRectype;
|
||||
|
||||
class TMemo_info : public TObject
|
||||
{
|
||||
protected:
|
||||
|
||||
TBit_array _dirty;
|
||||
TString_array _data;
|
||||
int _lfid;
|
||||
TRecnotype _recno;
|
||||
TRecnotype _recno;
|
||||
const TRectype * _owner;
|
||||
|
||||
protected:
|
||||
RecDes * rec_des( ) const;
|
||||
|
||||
public:
|
||||
|
||||
TRecnotype recno( ){ return _recno; }
|
||||
TRecnotype recno( ) const { return _recno; }
|
||||
int num() const ;
|
||||
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( );
|
||||
void write_data( isdef * def );
|
||||
bool memo_loaded( const char * fieldname );
|
||||
void reset( );
|
||||
TMemo_info( const int lfid, const TRecnotype recno );
|
||||
TMemo_info( TMemo_info& memoinfo );
|
||||
TMemo_info( const TRectype * owner, const TRecnotype recno );
|
||||
TMemo_info( const TRectype * owner, TMemo_info& memoinfo);
|
||||
virtual ~TMemo_info( );
|
||||
};
|
||||
|
||||
@ -199,9 +202,10 @@ public:
|
||||
|
||||
virtual ~TRectype();
|
||||
|
||||
void init_memo_info( const int lf, const TRecnotype recnum );
|
||||
void init_memo_info(const TRecnotype recnum );
|
||||
TMemo_info& memo_info( ) const { CHECK( _memoinfo, "Tentativo di accesso ad una memoinfo vuota!" ); return *_memoinfo; }
|
||||
void write_memo_info( ) const;
|
||||
void write_memo_info( isdef * def ) const;
|
||||
bool has_memo() const { return _memoinfo != NULL; }
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user