diff --git a/src/include/recset.cpp b/src/include/recset.cpp index 16705e563..0ccc0d68a 100755 --- a/src/include/recset.cpp +++ b/src/include/recset.cpp @@ -1652,6 +1652,36 @@ const TString& TISAM_recordset::driver_version() const return tmp; } +TString& TISAM_recordset::add_between_filter(const TString& field, const TString& from_val, const TString& to_val, + TString from_fld, TString to_fld) +{ + // Se from_fld e to_fld sono vuoti vengono valorizzati con il nome del campo preceduti da #DA e #A + if (from_fld.empty() || to_fld.empty()) + { + const TString qf = field.find('.') < 0 ? field : field.sub(field.find('.') + 1); + if (from_fld.empty()) + from_fld << "#DA" << qf; + if (to_fld.empty()) + to_fld << "#A" << qf; + } + + TString& ret = get_tmp_string(); + if (from_val.full() && to_val.full()) + { + ret << "&&(BETWEEN(" << field << ", " << from_fld << ", " << to_fld << "))"; + } + else if (from_val.full()) + { + ret << "&&(" << field << ">=" << from_fld << ")"; + } + else if (to_val.full()) + { + ret << "&&(" << field << "<=" << to_fld << ")"; + } + + return ret; +} + TISAM_recordset::TISAM_recordset(const char* use) : _relation(NULL), _cursor(NULL) { diff --git a/src/include/recset.h b/src/include/recset.h index a8473e968..05ea83e69 100755 --- a/src/include/recset.h +++ b/src/include/recset.h @@ -167,6 +167,13 @@ public: virtual const TString& driver_version() const; virtual const TString& query_text() const { return _use; } + // Utility + /* Ritorna un filtro che puņ essere: + * from_val && to_val: field between + * solo from_from: field >= from_val + * solo to_from: field <= to_val */ + static TString& add_between_filter(const TString& field, const TString& from_val, const TString& to_val, TString from_fld = "", TString to_fld = ""); + TISAM_recordset(const char* use); virtual ~TISAM_recordset(); }; @@ -181,5 +188,4 @@ const TString& logic2table(int logic_num); int table2logic(const TString& name); TRecordset* create_recordset(const TString& sql); - #endif