Funzioni sui file portate a livello record
git-svn-id: svn://10.65.10.50/trunk@4382 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
fb85404c31
commit
3fdd1b2259
306
include/isam.cpp
306
include/isam.cpp
@ -808,9 +808,7 @@ int TBaseisamfile::last(word lockop)
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::next(word lockop)
|
||||
|
||||
int TBaseisamfile::_next(word lockop)
|
||||
{
|
||||
NOT_OPEN();
|
||||
curr().setdirty();
|
||||
@ -833,6 +831,11 @@ int TBaseisamfile::next(word lockop)
|
||||
if( curr().has_memo( ) )
|
||||
curr( ).init_memo(_recno );
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
int TBaseisamfile::next(word lockop)
|
||||
{
|
||||
return curr().next(*this, lockop);
|
||||
}
|
||||
|
||||
|
||||
@ -869,7 +872,6 @@ int TBaseisamfile::prev(word lockop)
|
||||
|
||||
|
||||
int TBaseisamfile::prev(TDate& atdate)
|
||||
|
||||
{
|
||||
error_box("TBaseisamfile::prev(TDate&) is no more available");
|
||||
return NOERR;
|
||||
@ -939,115 +941,65 @@ int TBaseisamfile::skip(TRecnotype nrec, word lockop)
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::read(word op, word lockop, TDate& atdate)
|
||||
|
||||
// funzione di lettura dei file
|
||||
int TBaseisamfile::_read(TRectype& rec, word op, word lockop, TDate& atdate)
|
||||
{
|
||||
CHECKD(op >= _iscurr && op <= _isgteq, "Invalid read operation : ", op);
|
||||
NOT_OPEN();
|
||||
curr().setdirty();
|
||||
_lasterr=cisread(_isamfile, curr(), op + lockop);
|
||||
if (_lasterr != NOERR) _lasterr=get_error(_lasterr);
|
||||
_recno = _isamfile->RecNo;
|
||||
if( curr().has_memo( ) )
|
||||
curr( ).init_memo(_recno);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
if (_lasterr != NOERR) _lasterr=get_error(_lasterr);
|
||||
_recno = _isamfile->RecNo;
|
||||
if( rec.has_memo( ) )
|
||||
rec.init_memo(_recno);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::readat(TRecnotype nrec, word lockop)
|
||||
int TBaseisamfile::read(TRectype& rec, word op, word lockop, TDate& atdate)
|
||||
|
||||
{
|
||||
// CHECKD(op >= _iscurr && op <= _isgteq, "Invalid read operation : ", op);
|
||||
NOT_OPEN();
|
||||
curr().setdirty();
|
||||
_lasterr=DB_go(_isamfile->fhnd,nrec);
|
||||
if (_lasterr != NOERR)
|
||||
_lasterr = get_error(_lasterr);
|
||||
else
|
||||
curr() = (const char *) DB_getrecord(_isamfile->fhnd);
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
if( curr().has_memo( ) )
|
||||
curr( ).init_memo(_recno);
|
||||
_lasterr=rec.read(*this, op, lockop, atdate);
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
int TBaseisamfile::read(word op, word lockop, TDate& atdate)
|
||||
|
||||
{
|
||||
// CHECKD(op >= _iscurr && op <= _isgteq, "Invalid read operation : ", op);
|
||||
return TBaseisamfile::read(curr(),op, lockop, atdate);
|
||||
}
|
||||
|
||||
int TBaseisamfile::readat(TRectype& rec, TRecnotype nrec, word lockop)
|
||||
|
||||
{
|
||||
return rec.readat(*this,nrec,lockop);
|
||||
}
|
||||
|
||||
int TBaseisamfile::readat(TRecnotype nrec, word lockop)
|
||||
{
|
||||
return TBaseisamfile::readat(curr(),nrec,lockop);
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::_readat(TRectype& rec, TRecnotype nrec, word lockop)
|
||||
{
|
||||
NOT_OPEN();
|
||||
rec.setdirty();
|
||||
_lasterr=DB_go(_isamfile->fhnd,nrec);
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
if (_lasterr != NOERR)
|
||||
_lasterr = get_error(_lasterr);
|
||||
else
|
||||
rec = (const char *) DB_getrecord(_isamfile->fhnd);
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
if( rec.has_memo( ) )
|
||||
rec.init_memo( _recno );
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::write(TDate& atdate)
|
||||
{
|
||||
CHECK(!curr().empty(), "Can't write an empty record");
|
||||
|
||||
NOT_OPEN();
|
||||
int oldkey=getkey();
|
||||
browse_null(curr().string(),DB_reclen(_isamfile->fhnd));
|
||||
|
||||
setkey(1);
|
||||
memcpy(DB_getrecord(_isamfile->fhnd),curr().string(),DB_reclen(_isamfile->fhnd));
|
||||
_lasterr = DB_add(_isamfile->fhnd);
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
setkey(oldkey);
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
if(_lasterr == NOERR && curr().has_memo( ))
|
||||
curr( ).write_memo( _isamfile, _recno );
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::write(const TRectype& rec, TDate& atdate)
|
||||
|
||||
int TBaseisamfile::_write(const TRectype& rec, TDate& atdate)
|
||||
{
|
||||
CHECK(!rec.empty(), "Can't write an empty record");
|
||||
|
||||
NOT_OPEN();
|
||||
int oldkey=getkey();
|
||||
browse_null(rec.string(),DB_reclen(_isamfile->fhnd));
|
||||
|
||||
setkey(1);
|
||||
memcpy(DB_getrecord(_isamfile->fhnd),rec.string(),DB_reclen(_isamfile->fhnd));
|
||||
_lasterr = DB_add(_isamfile->fhnd);
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
setkey(oldkey);
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
if (_lasterr == NOERR && rec.has_memo())
|
||||
((TRectype &)rec).write_memo( _isamfile, _recno );
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::rewrite(TDate& atdate)
|
||||
|
||||
{
|
||||
CHECK(!curr().empty(), "Can't rewrite an empty record");
|
||||
|
||||
/*
|
||||
NOT_OPEN();
|
||||
TRectype save_rec(curr());
|
||||
|
||||
@ -1074,11 +1026,39 @@ int TBaseisamfile::rewrite(TDate& atdate)
|
||||
curr( ).write_memo( _isamfile, _recno );
|
||||
}
|
||||
return _lasterr;
|
||||
*/
|
||||
CHECK(!rec.empty(), "Can't write an empty record");
|
||||
|
||||
NOT_OPEN();
|
||||
int oldkey=getkey();
|
||||
browse_null(rec.string(),DB_reclen(_isamfile->fhnd));
|
||||
|
||||
setkey(1);
|
||||
memcpy(DB_getrecord(_isamfile->fhnd),rec.string(),DB_reclen(_isamfile->fhnd));
|
||||
_lasterr = DB_add(_isamfile->fhnd);
|
||||
if (_lasterr != NOERR) _lasterr = get_error(_lasterr);
|
||||
setkey(oldkey);
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
if (_lasterr == NOERR && rec.has_memo())
|
||||
((TRectype &)rec).write_memo( _isamfile, _recno );
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
int TBaseisamfile::write(const TRectype& rec, TDate& atdate)
|
||||
{
|
||||
// CHECK(!rec.empty(), "Can't write an empty record");
|
||||
return rec.write(*this, atdate);
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::rewrite(const TRectype& rec, TDate& atdate)
|
||||
|
||||
int TBaseisamfile::write(TDate& atdate)
|
||||
{
|
||||
// CHECK(!curr().empty(), "Can't write an empty record");
|
||||
return TBaseisamfile::write(curr(),atdate);
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::_rewrite(const TRectype& rec, TDate& atdate)
|
||||
{
|
||||
CHECK(!rec.empty(), "Can't write an empty record");
|
||||
|
||||
@ -1108,27 +1088,22 @@ int TBaseisamfile::rewrite(const TRectype& rec, TDate& atdate)
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::rewriteat(TRecnotype nrec)
|
||||
int TBaseisamfile::rewrite(const TRectype& rec, TDate& atdate)
|
||||
|
||||
{
|
||||
NOT_OPEN();
|
||||
if ((_lasterr=DB_go(_isamfile->fhnd,nrec))== NOERR)
|
||||
{
|
||||
browse_null(curr().string(),DB_reclen(_isamfile->fhnd));
|
||||
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);
|
||||
if( _lasterr == NOERR && curr().has_memo( ) )
|
||||
curr( ).write_memo( _isamfile, _recno);
|
||||
return _lasterr;
|
||||
// CHECK(!rec.empty(), "Can't write an empty record");
|
||||
return rec.rewrite(*this,atdate);
|
||||
}
|
||||
|
||||
int TBaseisamfile::rewrite(TDate& atdate)
|
||||
{
|
||||
// CHECK(!curr().empty(), "Can't rewrite an empty record");
|
||||
return TBaseisamfile::rewrite(curr(),atdate);
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::rewriteat(const TRectype& rec, TRecnotype nrec)
|
||||
|
||||
{
|
||||
NOT_OPEN();
|
||||
if ((_lasterr=DB_go(_isamfile->fhnd,nrec))== NOERR)
|
||||
@ -1146,36 +1121,14 @@ int TBaseisamfile::rewriteat(const TRectype& rec, TRecnotype nrec)
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::remove(TDate& atdate)
|
||||
int TBaseisamfile::rewriteat(TRecnotype nrec)
|
||||
|
||||
{
|
||||
CHECK(!curr().empty(), "Can't remove empty record");
|
||||
|
||||
NOT_OPEN();
|
||||
|
||||
if ((_lasterr=cisread(_isamfile, curr(), _isequal + _nolock)) == 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(_lasterr == NOERR && curr().has_memo())
|
||||
curr().memo_recno();
|
||||
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
return _lasterr;
|
||||
return TBaseisamfile::rewriteat(curr(),nrec);
|
||||
}
|
||||
|
||||
|
||||
int TBaseisamfile::remove(const TRectype& rec, TDate& atdate)
|
||||
int TBaseisamfile::_remove(const TRectype& rec, TDate& atdate)
|
||||
{
|
||||
CHECK(!rec.empty(), "Can't remove an empty record");
|
||||
|
||||
@ -1204,6 +1157,72 @@ int TBaseisamfile::remove(const TRectype& rec, TDate& atdate)
|
||||
return _lasterr;
|
||||
}
|
||||
|
||||
int TBaseisamfile::remove(const TRectype& rec, TDate& atdate)
|
||||
{
|
||||
/* old version:
|
||||
CHECK(!rec.empty(), "Can't remove an empty record");
|
||||
|
||||
NOT_OPEN();
|
||||
memcpy(DB_getrecord(_isamfile->fhnd),rec.string(),DB_reclen(_isamfile->fhnd));
|
||||
if ((_lasterr=cisread(_isamfile, (TRectype&) rec, _isequal + _nolock))==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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(_lasterr == NOERR && curr().has_memo())
|
||||
curr().memo_recno();
|
||||
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
return _lasterr;
|
||||
*/
|
||||
// new version:
|
||||
return rec.remove(*this, atdate);
|
||||
}
|
||||
|
||||
int TBaseisamfile::remove(TDate& atdate)
|
||||
{
|
||||
/* old version:
|
||||
CHECK(!curr().empty(), "Can't remove empty record");
|
||||
|
||||
NOT_OPEN();
|
||||
|
||||
if ((_lasterr=cisread(_isamfile, curr(), _isequal + _nolock)) == 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(_lasterr == NOERR && curr().has_memo())
|
||||
curr().memo_recno();
|
||||
|
||||
_recno = _isamfile->RecNo = DB_recno(_isamfile->fhnd);
|
||||
return _lasterr;
|
||||
*/
|
||||
// new version:
|
||||
return TBaseisamfile::remove(curr(),atdate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int TBaseisamfile::lock()
|
||||
{
|
||||
@ -1496,6 +1515,7 @@ int TLocalisamfile::operator --()
|
||||
}
|
||||
|
||||
|
||||
|
||||
TIsamfile::TIsamfile(int logicnum, bool linkrecinst) : TBaseisamfile(logicnum, linkrecinst) {}
|
||||
|
||||
|
||||
@ -3085,32 +3105,40 @@ TRectype& TRectype::operator =(const TBaseisamfile& f)
|
||||
return *this = f.curr();
|
||||
}
|
||||
|
||||
// Certified 100%
|
||||
int TRectype::read(TBaseisamfile& f, word op)
|
||||
{ return f.read(*this, op); }
|
||||
// Certified ??%
|
||||
int TRectype::read(TBaseisamfile& f, word op, word lockop, TDate& atdate)
|
||||
{
|
||||
return f._read(*this,op,lockop,atdate) ;
|
||||
}
|
||||
|
||||
int TRectype::readat(TBaseisamfile& f, TRecnotype nrec, word lockop)
|
||||
{
|
||||
return f._readat(*this,nrec,lockop);
|
||||
}
|
||||
|
||||
|
||||
// Certified 100%
|
||||
int TRectype::next(TBaseisamfile& f)
|
||||
int TRectype::next(TBaseisamfile& f,word lockop)
|
||||
{
|
||||
const int err = f.next();
|
||||
const int err = f._next(lockop);
|
||||
*this = f.curr();
|
||||
return err;
|
||||
}
|
||||
|
||||
// Certified 100%
|
||||
int TRectype::write(TBaseisamfile& f) const
|
||||
{ return f.write(*this); }
|
||||
// Certified ??%
|
||||
int TRectype::write(TBaseisamfile& f, TDate& atdate ) const
|
||||
{ return f._write(*this,atdate); }
|
||||
|
||||
// Certified 100%
|
||||
int TRectype::rewrite(TBaseisamfile& f) const
|
||||
// Certified ??%
|
||||
int TRectype::rewrite(TBaseisamfile& f, TDate& atdate) const
|
||||
{
|
||||
return f.rewrite(*this);
|
||||
return f._rewrite(*this,atdate);
|
||||
}
|
||||
|
||||
// Certified 100%
|
||||
int TRectype::remove(TBaseisamfile& f) const
|
||||
// Certified ??%
|
||||
int TRectype::remove(TBaseisamfile& f, TDate& atdate) const
|
||||
{
|
||||
return f.remove(*this);
|
||||
return f._remove(*this,atdate);
|
||||
}
|
||||
|
||||
void TRectype::renum_key(const char* field, const char* val)
|
||||
|
@ -117,15 +117,17 @@ public:
|
||||
virtual TObject* dup() const;
|
||||
|
||||
// @cmember Legge il file <p f> con il tipo di record
|
||||
virtual int read(TBaseisamfile& f, word op = _isequal);
|
||||
virtual int read(TBaseisamfile& f, word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime);
|
||||
// @cmember Legge il file <p f> con il tipo di record alla posizione desiderata
|
||||
virtual int readat(TBaseisamfile& f, TRecnotype nrec, word lockop = _nolock);
|
||||
// @cmember Legge il prossimo record
|
||||
virtual int next(TBaseisamfile& f);
|
||||
virtual int next(TBaseisamfile& f, word lockop = _nolock);
|
||||
// @cmember Aggiunge il record al file
|
||||
virtual int write(TBaseisamfile& f) const;
|
||||
virtual int write(TBaseisamfile& f,TDate& atdate = (TDate&)botime) const;
|
||||
// @cmember Riscrive il record sul file
|
||||
virtual int rewrite(TBaseisamfile& f) const;
|
||||
virtual int rewrite(TBaseisamfile& f,TDate& atdate = (TDate&)botime) const;
|
||||
// @cmember Elimina il record dal file
|
||||
virtual int remove(TBaseisamfile& f) const;
|
||||
virtual int remove(TBaseisamfile& f,TDate& atdate = (TDate&)botime) const;
|
||||
// @cmember Cambia il campo <p field> della chiave principale con il valore <p val>
|
||||
virtual void renum_key(const char* field, const char* val);
|
||||
|
||||
@ -324,7 +326,14 @@ class TBaseisamfile : public TObject
|
||||
int rewhr(const TRectype& rec, TDate& atdate);
|
||||
// @cmember:(INTERNAL) Ritorna NOERR
|
||||
int delhr(const TRectype& rec, TDate& atdate);
|
||||
|
||||
|
||||
// @cmember:(INTERNAL) IO su file:
|
||||
int _next(word lockop = _nolock);
|
||||
int _read(TRectype& rec, word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime);
|
||||
int _readat(TRectype& rec, TRecnotype nrec, word lockop = _nolock);
|
||||
int _write(const TRectype& rec, TDate& atdate = (TDate&)botime);
|
||||
int _rewrite(const TRectype& rec, TDate& atdate = (TDate&)botime);
|
||||
int _remove(const TRectype& rec, TDate& atdate = (TDate&)botime);
|
||||
// @access Protected Member
|
||||
protected:
|
||||
// @cmember Ritorna il descrittore del file isam
|
||||
@ -400,8 +409,8 @@ public:
|
||||
// @cmember Ritorna il numero logico del file sotto forma di stringa
|
||||
virtual const char* name() const;
|
||||
|
||||
// @cmember Ritorna il record corrente
|
||||
TRecnotype recno() const
|
||||
// @cmember Ritorna il numero del record corrente
|
||||
virtual TRecnotype recno() const
|
||||
{ return _recno;}
|
||||
// @cmember Attiva lock di tutto il file
|
||||
int lock();
|
||||
@ -416,6 +425,9 @@ public:
|
||||
{ return _lasterr; }
|
||||
// @cmember Controlla se il file e' valido (ritorna 0 se il file e' valido)
|
||||
int is_valid();
|
||||
// @cmember Restituisce se il file è ordinato con indice esterno (default:FALSE)
|
||||
virtual bool is_sorted()
|
||||
{return FALSE;}
|
||||
// @cmember Ritorna il puntatore al record corrente
|
||||
virtual TRectype& curr() const
|
||||
{return *_current;}
|
||||
@ -434,14 +446,14 @@ public:
|
||||
bool bad() const
|
||||
{ return status() != NOERR;}
|
||||
// @cmember Controlla se il file e' vuoto (TRUE se vuoto)
|
||||
bool empty();
|
||||
virtual bool empty();
|
||||
// @cmember Ritorna il numero logico del record corrente
|
||||
int num() const
|
||||
{ return _logicnum;}
|
||||
// @cmember Ritorna la descrizione del file corrente
|
||||
const char* description() const;
|
||||
// @cmember Ritorna il numero di record contenuti nel file corrente
|
||||
TRecnotype eod() const ;
|
||||
virtual TRecnotype eod() const ;
|
||||
|
||||
// @cmember Ritorna l'handle del file isam nella tabella
|
||||
isdef* filehnd() const
|
||||
|
Loading…
x
Reference in New Issue
Block a user