Tolte righe "inutili" dal costruttore dei cursori

git-svn-id: svn://10.65.10.50/trunk@1250 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1995-04-14 12:14:56 +00:00
parent 1f56500d97
commit 4a281a170f

View File

@ -1,4 +1,4 @@
// $Id: relation.cpp,v 1.34 1995-04-10 15:27:51 guy Exp $
// $Id: relation.cpp,v 1.35 1995-04-14 12:14:56 guy Exp $
// relation.cpp
// fv 12/8/93
// relation class for isam files
@ -913,18 +913,15 @@ TRecnotype TCursor::update()
}
void TCursor::filter(const char* filter, const TRectype *from,
void TCursor::filter(const char* fil, const TRectype *from,
const TRectype* to)
{
CHECK(!_frozen, "Impossibile filtrare un cursore congelato");
TString kf(_keyfrom), kto(_keyto), kfilter;
TString kf(_keyfrom), kto(_keyto), filter(fil);
if (filter)
kfilter << filter;
bool filterchanged = (filter != NULL) && (_filter != kfilter);
const bool filterchanged = _filter != filter;
if (file().tab())
{
@ -943,6 +940,7 @@ void TCursor::filter(const char* filter, const TRectype *from,
int p;
while ((p = kto.find('~')) != -1) kto[p] = ' ';
}
if (filterchanged || (_keyfrom != kf) || (_keyto != kto))
{
_pos = 0;
@ -950,7 +948,7 @@ void TCursor::filter(const char* filter, const TRectype *from,
_lastrec = 0;
if (filterchanged)
{
_filter = kfilter;
_filter = filter;
if (_fexpr) delete _fexpr;
TTypeexp type = (_filter.find('"') != -1) ? _strexpr : _numexpr;
if (_filter.not_empty())
@ -966,7 +964,6 @@ void TCursor::filter(const char* filter, const TRectype *from,
}
else _fexpr = NULL;
}
file().setkey(_nkey);
_keyfrom = kf;
_keyto = kto;
}
@ -988,7 +985,7 @@ void TCursor::setkey(int nkey)
TRecnotype TCursor::read(TIsamop op, TReclock lockop, TDate& atdate)
{
TRecnotype *page;
int pagecnt;
int pagecnt;
file().setkey(_nkey);
const bool approx = (op == _isgteq);
@ -1038,50 +1035,16 @@ TRecnotype TCursor::read(TIsamop op, TReclock lockop, TDate& atdate)
}
TCursor::TCursor(TRelation* r, const char* filter, int nkey, TRectype *from, TRectype* to)
: _frozen(FALSE), _filterfunction(NULL)
TCursor::TCursor(TRelation* r, const char* fil, int nkey,
const TRectype *from, const TRectype* to)
: _if(r), _nkey(nkey), _frozen(FALSE), _filterfunction(NULL), _fexpr(NULL)
{
_if = r;
_nkey = nkey;
CHECKD(_nkey > 0 && _nkey <= file().filehnd()->r->NKeys, "Bad key number : ", _nkey);
file().setkey(_nkey);
_pos = 0;
_totrec = 0;
_lastrec = 0;
_lastkrec = 0;
_filter << filter;
TTypeexp type = (_filter.find('"') != -1) ? _strexpr : _numexpr;
if (_filter.not_empty())
{
_fexpr = new TExpression(_filter, type);
if (_fexpr->type() == _numexpr)
for (int i = 0 ; i < _fexpr->numvar(); i++)
if (file().curr().type(_fexpr->varname(i)) == _alfafld)
{
_fexpr->set_type(_strexpr);
break;
}
}
else _fexpr = NULL;
file().setkey(_nkey);
if (file().tab())
{
TTable& f = (TTable&)file();
_keyfrom = _keyto = f.name();
}
if (from != NULL)
{
_keyfrom = from->key(_nkey);
int p;
while ((p = _keyfrom.find('~')) != -1) _keyfrom[p] = ' ';
}
if (to != NULL)
{
_keyto = to->key(_nkey);
int p;
while ((p = _keyto.find('~')) != -1) _keyto[p] = ' ';
}
filter(fil, from, to);
}
@ -1090,7 +1053,8 @@ TCursor::~TCursor()
{
if (_indexname.not_empty())
::remove(_indexname);
if (_fexpr) delete _fexpr;
if (_fexpr)
delete _fexpr;
}
@ -1352,8 +1316,43 @@ TRecord_array::TRecord_array(const TRectype& r, const char* numfield)
TRecord_array::TRecord_array(int logicnum, const char* numfield)
: _file(logicnum), _num(numfield)
{}
TRectype& TRecord_array::row(int n, bool create)
{
}
TRectype* r = (TRectype*)objptr(n);
if (r == NULL && create)
{
r = new TRectype(key());
n = add(r, n); // Riassegna n se era negativo!
r->put(_num, n); // Aggiorna campo numero riga
}
CHECKD(r && n > 0, "Bad record number ", n);
return *r;
}
bool TRecord_array::renum_key(const char* field, const TString& num)
{
const TString& curr = key().get(field);
CHECKS(!curr.blank() && !num.blank(), "Bad key field for record: ", field);
if (curr == num)
return FALSE;
for (int i = last(); i >= 0; i--)
{
TRectype* o = (TRectype*)objptr(i);
if (o) o->put(field, num);
}
return TRUE;
}
bool TRecord_array::renum_key(const char* field, long num)
{
TString16 n; n << num;
return renum_key(field, n);
}
int TRecord_array::rec2row(const TRectype& r) const
@ -1373,36 +1372,42 @@ int TRecord_array::add_row(const TRectype& r)
return nr;
}
bool TRecord_array::destroy_row(int r)
bool TRecord_array::destroy_row(int r, bool pack)
{
CHECKD(r > 0, "Can't destroy row ", r);
return destroy(r);
const bool ok = destroy(r, pack);
if (ok && pack)
{
for (int i = r; i < items(); i++)
row(i, FALSE).put(_num, i);
}
return ok;
}
void TRecord_array::destroy_rows()
{
const int u = last();
for (int i = 1; i <= u; i++)
for (int i = last(); i > 0; i--)
destroy_row(i);
}
bool TRecord_array::read(const TRectype& filter)
int TRecord_array::read(const TRectype& filter)
{
CHECKD(filter.num() == _file, "Bad key record ", filter.num());
CHECKS(filter.get(_num).empty(), "You can't specify in the filter the value ", (const char*)_num);
CHECKS(filter.get(_num).empty(), "You can't specify in the filter the field ", (const char*)_num);
destroy();
add(filter, 0); // Store filter record for later use
TLocalisamfile f(_file);
f.curr() = filter;
for (int err = f.read(_isgteq); err == NOERR && f.curr() == filter; err = f.next())
int err = f.read(_isgteq);
for (int e = err; e == NOERR && f.curr() == filter; e = f.next())
add_row(f.curr());
return ok();
return err;
}
bool TRecord_array::write(bool re)
int TRecord_array::write(bool re)
{
int err = NOERR;
@ -1416,10 +1421,10 @@ bool TRecord_array::write(bool re)
if (r != NULL)
{
err = re ? f.rewrite(*r) : f.write(*r);
if (err != NOERR);
err = re ? f.write(*r) : f.rewrite(*r);
if (err != NOERR)
err = re ? f.write(*r) : f.rewrite(*r);
if (err != NOERR)
return error_box("Errore di scrittura della riga %d", i);
break;
}
else
{
@ -1429,39 +1434,30 @@ bool TRecord_array::write(bool re)
{
err = f.remove();
if (err != NOERR)
return error_box("Errore di cancellazione della riga %d", i);
break;
}
}
}
// Cancella eventuali residui successivi
f.curr() = key(); f.put(_num, i);
for (err = f.read(_isgteq); err == NOERR && f.curr() == key(); err = f.next())
if (err == NOERR)
{
err = f.remove();
if (err != NOERR)
// Cancella eventuali residui successivi
f.curr() = key(); f.put(_num, i);
for (int e = f.read(_isgteq); e == NOERR && f.curr() == key(); e = f.next())
{
i = atoi(f.get(_num));
return error_box("Errore di cancellazione della riga %d", i);
}
}
err = f.remove();
if (err != NOERR)
break;
}
}
return TRUE;
return err;
}
bool TRecord_array::remove()
int TRecord_array::remove()
{
destroy_rows();
TLocalisamfile f(_file);
f.curr() = key();
for (int err = f.read(_isgteq); err == NOERR && f.curr() == key(); err = f.next())
{
err = f.remove();
return error_box("Errore di cancellazione delle righe");
}
return TRUE;
return rewrite();
}
// *** EOF relation.cpp