Patch level : 12.0 no-patch

Files correlati     :
Commento            :

Aggiunta DATACOMPCR
Aggiunta funzione find per trovare un record in un record array usando la chiave nkey.
This commit is contained in:
Alessandro Bonazzi 2020-06-21 22:10:33 +02:00
parent 7b398f878d
commit 4d7d204fee
4 changed files with 46 additions and 25 deletions

View File

@ -1644,6 +1644,7 @@ void TMask::set(
// @syntax set(short fld_id, long n, bool hit);
{
TMask_field& f = field(fld_id);
f.set(s);
if ((f.active() || f.ghost()))
{

View File

@ -36,6 +36,7 @@
#define MOV_CORRLIRE "CORRLIRE"
#define MOV_CORRVALUTA "CORRVALUTA"
#define MOV_DATACOMP "DATACOMP"
#define MOV_DATACOMPCR "DATACOMPCR"
#define MOV_DATACOMPI "DATACOMPI"
#define MOV_CODVALI "CODVALI"
#define MOV_CAMBIOI "CAMBIOI"

View File

@ -205,6 +205,21 @@ void TRecord_array::sort(COMPARE_FUNCTION sort_func)
}
}
int TRecord_array::find(const TRectype & rec, int nkey) const
{
const int last = last_row();
const TString80 key2find = rec.key(nkey);
TString80 key;
for (int nrow = first_row(); nrow <= last; nrow = succ_row(nrow))
{
key = row(nrow).key(nkey);
if (key2find == key)
return nrow;
}
return -1;
}
int TRecord_array::rec2row(const TRectype& r) const
{
CHECK(r.num() == _file, "Incompatible record");
@ -447,34 +462,36 @@ int TRecord_array::write(bool re) const
const int u = _data.last();
CHECK(u<1 || !key().empty(), "Can't write rows using an empty key");
CHECK(u < 1 || !key().empty(), "Can't write rows using an empty key");
int i;
for (i = 1; i <= u; i++)
{
const TRectype* r = (TRectype*)_data.objptr(i);
TRectype* r = (TRectype*)_data.objptr(i);
if (r != NULL)
{
if (re)
{
err = r->rewrite(f);
if (err == _iskeynotfound || err == _iseof || err == _isemptyfile)
err = r->write(f);
if (err != NOERR)
break;
}
else
{
err = r->write(f);
if (err == _isreinsert)
{
err = r->rewrite(f);
re = true;
}
if (err != NOERR)
break;
}
}
if (r != NULL)
{
if (re)
{
if (db_log() && _file != LF_DBLOG)
r->set_preserve_values(false);
err = r->rewrite(f);
if (err == _iskeynotfound || err == _iseof || err == _isemptyfile)
err = r->write(f);
if (err != NOERR)
break;
}
else
{
err = r->write(f);
if (err == _isreinsert)
{
err = r->rewrite(f);
re = true;
}
if (err != NOERR)
break;
}
}
else
{
const int pos = i+_offset;
@ -507,7 +524,7 @@ int TRecord_array::write(bool re) const
last_on_file = EOR; // Sul file non ci sono piu' righe da cancellare
delete rec;
}
}
}
}
// Cancella eventuali residui successivi

View File

@ -123,6 +123,8 @@ public:
bool renum_key(const char* field, long num);
// @cmember Ordina il Record Array secondo il criterio definito in <t COMPARE_FUNCTION>
void sort(COMPARE_FUNCTION sort_func);
// @cmember Cerca un record nel Record Array secondo la chiave nkey
int find(const TRectype & rec, int nkey = 1) const ;
// @cmember Legge tutto l'array dal file
virtual int read(const TRectype& r);