diff --git a/include/relation.cpp b/include/relation.cpp index 7c2c83948..bb8691aa6 100755 --- a/include/relation.cpp +++ b/include/relation.cpp @@ -1134,15 +1134,28 @@ TRecnotype TCursor::buildcursor(TRecnotype rp) return ap; } +bool TCursor::call_filterfunction(const TRelation * r, TRecnotype recno) const +{ + bool ok = true; + if (_filterfunction) + { + // memorizzo la chiave prima di eventuali spostamenti + const char * s0 = DB_index_getkey(file().handle()); + ok = _filterfunction(_if); +// ripristino la chiave dopo eventuali spostamenti + const int handle = file().handle(); + if (recno != DB_index_recno(handle)) + DB_index_go(handle, s0, recno); + } + return ok; +} bool TCursor::filtercursor(TRecnotype recno) { file().readat(recno); - - if (update_relation()) { - // memorizzo la chiave prima di eventuali spostamenti - const TString s0(DB_index_getkey(file().handle())); + // memorizzo la chiave prima di eventuali spostamenti + const char * s0 = DB_index_getkey(file().handle()); _if->update(-filter_limit()); @@ -1152,13 +1165,10 @@ bool TCursor::filtercursor(TRecnotype recno) DB_index_go(handle, s0, recno); } - bool ok = TRUE; - - if (_filterfunction) - ok = _filterfunction(_if); - if (ok && _fexpr) + bool ok = call_filterfunction(_if, recno); + + if (ok && _fexpr) ok = __evalcondition(*_if, _fexpr, _frefs); - return ok; } @@ -1249,19 +1259,20 @@ bool TCursor::ok() const return FALSE; } - if (update_relation()) + const TRecnotype old = file().recno(); + + if (update_relation()) { - const TRecnotype old = file().recno(); _if->update(); if (DB_recno(file().handle()) != old) file().readat(old); } - if ((_filterfunction ? _filterfunction(_if) : TRUE ) && - (_fexpr ? __evalcondition(*_if, _fexpr, _frefs) : TRUE)) - return TRUE; + if (call_filterfunction(_if, old) && + (_fexpr ? __evalcondition(*_if, _fexpr, _frefs) : true)) + return true; - return FALSE; + return false; } bool TCursor::changed() @@ -1603,8 +1614,8 @@ TRecnotype TCursor::read(TIsamop op, TReclock lockop) TCursor::TCursor(TRelation* r, const char* fil, int nkey, const TRectype *from, const TRectype* to, int tilde) - : _if(r), _nkey(nkey), _fexpr(NULL), _frozen(FALSE), _filter_update(FALSE), - _filterfunction_update(FALSE), _filter_limit(0), _filterfunction(NULL) + : _if(r), _nkey(nkey), _fexpr(NULL), _frozen(false), _filter_update(false), + _filterfunction_update(false), _filter_limit(0), _filterfunction(NULL) { file().setkey(_nkey); _pos = 0; diff --git a/include/relation.h b/include/relation.h index 40b9fce65..72d6b647a 100755 --- a/include/relation.h +++ b/include/relation.h @@ -308,6 +308,9 @@ protected: int filter_limit() const { return _filter_limit; } void set_filter_limit(int l) { _filter_limit = l; } + + bool call_filterfunction(const TRelation * r, TRecnotype recno) const; + // @access Public Member public: