Corretta la renum_key

git-svn-id: svn://10.65.10.50/trunk@4921 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
augusto 1997-07-25 13:29:06 +00:00
parent 1e56247292
commit 09d80ab702

View File

@ -105,9 +105,6 @@ bool TRecord_array::renum_key(
{
CHECKS(_num != field, "You can't renumber field ", field);
const TString& curr = key().get(field);
if (curr == num)
return FALSE;
for (int i = _data.last(); i >= 0; i--)
{
@ -158,16 +155,10 @@ int TRecord_array::insert_row(TRectype* r)
int TRecord_array::add_row(TRectype* r)
{
const int nr = rec2row(*r);
_data.add(r, nr);
if (nr == 0 && rows() > 0) // Se ho cambiato il record campione
{ // e ci sono altre righe ...
for (int f = r->items()-1; f >= 0; f--)
{
const char* fn = r->fieldname(f);
const TString& v = r->get(fn);
if (v.not_empty()) renum_key(fn, v); // ... aggiorna tutte le righe in base
} // ai campi non vuoti del campione
}
if (nr==0)
set_key(r);
else
_data.add(r, nr);
return nr;
}
@ -247,16 +238,17 @@ bool TRecord_array::good(
int TRecord_array::read(TRectype* filter)
{
CHECK(filter != NULL , "You can't specify NULL as filter ");
CHECKD(filter->num() == _file, "Bad key record ", filter->num());
CHECKS(filter->get(_num).empty(), "You can't specify in the filter the field ", (const char*)_num);
_data.destroy();
set_key(filter);
int err = NOERR;
if (filter != NULL && !filter->empty())
if (!filter->empty())
{
TLocalisamfile f(_file);
set_key(filter);
TRectype* rec = (TRectype*)filter->dup();
err = rec->read(f, _isgteq);
for (int e = err; e == NOERR && good(*rec); e = rec->next(f))
@ -265,7 +257,8 @@ int TRecord_array::read(TRectype* filter)
rec = (TRectype*)(key().dup());
}
delete rec;
}
} else
err = _iskeynotfound;
return err;
}
@ -311,10 +304,13 @@ int TRecord_array::write(bool re) const
TLocalisamfile f(_file);
const int u = _data.last();
//TRectype* rec = (TRectype*)key().dup();
CHECK(u<1 || !key().empty(), "Can't write rows using an empty key");
for (int i = 1; i <= u; i++)
{
const TRectype* r = (TRectype*)_data.objptr(i);
if (r != NULL)
{
if (re)