diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-07-17 14:16:53 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-07-17 14:16:53 +0200 |
commit | cb36059b338552027a511fcf16a62257304e2a02 (patch) | |
tree | 3440d89be23d64705d8e7c50875678a4a484fd25 | |
parent | 0d1e7d241cc459ace099db554fee413abcbf7700 (diff) |
Handle empty query::in_range() case
-rw-r--r-- | odb/pgsql/query-dynamic.cxx | 24 | ||||
-rw-r--r-- | odb/pgsql/query.txx | 25 |
2 files changed, 30 insertions, 19 deletions
diff --git a/odb/pgsql/query-dynamic.cxx b/odb/pgsql/query-dynamic.cxx index 37a78a9..92034e2 100644 --- a/odb/pgsql/query-dynamic.cxx +++ b/odb/pgsql/query-dynamic.cxx @@ -94,20 +94,26 @@ namespace odb } case part::op_in: { - size_t b (p - x.data); + if (x.data != 0) + { + size_t b (p - x.data); - translate (q, s, b - 1); // column - q += "IN ("; + translate (q, s, b - 1); // column + q += "IN ("; - for (size_t i (b); i != p; ++i) - { - if (i != b) - q += ","; + for (size_t i (b); i != p; ++i) + { + if (i != b) + q += ","; - translate (q, s, i); + translate (q, s, i); + } + + q += ")"; } + else + q.append (false); - q += ")"; break; } case part::op_like: diff --git a/odb/pgsql/query.txx b/odb/pgsql/query.txx index c1dc0d9..3606ae0 100644 --- a/odb/pgsql/query.txx +++ b/odb/pgsql/query.txx @@ -100,19 +100,24 @@ namespace odb query_base query_column<T, ID>:: in_range (I begin, I end) const { - query_base q (table_, column_); - q += "IN ("; - - for (I i (begin); i != end; ++i) + if (begin != end) { - if (i != begin) - q += ","; + query_base q (table_, column_); + q += "IN ("; - q.append<T, ID> (val_bind<T> (*i), conversion_); - } + for (I i (begin); i != end; ++i) + { + if (i != begin) + q += ","; - q += ")"; - return q; + q.append<T, ID> (val_bind<T> (*i), conversion_); + } + + q += ")"; + return q; + } + else + return query_base (false); } // like |