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:
parent
1f56500d97
commit
4a281a170f
@ -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
|
// relation.cpp
|
||||||
// fv 12/8/93
|
// fv 12/8/93
|
||||||
// relation class for isam files
|
// 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)
|
const TRectype* to)
|
||||||
|
|
||||||
{
|
{
|
||||||
CHECK(!_frozen, "Impossibile filtrare un cursore congelato");
|
CHECK(!_frozen, "Impossibile filtrare un cursore congelato");
|
||||||
|
|
||||||
TString kf(_keyfrom), kto(_keyto), kfilter;
|
TString kf(_keyfrom), kto(_keyto), filter(fil);
|
||||||
|
|
||||||
if (filter)
|
const bool filterchanged = _filter != filter;
|
||||||
kfilter << filter;
|
|
||||||
|
|
||||||
bool filterchanged = (filter != NULL) && (_filter != kfilter);
|
|
||||||
|
|
||||||
if (file().tab())
|
if (file().tab())
|
||||||
{
|
{
|
||||||
@ -943,6 +940,7 @@ void TCursor::filter(const char* filter, const TRectype *from,
|
|||||||
int p;
|
int p;
|
||||||
while ((p = kto.find('~')) != -1) kto[p] = ' ';
|
while ((p = kto.find('~')) != -1) kto[p] = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filterchanged || (_keyfrom != kf) || (_keyto != kto))
|
if (filterchanged || (_keyfrom != kf) || (_keyto != kto))
|
||||||
{
|
{
|
||||||
_pos = 0;
|
_pos = 0;
|
||||||
@ -950,7 +948,7 @@ void TCursor::filter(const char* filter, const TRectype *from,
|
|||||||
_lastrec = 0;
|
_lastrec = 0;
|
||||||
if (filterchanged)
|
if (filterchanged)
|
||||||
{
|
{
|
||||||
_filter = kfilter;
|
_filter = filter;
|
||||||
if (_fexpr) delete _fexpr;
|
if (_fexpr) delete _fexpr;
|
||||||
TTypeexp type = (_filter.find('"') != -1) ? _strexpr : _numexpr;
|
TTypeexp type = (_filter.find('"') != -1) ? _strexpr : _numexpr;
|
||||||
if (_filter.not_empty())
|
if (_filter.not_empty())
|
||||||
@ -966,7 +964,6 @@ void TCursor::filter(const char* filter, const TRectype *from,
|
|||||||
}
|
}
|
||||||
else _fexpr = NULL;
|
else _fexpr = NULL;
|
||||||
}
|
}
|
||||||
file().setkey(_nkey);
|
|
||||||
_keyfrom = kf;
|
_keyfrom = kf;
|
||||||
_keyto = kto;
|
_keyto = kto;
|
||||||
}
|
}
|
||||||
@ -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)
|
TCursor::TCursor(TRelation* r, const char* fil, int nkey,
|
||||||
: _frozen(FALSE), _filterfunction(NULL)
|
const TRectype *from, const TRectype* to)
|
||||||
|
: _if(r), _nkey(nkey), _frozen(FALSE), _filterfunction(NULL), _fexpr(NULL)
|
||||||
{
|
{
|
||||||
_if = r;
|
file().setkey(_nkey);
|
||||||
_nkey = nkey;
|
|
||||||
CHECKD(_nkey > 0 && _nkey <= file().filehnd()->r->NKeys, "Bad key number : ", _nkey);
|
|
||||||
|
|
||||||
_pos = 0;
|
_pos = 0;
|
||||||
_totrec = 0;
|
_totrec = 0;
|
||||||
_lastrec = 0;
|
_lastrec = 0;
|
||||||
_lastkrec = 0;
|
_lastkrec = 0;
|
||||||
_filter << filter;
|
filter(fil, from, to);
|
||||||
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] = ' ';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1090,7 +1053,8 @@ TCursor::~TCursor()
|
|||||||
{
|
{
|
||||||
if (_indexname.not_empty())
|
if (_indexname.not_empty())
|
||||||
::remove(_indexname);
|
::remove(_indexname);
|
||||||
if (_fexpr) delete _fexpr;
|
if (_fexpr)
|
||||||
|
delete _fexpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1352,7 +1316,42 @@ TRecord_array::TRecord_array(const TRectype& r, const char* numfield)
|
|||||||
|
|
||||||
TRecord_array::TRecord_array(int logicnum, const char* numfield)
|
TRecord_array::TRecord_array(int logicnum, const char* numfield)
|
||||||
: _file(logicnum), _num(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1373,36 +1372,42 @@ int TRecord_array::add_row(const TRectype& r)
|
|||||||
return nr;
|
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);
|
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()
|
void TRecord_array::destroy_rows()
|
||||||
{
|
{
|
||||||
const int u = last();
|
for (int i = last(); i > 0; i--)
|
||||||
for (int i = 1; i <= u; i++)
|
|
||||||
destroy_row(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());
|
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();
|
destroy();
|
||||||
add(filter, 0); // Store filter record for later use
|
add(filter, 0); // Store filter record for later use
|
||||||
|
|
||||||
TLocalisamfile f(_file);
|
TLocalisamfile f(_file);
|
||||||
f.curr() = filter;
|
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());
|
add_row(f.curr());
|
||||||
|
|
||||||
return ok();
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TRecord_array::write(bool re)
|
int TRecord_array::write(bool re)
|
||||||
{
|
{
|
||||||
int err = NOERR;
|
int err = NOERR;
|
||||||
|
|
||||||
@ -1416,10 +1421,10 @@ bool TRecord_array::write(bool re)
|
|||||||
if (r != NULL)
|
if (r != NULL)
|
||||||
{
|
{
|
||||||
err = re ? f.rewrite(*r) : f.write(*r);
|
err = re ? f.rewrite(*r) : f.write(*r);
|
||||||
if (err != NOERR);
|
if (err != NOERR)
|
||||||
err = re ? f.write(*r) : f.rewrite(*r);
|
err = re ? f.write(*r) : f.rewrite(*r);
|
||||||
if (err != NOERR)
|
if (err != NOERR)
|
||||||
return error_box("Errore di scrittura della riga %d", i);
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1429,39 +1434,30 @@ bool TRecord_array::write(bool re)
|
|||||||
{
|
{
|
||||||
err = f.remove();
|
err = f.remove();
|
||||||
if (err != NOERR)
|
if (err != NOERR)
|
||||||
return error_box("Errore di cancellazione della riga %d", i);
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (err == NOERR)
|
||||||
|
{
|
||||||
// Cancella eventuali residui successivi
|
// Cancella eventuali residui successivi
|
||||||
f.curr() = key(); f.put(_num, i);
|
f.curr() = key(); f.put(_num, i);
|
||||||
for (err = f.read(_isgteq); err == NOERR && f.curr() == key(); err = f.next())
|
for (int e = f.read(_isgteq); e == NOERR && f.curr() == key(); e = f.next())
|
||||||
{
|
{
|
||||||
err = f.remove();
|
err = f.remove();
|
||||||
if (err != NOERR)
|
if (err != NOERR)
|
||||||
{
|
break;
|
||||||
i = atoi(f.get(_num));
|
|
||||||
return error_box("Errore di cancellazione della riga %d", i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TRecord_array::remove()
|
int TRecord_array::remove()
|
||||||
{
|
{
|
||||||
destroy_rows();
|
destroy_rows();
|
||||||
|
return rewrite();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// *** EOF relation.cpp
|
// *** EOF relation.cpp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user