diff --git a/include/relation.cpp b/include/relation.cpp index 07dfe7ccf..310534400 100755 --- a/include/relation.cpp +++ b/include/relation.cpp @@ -1,4 +1,4 @@ -// $Id: relation.cpp,v 1.60 1995-08-28 07:51:24 guy Exp $ +// $Id: relation.cpp,v 1.61 1995-08-29 10:18:10 marcello Exp $ // relation.cpp // fv 12/8/93 // relation class for isam files @@ -1290,7 +1290,7 @@ TRecnotype TSorted_cursor::buildcursor(TRecnotype rp) ap += pagecnt; pagecnt = 0; } - page[pagecnt++] = recno; + page[pagecnt++] = recno; // lasciare cosi' altrimenti la readat legge due volte lo stesso record DB_index_next(file().filehnd()->fhnd); int rt=get_error(-1); if (rt != NOERR) @@ -1357,15 +1357,18 @@ int TSorted_cursor::filtercursor(int pagecnt, TRecnotype* page) s.cut(s.len()-1); TFieldref f(s,0); TString sf=f.read(relation()); - bool is_date = file(f.file()).curr().type(s) ==_datefld; - if (is_date) // Se il campo e' di tipo data, la converte in ANSI! + TFieldtypes fld_type = file(f.file()).curr().type(s); + if (fld_type == _datefld) // Se il campo e' di tipo data, la converte in ANSI! { TDate d(sf); sf=d.string(ANSI); } if (is_up) sf.upper(); - TString fmt; - fmt.format("%%-%ds",f.len(rec)); + TString fmt; + if (fld_type == _alfafld || fld_type == _datefld) + fmt.format("%%-%ds",f.len(rec)); + else + fmt.format("%%%ds",f.len(rec)); strcat(Element.f,(const char*)sf.format((const char *)fmt,(const char *)sf)); } Element.p=page[i]; @@ -1604,7 +1607,7 @@ TRecord_array::TRecord_array(int logicnum, const char* numfield, int first) TRecord_array::TRecord_array(const TRecord_array& a) : TArray(a), _file(a._file), _offset(a._offset), _num(a._num) -{} +{} const TRectype& TRecord_array::key() const { @@ -1660,32 +1663,10 @@ bool TRecord_array::renum_key(const char* field, long num) return renum_key(field, n); } -void TRecord_array::set_key(TRectype* r) -{ - CHECK(r->num() == _file, "Bad key record"); - add(r, 0); // Setta il nuovo campo chiave - - if (rows() > 0) - { - const int numkey = 0; // Memento! Gli indici delle chiavi partono da zero! - const RecDes* recd = r->rec_des(); // Descrizione del record della testata - const KeyDes& kd = recd->Ky[numkey]; // Elenco dei campi chaive - - // Copia tutti i campi chiave, tranne l'ultimo, in tutti i records - for (int i = recd->Ky[numkey].NkFields-1; i >= 0; i--) - { - const int nf = kd.FieldSeq[i] % MaxFields; - const RecFieldDes& rf = recd->Fd[nf]; - const TString& val = r->get(rf.Name); - renum_key(rf.Name, val); - } - } -} - int TRecord_array::rec2row(const TRectype& r) const { - CHECK(r.num() == _file, "Incompatible record"); + CHECK(r.num() == key().num(), "Incompatible record"); const int n = atoi(r.get(_num)) - _offset; // Non e' detto che sia un int! CHECKD(n >= 0 && n < 30000, "Bad line number in record ", n + _offset); return n; @@ -1723,7 +1704,7 @@ bool TRecord_array::destroy_row(int r, bool pack) void TRecord_array::destroy_rows() { - for (int i = last(); i > 0; i = pred(i)) + for (int i = last(); i > 0; i--) destroy(i); } @@ -1733,7 +1714,7 @@ int TRecord_array::read(TRectype* filter) CHECKS(filter->get(_num).empty(), "You can't specify in the filter the field ", (const char*)_num); destroy(); - set_key(filter); + add(filter, 0); // Store filter record for later use int err = NOERR; if (!filter->empty()) @@ -1742,10 +1723,7 @@ int TRecord_array::read(TRectype* filter) TRectype* rec = (TRectype*)filter->dup(); err = rec->read(f, _isgteq); for (int e = err; e == NOERR && *rec == key(); e = rec->next(f)) - { - add_row(rec); - rec = (TRectype*)filter->dup(); - } + add_row(*rec); delete rec; } return err;