aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite/query.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/sqlite/query.hxx')
-rw-r--r--odb/sqlite/query.hxx99
1 files changed, 54 insertions, 45 deletions
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 ());
- }
};
}