From 30e1e221904b0251397c79dc118791e5c043e173 Mon Sep 17 00:00:00 2001 From: Alessandro Bonazzi Date: Sat, 22 May 2021 21:50:20 +0200 Subject: [PATCH] Patch level : 12.0 nopatch Files correlati : Commento : sistemata add_between_filter. Aggiunte add_between_num_filter add_between_date_filter --- src/include/recset.cpp | 86 ++++++++++++++++++++++++++++++------------ src/include/recset.h | 9 ++--- 2 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/include/recset.cpp b/src/include/recset.cpp index 86debac6f..c45672389 100755 --- a/src/include/recset.cpp +++ b/src/include/recset.cpp @@ -1713,34 +1713,70 @@ 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) +TString& TISAM_recordset::add_between_filter(TString & clause, const TString& field, const char* from_val, const char * to_val) { - // 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 << ")"; - } + TString& ret = get_tmp_string(); - return ret; + if (from_val && *from_val && to_val && *to_val) + ret << "(BETWEEN(" << field << ", \"" << from_val << "\", \"" << to_val << "\"))"; + else + if (from_val && *from_val) + ret << "(" << field << ">=\"" << from_val << "\")"; + else + if (to_val && *to_val) + ret << "(\"" << field << "<=" << to_val << "\")"; + if (ret.full()) + { + if (clause.full()) + clause << "&&"; + clause << ret; + } + return ret; +} + +TString& TISAM_recordset::add_between_num_filter(TString & clause, const TString& field, const char* from_val, const char * to_val) +{ + + TString& ret = get_tmp_string(); + + if (from_val && *from_val && to_val && *to_val) + ret << "(BETWEEN(" << field << ", " << from_val << ", " << to_val << "))"; + else + if (from_val && *from_val) + ret << "(" << field << ">=" << from_val << ")"; + else + if (to_val && *to_val) + ret << "(" << field << "<=" << to_val << ")"; + if (ret.full()) + { + if (clause.full()) + clause << "&&"; + clause << ret; + } + return ret; +} + +TString& TISAM_recordset::add_between_date_filter(TString & clause, const TString& field, const TDate & from_val, const TDate & to_val) +{ + + TString& ret = get_tmp_string(); + + if (from_val && *from_val && to_val && *to_val) + ret << "(BETWEEN(" << field << ", " << from_val.date2ansi() << ", " << to_val.date2ansi() << "))"; + else + if (from_val && *from_val) + ret << "(ANSI(" << field << ")>=" << from_val.date2ansi() << ")"; + else + if (to_val && *to_val) + ret << "(ANSI(" << field << ")<=" << to_val.date2ansi() << ")"; + if (ret.full()) + { + if (clause.full()) + clause << "&&"; + clause << ret; + } + return ret; } TISAM_recordset::TISAM_recordset(const char* use) diff --git a/src/include/recset.h b/src/include/recset.h index b8b8e5c39..a084913e2 100755 --- a/src/include/recset.h +++ b/src/include/recset.h @@ -187,12 +187,9 @@ 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 = ""); + static TString& add_between_filter(TString & clause, const TString& field, const char * from_val, const char * to_val); + static TString& add_between_num_filter(TString & clause, const TString& field, const char * from_val, const char * to_val); + static TString& add_between_date_filter(TString & clause, const TString& field, const TDate & from_val, const TDate & to_val); TISAM_recordset(const char* use); TISAM_recordset(TCursor & c);