aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-09-09 12:18:39 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-09-09 12:18:39 +0200
commita8b1a89c291ab5bd170568eab3d7666631adf035 (patch)
tree022605b88d95ae497919a483a768e0afe25adcc9
parent1b1cb92a27592da6ab9300b2c5c8384f7588e2af (diff)
New templated query_columns architecture
We also now use the correct separate "role"-base join approach instead of having a single merged join for each table.
-rw-r--r--odb/sqlite/query.cxx25
-rw-r--r--odb/sqlite/query.hxx99
-rw-r--r--odb/sqlite/query.txx15
3 files changed, 77 insertions, 62 deletions
diff --git a/odb/sqlite/query.cxx b/odb/sqlite/query.cxx
index 4a2082b..ab158bb 100644
--- a/odb/sqlite/query.cxx
+++ b/odb/sqlite/query.cxx
@@ -156,11 +156,9 @@ namespace odb
}
void query::
- append (const string& q, clause_part::kind_type k)
+ append (const string& q)
{
- if (k == clause_part::native &&
- !clause_.empty () &&
- clause_.back ().kind == clause_part::native)
+ if (!clause_.empty () && clause_.back ().kind == clause_part::native)
{
string& s (clause_.back ().part);
@@ -177,7 +175,19 @@ namespace odb
s += q;
}
else
- clause_.push_back (clause_part (k, q));
+ clause_.push_back (clause_part (clause_part::native, q));
+ }
+
+ void query::
+ append (const char* table, const char* column)
+ {
+ string s ("\"");
+ s += table;
+ s += "\".\"";
+ s += column;
+ s += '"';
+
+ clause_.push_back (clause_part (clause_part::column, s));
}
void query::
@@ -188,7 +198,7 @@ namespace odb
}
string query::
- clause (string const& table) const
+ clause () const
{
string r;
@@ -204,9 +214,6 @@ namespace odb
if (last != ' ' && last != '(')
r += ' ';
- if (i->part[0] == '.')
- r += table;
-
r += i->part;
break;
}
diff --git a/odb/sqlite/query.hxx b/odb/sqlite/query.hxx
index f413756..9731d10 100644
--- a/odb/sqlite/query.hxx
+++ b/odb/sqlite/query.hxx
@@ -137,11 +137,16 @@ namespace odb
}
explicit
- query (const std::string& q,
- clause_part::kind_type k = clause_part::native)
+ query (const std::string& native)
: parameters_ (new (details::shared) query_params)
{
- clause_.push_back (clause_part (k, q));
+ clause_.push_back (clause_part (clause_part::native, native));
+ }
+
+ query (const char* table, const char* column)
+ : parameters_ (new (details::shared) query_params)
+ {
+ append (table, column);
}
template <typename T>
@@ -170,7 +175,7 @@ namespace odb
public:
std::string
- clause (std::string const& default_table) const;
+ clause () const;
binding&
parameters_binding () const;
@@ -200,7 +205,7 @@ namespace odb
query&
operator+= (const std::string& q)
{
- append (q, clause_part::native);
+ append (q);
return *this;
}
@@ -230,7 +235,10 @@ namespace odb
append (ref_bind<T>);
void
- append (const std::string&, clause_part::kind_type);
+ append (const std::string& native);
+
+ void
+ append (const char* table, const char* column);
private:
void
@@ -394,16 +402,23 @@ namespace odb
template <typename T, database_type_id ID>
struct query_column
{
- explicit
- query_column (const char* name)
- : name_ (name)
+ // Note that we keep shalow copies of the table and column names.
+ //
+ query_column (const char* table, const char* column)
+ : table_ (table), column_ (column)
{
}
const char*
- name () const
+ table () const
{
- return name_;
+ return table_;
+ }
+
+ const char*
+ column () const
+ {
+ return column_;
}
// is_null, is_not_null
@@ -412,7 +427,7 @@ namespace odb
query
is_null () const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "IS NULL";
return q;
}
@@ -420,7 +435,7 @@ namespace odb
query
is_not_null () const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "IS NOT NULL";
return q;
}
@@ -456,7 +471,7 @@ namespace odb
query
equal (val_bind<T> v) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "=";
q.append<T, ID> (v);
return q;
@@ -473,7 +488,7 @@ namespace odb
query
equal (ref_bind<T> r) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "=";
q.append<T, ID> (r);
return q;
@@ -541,7 +556,7 @@ namespace odb
query
unequal (val_bind<T> v) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "!=";
q.append<T, ID> (v);
return q;
@@ -558,7 +573,7 @@ namespace odb
query
unequal (ref_bind<T> r) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "!=";
q.append<T, ID> (r);
return q;
@@ -626,7 +641,7 @@ namespace odb
query
less (val_bind<T> v) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "<";
q.append<T, ID> (v);
return q;
@@ -643,7 +658,7 @@ namespace odb
query
less (ref_bind<T> r) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "<";
q.append<T, ID> (r);
return q;
@@ -711,7 +726,7 @@ namespace odb
query
greater (val_bind<T> v) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += ">";
q.append<T, ID> (v);
return q;
@@ -728,7 +743,7 @@ namespace odb
query
greater (ref_bind<T> r) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += ">";
q.append<T, ID> (r);
return q;
@@ -796,7 +811,7 @@ namespace odb
query
less_equal (val_bind<T> v) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "<=";
q.append<T, ID> (v);
return q;
@@ -813,7 +828,7 @@ namespace odb
query
less_equal (ref_bind<T> r) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "<=";
q.append<T, ID> (r);
return q;
@@ -881,7 +896,7 @@ namespace odb
query
greater_equal (val_bind<T> v) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += ">=";
q.append<T, ID> (v);
return q;
@@ -898,7 +913,7 @@ namespace odb
query
greater_equal (ref_bind<T> r) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += ">=";
q.append<T, ID> (r);
return q;
@@ -965,9 +980,9 @@ namespace odb
//
(void) (sizeof (type_instance<T> () == type_instance<T2> ()));
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "=";
- q.append (c.name (), query::clause_part::column);
+ q.append (c.table (), c.column ());
return q;
}
@@ -979,9 +994,9 @@ namespace odb
//
(void) (sizeof (type_instance<T> () != type_instance<T2> ()));
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "!=";
- q.append (c.name (), query::clause_part::column);
+ q.append (c.table (), c.column ());
return q;
}
@@ -993,9 +1008,9 @@ namespace odb
//
(void) (sizeof (type_instance<T> () < type_instance<T2> ()));
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "<";
- q.append (c.name (), query::clause_part::column);
+ q.append (c.table (), c.column ());
return q;
}
@@ -1007,9 +1022,9 @@ namespace odb
//
(void) (sizeof (type_instance<T> () > type_instance<T2> ()));
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += ">";
- q.append (c.name (), query::clause_part::column);
+ q.append (c.table (), c.column ());
return q;
}
@@ -1021,9 +1036,9 @@ namespace odb
//
(void) (sizeof (type_instance<T> () <= type_instance<T2> ()));
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "<=";
- q.append (c.name (), query::clause_part::column);
+ q.append (c.table (), c.column ());
return q;
}
@@ -1035,14 +1050,15 @@ namespace odb
//
(void) (sizeof (type_instance<T> () >= type_instance<T2> ()));
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += ">=";
- q.append (c.name (), query::clause_part::column);
+ q.append (c.table (), c.column ());
return q;
}
private:
- const char* name_;
+ const char* table_;
+ const char* column_;
};
//
@@ -1240,13 +1256,6 @@ namespace odb
: query_selector<T>::type (qc)
{
}
-
- std::string
- clause () const
- {
- return query_selector<T>::type::clause (
- query_selector<T>::table_name ());
- }
};
}
diff --git a/odb/sqlite/query.txx b/odb/sqlite/query.txx
index 6af80e7..590d4bd 100644
--- a/odb/sqlite/query.txx
+++ b/odb/sqlite/query.txx
@@ -15,12 +15,11 @@ namespace odb
query (const query_column<bool, ID>& c)
: parameters_ (new (details::shared) query_params)
{
- clause_.push_back (clause_part (clause_part::column, c.name ()));
-
// Cannot use IS TRUE here since database type can be a non-
// integral type.
//
- clause_.push_back (clause_part (clause_part::native, "="));
+ append (c.table (), c.column ());
+ append ("=");
append<bool, ID> (val_bind<bool> (true));
}
@@ -30,7 +29,7 @@ namespace odb
query query_column<T, ID>::
in (const T& v1, const T& v2) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "IN (";
q.append<T, ID> (val_bind<T> (v1));
q += ",";
@@ -43,7 +42,7 @@ namespace odb
query query_column<T, ID>::
in (const T& v1, const T& v2, const T& v3) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "IN (";
q.append<T, ID> (val_bind<T> (v1));
q += ",";
@@ -58,7 +57,7 @@ namespace odb
query query_column<T, ID>::
in (const T& v1, const T& v2, const T& v3, const T& v4) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "IN (";
q.append<T, ID> (val_bind<T> (v1));
q += ",";
@@ -75,7 +74,7 @@ namespace odb
query query_column<T, ID>::
in (const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "IN (";
q.append<T, ID> (val_bind<T> (v1));
q += ",";
@@ -95,7 +94,7 @@ namespace odb
query query_column<T, ID>::
in_range (I begin, I end) const
{
- query q (name_, query::clause_part::column);
+ query q (table_, column_);
q += "IN (";
for (I i (begin); i != end; ++i)