Patch level :

Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
msksheet.cpp         Tolto spazio inutile
os_win32.cpp         Corretto calcolo spazio libero su disco
prefix.*             Aggiunto clock_t di ultima modifica al file
recarray.*           Aggiunta discard
relation.*           Corretti alcuni metodi TSorted_file


git-svn-id: svn://10.65.10.50/trunk@7201 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1998-10-01 14:04:23 +00:00
parent 1efdf8ef16
commit 5657e8ae59
8 changed files with 123 additions and 48 deletions

View File

@ -2648,7 +2648,7 @@ void TSheet_field::mask2row(int n, TToken_string & rec)
// Ricopia i campi del record dato nella maschera // Ricopia i campi del record dato nella maschera
void TSheet_field::row2mask(int n, TToken_string & r, int mode) void TSheet_field::row2mask(int n, TToken_string& r, int mode)
{ {
TString val(80); TString val(80);

View File

@ -183,11 +183,19 @@ bool os_test_disk_free_space(const char* path, unsigned long filesize)
// On Win95 may fail for disks > 2GB // On Win95 may fail for disks > 2GB
DWORD nSecPerClust, nBytePerSec, nFreeClust; DWORD nSecPerClust, nBytePerSec, nFreeClust;
GetDiskFreeSpace(path, &nSecPerClust, &nBytePerSec, &nFreeClust, NULL); bool ok = GetDiskFreeSpace(path, &nSecPerClust, &nBytePerSec, &nFreeClust, NULL) != 0;
__int64 nFree = nFreeClust;
nFree *= nSecPerClust; if (ok && nBytePerSec >= 512)
nFree *= nBytePerSec; {
return nFree > filesize; __int64 nFree = nFreeClust;
nFree *= nSecPerClust;
nFree *= nBytePerSec;
ok = nFree > filesize;
}
else
ok = TRUE;
return ok;
} }
unsigned long os_get_disk_size(const char* path) unsigned long os_get_disk_size(const char* path)

View File

@ -235,7 +235,7 @@ class TFile_info : public TObject
int _num; int _num;
int _handle; int _handle;
clock_t _last_access; clock_t _last_access, _last_change;
bool _locked, _exclusive; bool _locked, _exclusive;
TDirtype _dir; TDirtype _dir;
FileDes _filedes; FileDes _filedes;
@ -255,11 +255,13 @@ public:
int handle() const { return _handle; } int handle() const { return _handle; }
bool is_open() const { return _handle >= 0; } bool is_open() const { return _handle >= 0; }
clock_t last_access() const { return _last_access; } clock_t last_access() const { return _last_access; }
clock_t last_change() const { return _last_change; }
bool is_exclusive() const { return _exclusive; } bool is_exclusive() const { return _exclusive; }
bool is_locked() const { return _locked; } bool is_locked() const { return _locked; }
int ref_count() const { return _ref_count; } int ref_count() const { return _ref_count; }
int last_key() const { return _last_key; } int last_key() const { return _last_key; }
void touch() { _last_access = clock(); } void touch() { _last_access = clock(); }
void set_dirty() { _last_change = clock(); }
TDirtype dir_type() const { return _dir; } TDirtype dir_type() const { return _dir; }
bool mutable_dir() const { return _dir <= _studir; } bool mutable_dir() const { return _dir <= _studir; }
@ -436,7 +438,7 @@ const TFilename& TFile_info::load_filedes()
TFile_info::TFile_info(int logicnum, TFilename& name) TFile_info::TFile_info(int logicnum, TFilename& name)
: _num(logicnum), _handle(-1), _ref_count(0), : _num(logicnum), _handle(-1), _ref_count(0),
_locked(FALSE), _exclusive(FALSE), _locked(FALSE), _exclusive(FALSE),
_last_access(0), _last_key(-1) _last_access(0), _last_change(0), _last_key(-1)
{ {
if (logicnum < LF_EXTERNAL) if (logicnum < LF_EXTERNAL)
{ {
@ -477,14 +479,12 @@ TFile_info::TFile_info(int logicnum, TFilename& name)
} }
} }
TFile_info::~TFile_info() TFile_info::~TFile_info()
{ {
if (is_open()) if (is_open())
close_low(); close_low();
} }
TFile_info& TFile_manager::fileinfo(TIsam_handle num) const TFile_info& TFile_manager::fileinfo(TIsam_handle num) const
{ {
TFile_info* i = (TFile_info*)_fileinfo.objptr(num); TFile_info* i = (TFile_info*)_fileinfo.objptr(num);
@ -688,6 +688,18 @@ TDirtype TFile_manager::get_dirtype(int logicnum)
return i.dir_type(); return i.dir_type();
} }
void TFile_manager::notify_change(TIsam_handle name)
{
TFile_info& i = fileinfo(name);
i.set_dirty();
}
long TFile_manager::last_change(TIsam_handle name) const
{
TFile_info& i = fileinfo(name);
return i.last_change();
}
int TFile_manager::close_closeable() int TFile_manager::close_closeable()
{ {
_open_files = 0; _open_files = 0;
@ -1040,6 +1052,14 @@ const char* firm2dir(
return __tmp_string; return __tmp_string;
} }
int safely_close_closeable_isamfiles()
{
int f = 0;
if (_prefhndl)
f = _prefhndl->close_closeable_isamfiles();
return f;
}
bool TPrefix::build_firm_data(long codditta, bool flagcom) bool TPrefix::build_firm_data(long codditta, bool flagcom)
{ {
const char * const ndir = "/dir.gen"; const char * const ndir = "/dir.gen";
@ -1137,7 +1157,6 @@ bool TPrefix::build_firm_data(long codditta, bool flagcom)
} }
TConfig c(CONFIG_STUDIO, "cg"); TConfig c(CONFIG_STUDIO, "cg");
if (c.get_bool("StiReg")) if (c.get_bool("StiReg"))
{ {
TTable reg("REG"); TTable reg("REG");

View File

@ -49,6 +49,9 @@ public:
TCodeb_handle get_handle(TIsam_handle name, int key); TCodeb_handle get_handle(TIsam_handle name, int key);
int get_reclen(int logicnum); int get_reclen(int logicnum);
void notify_change(TIsam_handle name);
long last_change(TIsam_handle name) const;
int close_closeable(); int close_closeable();
void close_all(); void close_all();
void open_all(); void open_all();
@ -162,6 +165,12 @@ public:
const TFilename& get_filename(TIsam_handle name) const const TFilename& get_filename(TIsam_handle name) const
{ return _manager.get_filename(name); } { return _manager.get_filename(name); }
void notify_change(TIsam_handle name)
{ _manager.notify_change(name); }
long last_change(TIsam_handle name) const
{ return _manager.last_change(name); }
// @cmember Costruttore // @cmember Costruttore
TPrefix(); TPrefix();
// @cmember Distruttore // @cmember Distruttore
@ -170,6 +179,7 @@ public:
const char* firm2dir(long codditta); const char* firm2dir(long codditta);
int safely_close_closeable_isamfiles();
TPrefix& prefix_init(); TPrefix& prefix_init();
bool prefix_valid(); bool prefix_valid();

View File

@ -427,9 +427,12 @@ TFile_cache::~TFile_cache()
void TFile_cache::init_file(TLocalisamfile* f) void TFile_cache::init_file(TLocalisamfile* f)
{ {
if (_file != NULL) if (_file != NULL)
{
delete _file; delete _file;
_file = NULL;
}
if (f == NULL) if (f == NULL)
{ {
int logicnum = atoi(_filecode); int logicnum = atoi(_filecode);
@ -519,6 +522,14 @@ const TObject& TFile_cache::query(const char* code)
return *obj; return *obj;
} }
bool TFile_cache::discard(const char* victim)
{
if (victim && *victim)
return _cache.remove(victim);
destroy();
return TRUE;
}
int TFile_cache::io_result() int TFile_cache::io_result()
{ {
return _error; return _error;

View File

@ -164,6 +164,8 @@ protected:
TLocalisamfile & file(); TLocalisamfile & file();
public: public:
virtual bool discard(const char* victim);
int io_result(); int io_result();
const int key_number() const const int key_number() const
{ return _key; } { return _key; }

View File

@ -1425,7 +1425,8 @@ TRecnotype TCursor::operator +=(const TRecnotype npos)
_totrec = update(); _totrec = update();
_pos += npos; _pos += npos;
if (_pos > _totrec) _pos = _totrec; if (_pos > _totrec)
_pos = _totrec;
else else
if (_pos < 0) _pos = 0; if (_pos < 0) _pos = 0;
readrec(); readrec();
@ -2336,16 +2337,26 @@ TRelation_description::~TRelation_description()
// @mfunc Avanza di <p npos> record // @mfunc Avanza di <p npos> record
int TSortedfile::operator +=(const TRecnotype npos) int TSortedfile::operator +=(const TRecnotype npos)
{ {
*_curs+=npos; int err = NOERR;
setstatus(_curs->file().status()); TRecnotype p = _curs->pos() + npos;
return _curs->test(); if (p < 0)
{
p = 0;
err = _isbof;
}
if (p >= _curs->items())
{
err = _iseof;
p = _curs->items();
}
*_curs = p;
setstatus(err);
return err;
} }
// @mfunc Sposta indietro di <p npos> record // @mfunc Sposta indietro di <p npos> record
int TSortedfile::operator -=(const TRecnotype npos) int TSortedfile::operator -=(const TRecnotype npos)
{ {
*_curs-=npos; return operator+=(-npos);
setstatus(_curs->file().status());
return _curs->test();
} }
// @mfunc Avanza al record successivo // @mfunc Avanza al record successivo
int TSortedfile::operator ++() int TSortedfile::operator ++()
@ -2361,30 +2372,35 @@ int TSortedfile::operator --()
// @mfunc Si posiziona sul primo record del file (vedi <t TReclock>) // @mfunc Si posiziona sul primo record del file (vedi <t TReclock>)
int TSortedfile::first(word lockop ) int TSortedfile::first(word lockop )
{ {
_curs->first_item(); int err = _curs->items() > 0 ? NOERR : _iseof;
setstatus(_curs->file().status()); *_curs = 0;
return _curs->items()>0; setstatus(err);
return err;
} }
// @mfunc Si posiziona sull'ultimo record del file (vedi <t TReclock>) // @mfunc Si posiziona sull'ultimo record del file (vedi <t TReclock>)
int TSortedfile::last(word lockop ) int TSortedfile::last(word lockop )
{ {
int err = _curs->items() > 0 ? NOERR : _iseof;
_curs->last_item(); _curs->last_item();
setstatus(_curs->file().status()); setstatus(err);
return _curs->items()>0; return err;
} }
// @mfunc Si posiziona sul successivo record del file (vedi <t TReclock>) // @mfunc Si posiziona sul successivo record del file (vedi <t TReclock>)
int TSortedfile::next(word lockop ) int TSortedfile::next(word lockop )
{ {
_curs->succ_item(); _curs->succ_item();
setstatus(_curs->file().status()); int err = _curs->pos() < _curs->items() ? NOERR : _iseof;
return _curs->pos()<=_curs->items(); setstatus(err);
return err;
} }
// @mfunc Si posiziona sul precedente record del file (vedi <t TReclock>) // @mfunc Si posiziona sul precedente record del file (vedi <t TReclock>)
int TSortedfile::prev(word lockop ) int TSortedfile::prev(word lockop )
{ {
_curs->pred_item(); int err = _curs->pos() > 0 ? NOERR : _isbof;
setstatus(_curs->file().status()); if (err == NOERR)
return _curs->pos()>0; _curs->pred_item();
setstatus(err);
return err;
} }
// @mfunc Salta <p nrec> record dalla posizione corrente (vedi <t TReclock>) // @mfunc Salta <p nrec> record dalla posizione corrente (vedi <t TReclock>)
@ -2392,7 +2408,7 @@ int TSortedfile::skip(TRecnotype nrec, word lockop )
{ {
// return *this+=nrec; manca il lock... // return *this+=nrec; manca il lock...
setstatus(_curs->file().status()); setstatus(_curs->file().status());
error_box("Operazione 'skip' non consentita sul cursore"); NFCHECK("Operazione 'skip' non consentita sul cursore");
return 0; return 0;
} }
@ -2444,24 +2460,27 @@ int TSortedfile::readat(TRecnotype nrec, word lockop )
} }
// @mfunc Aggiunge un record // @mfunc Aggiunge un record
int TSortedfile::write() int TSortedfile::write()
{ {
return write(curr()); return write(curr());
} }
// @mfunc Aggiunge un record copiando da <p rec> // @mfunc Aggiunge un record copiando da <p rec>
int TSortedfile::write(const TRectype& rec) int TSortedfile::write(const TRectype& rec)
{ {
return 0; NFCHECK("Operazione 'write' non consentita sul TSortedfile");
return 0;
} }
// @mfunc Riscrive un record // @mfunc Riscrive un record
int TSortedfile::rewrite() int TSortedfile::rewrite()
{ {
return 0; rewrite(curr());
return 0;
} }
// @mfunc Riscrive un record (il record <p rec>) // @mfunc Riscrive un record (il record <p rec>)
int TSortedfile::rewrite(const TRectype& rec) int TSortedfile::rewrite(const TRectype& rec)
{ {
NFCHECK("Operazione 'rewrite' non consentita sul TSortedfile");
return 0; return 0;
} }
@ -2473,7 +2492,7 @@ int TSortedfile::rewriteat(TRecnotype nrec)
// @mfunc Riscrive un record alla posizione <p nrec> copiando da <p rec> // @mfunc Riscrive un record alla posizione <p nrec> copiando da <p rec>
int TSortedfile::rewriteat(const TRectype& rec, TRecnotype nrec) int TSortedfile::rewriteat(const TRectype& rec, TRecnotype nrec)
{ {
error_box("Operazione 'rewriteat' non consentita sul cursore"); NFCHECK("Operazione 'rewriteat' non consentita sul TSortedfile");
return 0; return 0;
} }
@ -2485,6 +2504,7 @@ int TSortedfile::remove()
// @mfunc Elimina il record copiando da <p rec> // @mfunc Elimina il record copiando da <p rec>
int TSortedfile::remove(const TRectype& rec) int TSortedfile::remove(const TRectype& rec)
{ {
NFCHECK("Operazione 'remove' non consentita sul TSortedfile");
return 0; return 0;
} }
@ -2510,9 +2530,13 @@ bool TSortedfile::empty()
return _curs->items()==0; return _curs->items()==0;
} }
TRectype& TSortedfile::curr() const
{
return _curs->curr();
}
void TSortedfile::set_curr(TRectype * curr) void TSortedfile::set_curr(TRectype * curr)
{ {
TLocalisamfile::set_curr(curr);
_curs->file().set_curr(curr); _curs->file().set_curr(curr);
} }
@ -2521,26 +2545,25 @@ TSortedfile::TSortedfile(int logicnum,TRelation * rel,const char * ordexpr,const
:TLocalisamfile(logicnum),_rel(NULL) :TLocalisamfile(logicnum),_rel(NULL)
{ {
// costruisce il cursore // costruisce il cursore
if (!rel) if (rel == NULL)
{ rel = new TRelation(logicnum);
_rel = new TRelation(logicnum);
} _rel=rel;
else
_rel=rel;
_curs = new TSorted_cursor(_rel,ordexpr,"",nkey); _curs = new TSorted_cursor(_rel,ordexpr,"",nkey);
if (&curr()!=&(_curs->file().curr())) // if (&curr()!=&(_curs->file().curr()))
_curs->file().set_curr(&curr()); // _curs->file().set_curr(&curr());
_curs->setfilter(filter,TRUE); //must pass TRUE because cursors doesn't update rel (BUG). _curs->setfilter(filter,TRUE); //must pass TRUE because cursors doesn't update rel (BUG).
// DON't move this line BEFORE set_curr : filter's fieldrefs are allocated at cursor setfilter // DON't move this line BEFORE set_curr : filter's fieldrefs are allocated at cursor setfilter
} }
// @mfunc Distruttore // @mfunc Distruttore
TSortedfile::~TSortedfile() TSortedfile::~TSortedfile()
{ {
delete _curs; delete _curs;
if (_rel) delete _rel; if (_rel)
delete _rel;
} }

View File

@ -114,7 +114,7 @@ public:
bool next_match(int logicnum, const char* fieldlist = NULL, int nkey = 0); bool next_match(int logicnum, const char* fieldlist = NULL, int nkey = 0);
// @cmember Aggiunge una nuovo file alla relazione partendo dal descrittore del file // @cmember Aggiunge una nuovo file alla relazione partendo dal descrittore del file
bool add(TLocalisamfile* f, const char* relexprs, int key, int linkto, int alias, bool allow_lock); bool add(TLocalisamfile* f, const char* relexprs, int key = 1, int linkto = 0, int alias = 0, bool allow_lock = FALSE);
// @cmember Aggiunge una nuovo file alla relazione partendo dal numero logico del file // @cmember Aggiunge una nuovo file alla relazione partendo dal numero logico del file
bool add(int logicnum, const char* relexprs, int key = 1, int linkto = 0, int alias = 0, bool allow_lock = FALSE); bool add(int logicnum, const char* relexprs, int key = 1, int linkto = 0, int alias = 0, bool allow_lock = FALSE);
// @cmember Aggiunge una nuovo file alla relazione partendo dal nome della tabella // @cmember Aggiunge una nuovo file alla relazione partendo dal nome della tabella
@ -687,6 +687,8 @@ public:
virtual bool tab() const virtual bool tab() const
{ return FALSE;} { return FALSE;}
// @cmember Ritorna il record corrente del del file
virtual TRectype& curr() const;
// @cmember Sostituisce il record corrente del del file (disallocando il vecchio) // @cmember Sostituisce il record corrente del del file (disallocando il vecchio)
virtual void set_curr(TRectype * curr); virtual void set_curr(TRectype * curr);
// @cmember Si posiziona sul primo record del file (vedi <t TReclock>) // @cmember Si posiziona sul primo record del file (vedi <t TReclock>)
@ -749,7 +751,7 @@ public:
virtual bool is_sorted() virtual bool is_sorted()
{return TRUE;} {return TRUE;}
// @cmember Costruttore. // @cmember Costruttore.
TSortedfile(int logicnum,TRelation * rel,const char * ordexpr="",const char * filter="", int nkey=1); TSortedfile(int logicnum,TRelation* rel = NULL,const char* ordexpr="",const char * filter="", int nkey=1);
// @cmember Distruttore // @cmember Distruttore
virtual ~TSortedfile(); virtual ~TSortedfile();
}; };