diff options
-rw-r--r-- | odb/oracle/makefile | 2 | ||||
-rw-r--r-- | odb/oracle/object-result.hxx | 73 | ||||
-rw-r--r-- | odb/oracle/object-result.txx | 109 | ||||
-rw-r--r-- | odb/oracle/query-const-expr.cxx | 16 | ||||
-rw-r--r-- | odb/oracle/query.cxx | 345 | ||||
-rw-r--r-- | odb/oracle/query.hxx | 1724 | ||||
-rw-r--r-- | odb/oracle/query.ixx | 28 | ||||
-rw-r--r-- | odb/oracle/query.txx | 111 | ||||
-rw-r--r-- | odb/oracle/result.hxx | 35 | ||||
-rw-r--r-- | odb/oracle/view-result.hxx | 68 | ||||
-rw-r--r-- | odb/oracle/view-result.txx | 77 |
11 files changed, 2588 insertions, 0 deletions
diff --git a/odb/oracle/makefile b/odb/oracle/makefile index bd8d8cb..98cd7c8 100644 --- a/odb/oracle/makefile +++ b/odb/oracle/makefile @@ -14,6 +14,8 @@ database.cxx \ error.cxx \ exceptions.cxx \ object-statements.cxx \ +query.cxx \ +query-const-expr.cxx \ statement.cxx \ statements-base.cxx \ traits.cxx \ diff --git a/odb/oracle/object-result.hxx b/odb/oracle/object-result.hxx new file mode 100644 index 0000000..aa20615 --- /dev/null +++ b/odb/oracle/object-result.hxx @@ -0,0 +1,73 @@ +// file : odb/oracle/object-result.hxx +// author : Constantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#ifndef ODB_ORACLE_OBJECT_RESULT_HXX +#define ODB_ORACLE_OBJECT_RESULT_HXX + +#include <odb/pre.hxx> + +#include <cstddef> // std::size_t + +#include <odb/details/shared-ptr.hxx> + +#include <odb/oracle/version.hxx> +#include <odb/oracle/forward.hxx> // query, object_statements +#include <odb/oracle/result.hxx> +#include <odb/oracle/statement.hxx> + +namespace odb +{ + namespace oracle + { + template <typename T> + class result_impl<T, class_object>: + public odb::result_impl<T, class_object> + { + public: + typedef odb::result_impl<T, class_object> base_type; + + typedef typename base_type::object_type object_type; + typedef typename base_type::object_traits object_traits; + typedef typename base_type::id_type id_type; + + typedef typename base_type::pointer_type pointer_type; + typedef typename base_type::pointer_traits pointer_traits; + + virtual + ~result_impl (); + + result_impl (const query&, + details::shared_ptr<select_statement>, + object_statements<object_type>&); + + virtual void + load (object_type&); + + virtual id_type + load_id (); + + virtual void + next (); + + virtual void + cache (); + + virtual std::size_t + size (); + + using base_type::current; + + private: + details::shared_ptr<select_statement> statement_; + object_statements<object_type>& statements_; + }; + } +} + +#include <odb/oracle/object-result.txx> + +#include <odb/post.hxx> + +#endif // ODB_ORACLE_OBJECT_RESULT_HXX diff --git a/odb/oracle/object-result.txx b/odb/oracle/object-result.txx new file mode 100644 index 0000000..01a8a6f --- /dev/null +++ b/odb/oracle/object-result.txx @@ -0,0 +1,109 @@ +// file : odb/oracle/object-result.txx +// author : Constantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#include <odb/callback.hxx> +#include <odb/exceptions.hxx> + +#include <odb/oracle/object-statements.hxx> + +namespace odb +{ + namespace oracle + { + template <typename T> + result_impl<T, class_object>:: + ~result_impl () + { + } + + template <typename T> + result_impl<T, class_object>:: + result_impl (const query&, + details::shared_ptr<select_statement> statement, + object_statements<object_type>& statements) + : base_type (statements.connection ().database ()), + statement_ (statement), + statements_ (statements) + { + } + + template <typename T> + void result_impl<T, class_object>:: + load (object_type& obj) + { + // This is a top-level call so the statements cannot be locked. + // + assert (!statements_.locked ()); + typename object_statements<object_type>::auto_lock l (statements_); + + odb::database& db (this->database ()); + object_traits::callback (db, obj, callback_event::pre_load); + + typename object_traits::image_type& i (statements_.image ()); + object_traits::init (obj, i, db); + + // Initialize the id image and binding and load the rest of the object + // (containers, etc). + // + typename object_traits::id_image_type& idi (statements_.id_image ()); + object_traits::init (idi, object_traits::id (i)); + statement_->stream_result (); + + binding& idb (statements_.id_image_binding ()); + if (idi.version != statements_.id_image_version () || idb.version == 0) + { + object_traits::bind (idb.bind, idi); + statements_.id_image_version (idi.version); + idb.version++; + } + + object_traits::load_ (statements_, obj); + statements_.load_delayed (); + l.unlock (); + object_traits::callback (db, obj, callback_event::post_load); + } + + template <typename T> + typename result_impl<T, class_object>::id_type + result_impl<T, class_object>:: + load_id () + { + return object_traits::id (statements_.image ()); + } + + template <typename T> + void result_impl<T, class_object>:: + next () + { + this->current (pointer_type ()); + + typename object_traits::image_type& im (statements_.image ()); + + if (im.version != statements_.select_image_version ()) + { + binding& b (statements_.select_image_binding ()); + object_traits::bind (b.bind, im, statement_select); + statements_.select_image_version (im.version); + b.version++; + } + + this->end_ = this->end_ || + (statement_->fetch () == select_statement::success ? false : true); + } + + template <typename T> + void result_impl<T, class_object>:: + cache () + { + } + + template <typename T> + std::size_t result_impl<T, class_object>:: + size () + { + throw result_not_cached (); + } + } +} diff --git a/odb/oracle/query-const-expr.cxx b/odb/oracle/query-const-expr.cxx new file mode 100644 index 0000000..e5fa2d0 --- /dev/null +++ b/odb/oracle/query-const-expr.cxx @@ -0,0 +1,16 @@ +// file : odb/oracle/query-const-expr.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#include <odb/oracle/query.hxx> + +namespace odb +{ + namespace oracle + { + // Sun CC cannot handle this in query.cxx. + // + const query query::true_expr (true); + } +} diff --git a/odb/oracle/query.cxx b/odb/oracle/query.cxx new file mode 100644 index 0000000..4a6642b --- /dev/null +++ b/odb/oracle/query.cxx @@ -0,0 +1,345 @@ +// file : odb/oracle/query.cxx +// author : Constantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#include <cstddef> // std::size_t +#include <cstring> // std::memset +#include <sstream> // std::ostringstream + +#include <odb/oracle/query.hxx> + +using namespace std; + +namespace odb +{ + namespace oracle + { + // query_param + // + query_param:: + ~query_param () + { + } + + // query + // + query:: + query (const query& q) + : clause_ (q.clause_), + parameters_ (q.parameters_), + bind_ (q.bind_), + binding_ (0, 0) + { + // Here and below we want to maintain up to date binding info so + // that the call to parameters_binding() below is an immutable + // operation, provided the query does not have any by-reference + // parameters. This way a by-value-only query can be shared + // between multiple threads without the need for synchronization. + // + if (size_t n = bind_.size ()) + { + binding_.bind = &bind_[0]; + binding_.count = n; + binding_.version++; + } + } + + query& query:: + operator= (const query& q) + { + if (this != &q) + { + clause_ = q.clause_; + parameters_ = q.parameters_; + bind_ = q.bind_; + + size_t n (bind_.size ()); + binding_.bind = n != 0 ? &bind_[0] : 0; + binding_.count = n; + binding_.version++; + } + + return *this; + } + + query& query:: + operator+= (const query& q) + { + clause_.insert (clause_.end (), q.clause_.begin (), q.clause_.end ()); + + size_t n (bind_.size ()); + + parameters_.insert ( + parameters_.end (), q.parameters_.begin (), q.parameters_.end ()); + + bind_.insert ( + bind_.end (), q.bind_.begin (), q.bind_.end ()); + + if (n != bind_.size ()) + { + binding_.bind = &bind_[0]; + binding_.count = bind_.size (); + binding_.version++; + } + + return *this; + } + + void query:: + append (const string& q) + { + if (!clause_.empty () && clause_.back ().kind == clause_part::native) + { + string& s (clause_.back ().part); + + char first (!q.empty () ? q[0] : ' '); + char last (!s.empty () ? s[s.size () - 1] : ' '); + + // We don't want extra spaces after '(' as well as before ',' + // and ')'. + // + if (last != ' ' && last != '(' && + first != ' ' && first != ',' && first != ')') + s += ' '; + + s += q; + } + else + 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:: + add (details::shared_ptr<query_param> p) + { + clause_.push_back (clause_part (clause_part::param)); + + parameters_.push_back (p); + bind_.push_back (bind ()); + binding_.bind = &bind_[0]; + binding_.count = bind_.size (); + binding_.version++; + + bind* b (&bind_.back ()); + memset (b, 0, sizeof (bind)); + p->bind (b); + } + + binding& query:: + parameters_binding () const + { + size_t n (parameters_.size ()); + binding& r (binding_); + + if (n == 0) + return r; + + bool inc_ver (false); + bind* b (&bind_[0]); + + for (size_t i (0); i < n; ++i) + { + query_param& p (*parameters_[i]); + + if (p.reference ()) + { + if (p.init ()) + { + p.bind (b + i); + inc_ver = true; + } + } + } + + if (inc_ver) + r.version++; + + return r; + } + + static bool + check_prefix (const string& s) + { + string::size_type n; + + // It is easier to compare to upper and lower-case versions + // rather than getting involved with the portable case- + // insensitive string comparison mess. + // + if (s.compare (0, (n = 5), "WHERE") == 0 || + s.compare (0, (n = 5), "where") == 0 || + s.compare (0, (n = 6), "SELECT") == 0 || + s.compare (0, (n = 6), "select") == 0 || + s.compare (0, (n = 8), "ORDER BY") == 0 || + s.compare (0, (n = 8), "order by") == 0 || + s.compare (0, (n = 8), "GROUP BY") == 0 || + s.compare (0, (n = 8), "group by") == 0 || + s.compare (0, (n = 6), "HAVING") == 0 || + s.compare (0, (n = 6), "having") == 0) + { + // It either has to be an exact match, or there should be + // a whitespace following the keyword. + // + if (s.size () == n || s[n] == ' ' || s[n] =='\t') + return true; + } + + return false; + } + + void query:: + optimize () + { + // Remove a single TRUE literal or one that is followe by one of + // the other clauses. This avoids usless WHERE clauses like + // + // WHERE TRUE GROUP BY foo + // + clause_type::iterator i (clause_.begin ()), e (clause_.end ()); + + if (i != e && i->kind == clause_part::boolean && i->bool_part) + { + clause_type::iterator j (i + 1); + + if (j == e || + (j->kind == clause_part::native && check_prefix (j->part))) + clause_.erase (i); + } + } + + const char* query:: + clause_prefix () const + { + if (!clause_.empty ()) + { + const clause_part& p (clause_.front ()); + + if (p.kind == clause_part::native && check_prefix (p.part)) + return ""; + + return "WHERE "; + } + + return ""; + } + + string query:: + clause () const + { + string r; + size_t param (1); + + for (clause_type::const_iterator i (clause_.begin ()), + end (clause_.end ()); + i != end; + ++i) + { + char last (!r.empty () ? r[r.size () - 1] : ' '); + + switch (i->kind) + { + case clause_part::column: + { + if (last != ' ' && last != '(') + r += ' '; + + r += i->part; + break; + } + case clause_part::param: + { + if (last != ' ' && last != '(') + r += ' '; + + ostringstream os; + os << param++; + r += ':'; + r += os.str (); + break; + } + case clause_part::native: + { + // We don't want extra spaces after '(' as well as before ',' + // and ')'. + // + const string& p (i->part); + char first (!p.empty () ? p[0] : ' '); + + if (last != ' ' && last != '(' && + first != ' ' && first != ',' && first != ')') + r += ' '; + + r += p; + break; + } + case clause_part::boolean: + { + if (last != ' ' && last != '(') + r += ' '; + + r += i->bool_part ? "1 = 1" : "1 = 0"; + break; + } + } + } + + return clause_prefix () + r; + } + + query + operator&& (const query& x, const query& y) + { + // Optimize cases where one or both sides are constant truth. + // + bool xt (x.const_true ()), yt (y.const_true ()); + + if (xt && yt) + return x; + + if (xt) + return y; + + if (yt) + return x; + + query r ("("); + r += x; + r += ") AND ("; + r += y; + r += ")"; + return r; + } + + query + operator|| (const query& x, const query& y) + { + query r ("("); + r += x; + r += ") OR ("; + r += y; + r += ")"; + return r; + } + + query + operator! (const query& x) + { + query r ("NOT ("); + r += x; + r += ")"; + return r; + } + } +} diff --git a/odb/oracle/query.hxx b/odb/oracle/query.hxx new file mode 100644 index 0000000..d491cdf --- /dev/null +++ b/odb/oracle/query.hxx @@ -0,0 +1,1724 @@ +// file : odb/oracle/query.hxx +// author : Contantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#ifndef ODB_ORACLE_QUERY_HXX +#define ODB_ORACLE_QUERY_HXX + +#include <odb/pre.hxx> + +#include <string> +#include <vector> +#include <cstddef> // std::size_t + +#include <odb/query.hxx> + +#include <odb/oracle/version.hxx> +#include <odb/oracle/forward.hxx> +#include <odb/oracle/traits.hxx> +#include <odb/oracle/binding.hxx> + +#include <odb/details/buffer.hxx> +#include <odb/details/shared-ptr.hxx> + +#include <odb/oracle/details/export.hxx> + +namespace odb +{ + namespace oracle + { + template <typename T> + class val_bind + { + public: + explicit + val_bind (const T& v): val (v) {} + + const T& val; + }; + + template <typename T> + class ref_bind + { + public: + explicit + ref_bind (const T& r): ref (r) {} + + const T& ref; + }; + + struct LIBODB_ORACLE_EXPORT query_param: details::shared_base + { + typedef oracle::bind bind_type; + + virtual + ~query_param (); + + bool + reference () const + { + return value_ != 0; + } + + virtual bool + init () = 0; + + virtual void + bind (bind_type*) = 0; + + protected: + query_param (const void* value) + : value_ (value) + { + } + + protected: + const void* value_; + }; + + // + // + template <typename T, database_type_id ID> + struct query_column; + + class LIBODB_ORACLE_EXPORT query + { + public: + struct clause_part + { + enum kind_type + { + column, + param, + native, + boolean + }; + + clause_part (kind_type k): kind (k) {} + clause_part (kind_type k, const std::string& p): kind (k), part (p) {} + clause_part (bool p): kind (boolean), bool_part (p) {} + + kind_type kind; + std::string part; + bool bool_part; + }; + + query () + : binding_ (0, 0) + { + } + + // True or false literal. + // + explicit + query (bool v) + : binding_ (0, 0) + { + clause_.push_back (clause_part (v)); + } + + explicit + query (const char* native) + : binding_ (0, 0) + { + clause_.push_back (clause_part (clause_part::native, native)); + } + + explicit + query (const std::string& native) + : binding_ (0, 0) + { + clause_.push_back (clause_part (clause_part::native, native)); + } + + query (const char* table, const char* column) + : binding_ (0, 0) + { + append (table, column); + } + + template <typename T> + explicit + query (val_bind<T> v) + : binding_ (0, 0) + { + append<T, type_traits<T>::db_type_id> (v); + } + + template <typename T> + explicit + query (ref_bind<T> r) + : binding_ (0, 0) + { + append<T, type_traits<T>::db_type_id> (r); + } + + template <database_type_id ID> + query (const query_column<bool, ID>&); + + query (const query&); + + query& + operator= (const query&); + + public: + std::string + clause () const; + + const char* + clause_prefix () const; + + binding& + parameters_binding () const; + + public: + bool + empty () const + { + return clause_.empty (); + } + + static const query true_expr; + + bool + const_true () const + { + return clause_.size () == 1 && + clause_.front ().kind == clause_part::boolean && + clause_.front ().bool_part; + } + + void + optimize (); + + public: + template <typename T> + static val_bind<T> + _val (const T& x) + { + return val_bind<T> (x); + } + + template <typename T> + static ref_bind<T> + _ref (const T& x) + { + return ref_bind<T> (x); + } + + public: + query& + operator+= (const query&); + + query& + operator+= (const std::string& q) + { + append (q); + return *this; + } + + template <typename T> + query& + operator+= (val_bind<T> v) + { + append<T, type_traits<T>::db_type_id> (v); + return *this; + } + + template <typename T> + query& + operator+= (ref_bind<T> r) + { + append<T, type_traits<T>::db_type_id> (r); + return *this; + } + + public: + template <typename T, database_type_id ID> + void + append (val_bind<T>); + + template <typename T, database_type_id ID> + void + append (ref_bind<T>); + + void + append (const std::string& native); + + void + append (const char* table, const char* column); + + private: + void + add (details::shared_ptr<query_param>); + + private: + typedef std::vector<clause_part> clause_type; + typedef std::vector<details::shared_ptr<query_param> > parameters_type; + + clause_type clause_; + parameters_type parameters_; + mutable std::vector<bind> bind_; + mutable binding binding_; + }; + + inline query + operator+ (const query& x, const query& y) + { + query r (x); + r += y; + return r; + } + + template <typename T> + inline query + operator+ (const query& q, val_bind<T> b) + { + query r (q); + r += b; + return r; + } + + template <typename T> + inline query + operator+ (const query& q, ref_bind<T> b) + { + query r (q); + r += b; + return r; + } + + template <typename T> + inline query + operator+ (val_bind<T> b, const query& q) + { + query r; + r += b; + r += q; + return r; + } + + template <typename T> + inline query + operator+ (ref_bind<T> b, const query& q) + { + query r; + r += b; + r += q; + return r; + } + + inline query + operator+ (const query& q, const std::string& s) + { + query r (q); + r += s; + return r; + } + + inline query + operator+ (const std::string& s, const query& q) + { + query r (s); + r += q; + return r; + } + + template <typename T> + inline query + operator+ (const std::string& s, val_bind<T> b) + { + query r (s); + r += b; + return r; + } + + template <typename T> + inline query + operator+ (const std::string& s, ref_bind<T> b) + { + query r (s); + r += b; + return r; + } + + template <typename T> + inline query + operator+ (val_bind<T> b, const std::string& s) + { + query r; + r += b; + r += s; + return r; + } + + template <typename T> + inline query + operator+ (ref_bind<T> b, const std::string& s) + { + query r; + r += b; + r += s; + return r; + } + + LIBODB_ORACLE_EXPORT query + operator&& (const query& x, const query& y); + + LIBODB_ORACLE_EXPORT query + operator|| (const query& x, const query& y); + + LIBODB_ORACLE_EXPORT query + operator! (const query& x); + + // query_column + // + + template <typename T, typename T2> + class copy_bind: public val_bind<T> + { + public: + explicit + copy_bind (const T2& v): val_bind<T> (val), val (v) {} + + const T val; + }; + + template <typename T> + const T& + type_instance (); + + template <typename T, database_type_id ID> + struct query_column + { + // 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* + table () const + { + return table_; + } + + const char* + column () const + { + return column_; + } + + // is_null, is_not_null + // + public: + query + is_null () const + { + query q (table_, column_); + q += "IS NULL"; + return q; + } + + query + is_not_null () const + { + query q (table_, column_); + q += "IS NOT NULL"; + return q; + } + + // in + // + public: + query + in (const T&, const T&) const; + + query + in (const T&, const T&, const T&) const; + + query + in (const T&, const T&, const T&, const T&) const; + + query + in (const T&, const T&, const T&, const T&, const T&) const; + + template <typename I> + query + in_range (I begin, I end) const; + + // = + // + public: + query + equal (const T& v) const + { + return equal (val_bind<T> (v)); + } + + query + equal (val_bind<T> v) const + { + query q (table_, column_); + q += "="; + q.append<T, ID> (v); + return q; + } + + template <typename T2> + query + equal (val_bind<T2> v) const + { + copy_bind<T, T2> c (v.val); + return equal (c); + } + + query + equal (ref_bind<T> r) const + { + query q (table_, column_); + q += "="; + q.append<T, ID> (r); + return q; + } + + friend query + operator== (const query_column& c, const T& v) + { + return c.equal (v); + } + + friend query + operator== (const T& v, const query_column& c) + { + return c.equal (v); + } + + friend query + operator== (const query_column& c, val_bind<T> v) + { + return c.equal (v); + } + + friend query + operator== (val_bind<T> v, const query_column& c) + { + return c.equal (v); + } + + template <typename T2> + friend query + operator== (const query_column& c, val_bind<T2> v) + { + return c.equal (v); + } + + template <typename T2> + friend query + operator== (val_bind<T2> v, const query_column& c) + { + return c.equal (v); + } + + friend query + operator== (const query_column& c, ref_bind<T> r) + { + return c.equal (r); + } + + friend query + operator== (ref_bind<T> r, const query_column& c) + { + return c.equal (r); + } + + // != + // + public: + query + unequal (const T& v) const + { + return unequal (val_bind<T> (v)); + } + + query + unequal (val_bind<T> v) const + { + query q (table_, column_); + q += "!="; + q.append<T, ID> (v); + return q; + } + + template <typename T2> + query + unequal (val_bind<T2> v) const + { + copy_bind<T, T2> c (v.val); + return unequal (c); + } + + query + unequal (ref_bind<T> r) const + { + query q (table_, column_); + q += "!="; + q.append<T, ID> (r); + return q; + } + + friend query + operator!= (const query_column& c, const T& v) + { + return c.unequal (v); + } + + friend query + operator!= (const T& v, const query_column& c) + { + return c.unequal (v); + } + + friend query + operator!= (const query_column& c, val_bind<T> v) + { + return c.unequal (v); + } + + friend query + operator!= (val_bind<T> v, const query_column& c) + { + return c.unequal (v); + } + + template <typename T2> + friend query + operator!= (const query_column& c, val_bind<T2> v) + { + return c.unequal (v); + } + + template <typename T2> + friend query + operator!= (val_bind<T2> v, const query_column& c) + { + return c.unequal (v); + } + + friend query + operator!= (const query_column& c, ref_bind<T> r) + { + return c.unequal (r); + } + + friend query + operator!= (ref_bind<T> r, const query_column& c) + { + return c.unequal (r); + } + + // < + // + public: + query + less (const T& v) const + { + return less (val_bind<T> (v)); + } + + query + less (val_bind<T> v) const + { + query q (table_, column_); + q += "<"; + q.append<T, ID> (v); + return q; + } + + template <typename T2> + query + less (val_bind<T2> v) const + { + copy_bind<T, T2> c (v.val); + return less (c); + } + + query + less (ref_bind<T> r) const + { + query q (table_, column_); + q += "<"; + q.append<T, ID> (r); + return q; + } + + friend query + operator< (const query_column& c, const T& v) + { + return c.less (v); + } + + friend query + operator< (const T& v, const query_column& c) + { + return c.greater (v); + } + + friend query + operator< (const query_column& c, val_bind<T> v) + { + return c.less (v); + } + + friend query + operator< (val_bind<T> v, const query_column& c) + { + return c.greater (v); + } + + template <typename T2> + friend query + operator< (const query_column& c, val_bind<T2> v) + { + return c.less (v); + } + + template <typename T2> + friend query + operator< (val_bind<T2> v, const query_column& c) + { + return c.greater (v); + } + + friend query + operator< (const query_column& c, ref_bind<T> r) + { + return c.less (r); + } + + friend query + operator< (ref_bind<T> r, const query_column& c) + { + return c.greater (r); + } + + // > + // + public: + query + greater (const T& v) const + { + return greater (val_bind<T> (v)); + } + + query + greater (val_bind<T> v) const + { + query q (table_, column_); + q += ">"; + q.append<T, ID> (v); + return q; + } + + template <typename T2> + query + greater (val_bind<T2> v) const + { + copy_bind<T, T2> c (v.val); + return greater (c); + } + + query + greater (ref_bind<T> r) const + { + query q (table_, column_); + q += ">"; + q.append<T, ID> (r); + return q; + } + + friend query + operator> (const query_column& c, const T& v) + { + return c.greater (v); + } + + friend query + operator> (const T& v, const query_column& c) + { + return c.less (v); + } + + friend query + operator> (const query_column& c, val_bind<T> v) + { + return c.greater (v); + } + + friend query + operator> (val_bind<T> v, const query_column& c) + { + return c.less (v); + } + + template <typename T2> + friend query + operator> (const query_column& c, val_bind<T2> v) + { + return c.greater (v); + } + + template <typename T2> + friend query + operator> (val_bind<T2> v, const query_column& c) + { + return c.less (v); + } + + friend query + operator> (const query_column& c, ref_bind<T> r) + { + return c.greater (r); + } + + friend query + operator> (ref_bind<T> r, const query_column& c) + { + return c.less (r); + } + + // <= + // + public: + query + less_equal (const T& v) const + { + return less_equal (val_bind<T> (v)); + } + + query + less_equal (val_bind<T> v) const + { + query q (table_, column_); + q += "<="; + q.append<T, ID> (v); + return q; + } + + template <typename T2> + query + less_equal (val_bind<T2> v) const + { + copy_bind<T, T2> c (v.val); + return less_equal (c); + } + + query + less_equal (ref_bind<T> r) const + { + query q (table_, column_); + q += "<="; + q.append<T, ID> (r); + return q; + } + + friend query + operator<= (const query_column& c, const T& v) + { + return c.less_equal (v); + } + + friend query + operator<= (const T& v, const query_column& c) + { + return c.greater_equal (v); + } + + friend query + operator<= (const query_column& c, val_bind<T> v) + { + return c.less_equal (v); + } + + friend query + operator<= (val_bind<T> v, const query_column& c) + { + return c.greater_equal (v); + } + + template <typename T2> + friend query + operator<= (const query_column& c, val_bind<T2> v) + { + return c.less_equal (v); + } + + template <typename T2> + friend query + operator<= (val_bind<T2> v, const query_column& c) + { + return c.greater_equal (v); + } + + friend query + operator<= (const query_column& c, ref_bind<T> r) + { + return c.less_equal (r); + } + + friend query + operator<= (ref_bind<T> r, const query_column& c) + { + return c.greater_equal (r); + } + + // >= + // + public: + query + greater_equal (const T& v) const + { + return greater_equal (val_bind<T> (v)); + } + + query + greater_equal (val_bind<T> v) const + { + query q (table_, column_); + q += ">="; + q.append<T, ID> (v); + return q; + } + + template <typename T2> + query + greater_equal (val_bind<T2> v) const + { + copy_bind<T, T2> c (v.val); + return greater_equal (c); + } + + query + greater_equal (ref_bind<T> r) const + { + query q (table_, column_); + q += ">="; + q.append<T, ID> (r); + return q; + } + + friend query + operator>= (const query_column& c, const T& v) + { + return c.greater_equal (v); + } + + friend query + operator>= (const T& v, const query_column& c) + { + return c.less_equal (v); + } + + friend query + operator>= (const query_column& c, val_bind<T> v) + { + return c.greater_equal (v); + } + + friend query + operator>= (val_bind<T> v, const query_column& c) + { + return c.less_equal (v); + } + + template <typename T2> + friend query + operator>= (const query_column& c, val_bind<T2> v) + { + return c.greater_equal (v); + } + + template <typename T2> + friend query + operator>= (val_bind<T2> v, const query_column& c) + { + return c.less_equal (v); + } + + friend query + operator>= (const query_column& c, ref_bind<T> r) + { + return c.greater_equal (r); + } + + friend query + operator>= (ref_bind<T> r, const query_column& c) + { + return c.less_equal (r); + } + + // Column comparison. + // + public: + template <typename T2, database_type_id ID2> + query + operator== (const query_column<T2, ID2>& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (type_instance<T> () == type_instance<T2> ())); + + query q (table_, column_); + q += "="; + q.append (c.table (), c.column ()); + return q; + } + + template <typename T2, database_type_id ID2> + query + operator!= (const query_column<T2, ID2>& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (type_instance<T> () != type_instance<T2> ())); + + query q (table_, column_); + q += "!="; + q.append (c.table (), c.column ()); + return q; + } + + template <typename T2, database_type_id ID2> + query + operator< (const query_column<T2, ID2>& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (type_instance<T> () < type_instance<T2> ())); + + query q (table_, column_); + q += "<"; + q.append (c.table (), c.column ()); + return q; + } + + template <typename T2, database_type_id ID2> + query + operator> (const query_column<T2, ID2>& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (type_instance<T> () > type_instance<T2> ())); + + query q (table_, column_); + q += ">"; + q.append (c.table (), c.column ()); + return q; + } + + template <typename T2, database_type_id ID2> + query + operator<= (const query_column<T2, ID2>& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (type_instance<T> () <= type_instance<T2> ())); + + query q (table_, column_); + q += "<="; + q.append (c.table (), c.column ()); + return q; + } + + template <typename T2, database_type_id ID2> + query + operator>= (const query_column<T2, ID2>& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (type_instance<T> () >= type_instance<T2> ())); + + query q (table_, column_); + q += ">="; + q.append (c.table (), c.column ()); + return q; + } + + private: + const char* table_; + const char* column_; + }; + + // + // Oracle does not support comparison operations between LOB columns. + // query_column therefore only supports the IS NULL and IS NOT NULL + // predicates for these types. + // + + template <typename T> + struct query_column<T, id_blob> + { + // 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* + table () const + { + return table_; + } + + const char* + column () const + { + return column_; + } + + // is_null, is_not_null + // + public: + query + is_null () const + { + query q (table_, column_); + q += "IS NULL"; + return q; + } + + query + is_not_null () const + { + query q (table_, column_); + q += "IS NOT NULL"; + return q; + } + + private: + const char* table_; + const char* column_; + }; + + template <typename T> + struct query_column<T, id_clob> + { + // 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* + table () const + { + return table_; + } + + const char* + column () const + { + return column_; + } + + // is_null, is_not_null + // + public: + query + is_null () const + { + query q (table_, column_); + q += "IS NULL"; + return q; + } + + query + is_not_null () const + { + query q (table_, column_); + q += "IS NOT NULL"; + return q; + } + + private: + const char* table_; + const char* column_; + }; + + template <typename T> + struct query_column<T, id_nclob> + { + // 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* + table () const + { + return table_; + } + + const char* + column () const + { + return column_; + } + + // is_null, is_not_null + // + public: + query + is_null () const + { + query q (table_, column_); + q += "IS NULL"; + return q; + } + + query + is_not_null () const + { + query q (table_, column_); + q += "IS NOT NULL"; + return q; + } + + private: + const char* table_; + const char* column_; + }; + + // Provide operator+() for using columns to construct native + // query fragments (e.g., ORDER BY). + // + template <typename T, database_type_id ID> + inline query + operator+ (const query_column<T, ID>& c, const std::string& s) + { + query q (c.table (), c.column ()); + q += s; + return q; + } + + template <typename T, database_type_id ID> + inline query + operator+ (const std::string& s, const query_column<T, ID>& c) + { + query q (s); + q.append (c.table (), c.column ()); + return q; + } + + template <typename T, database_type_id ID> + inline query + operator+ (const query_column<T, ID>& c, const query& q) + { + query r (c.table (), c.column ()); + r += q; + return r; + } + + template <typename T, database_type_id ID> + inline query + operator+ (const query& q, const query_column<T, ID>& c) + { + query r (q); + r.append (c.table (), c.column ()); + return r; + } + + // + // + template <typename T, database_type_id> + struct query_param_impl; + + // id_int32. + // + template <typename T> + struct query_param_impl<T, id_int32>: query_param + { + query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} + query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast<const T*> (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind_type::integer; + b->buffer = &image_; + b->capacity = sizeof (int); + b->size = 0; + } + + private: + void + init (const T& v) + { + bool dummy; + value_traits<T, id_int32>::set_image (image_, dummy, v); + } + + private: + typename image_traits<T, id_int32>::image_type image_; + }; + + // id_int64. + // + template <typename T> + struct query_param_impl<T, id_int64>: query_param + { + query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} + query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast<const T*> (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind_type::integer; + b->buffer = &image_; + b->capacity = sizeof (long long); + b->size = 0; + } + + private: + void + init (const T& v) + { + bool dummy; + value_traits<T, id_int64>::set_image (image_, dummy, v); + } + + private: + typename image_traits<T, id_int64>::image_type image_; + }; + + // id_big_int. + // + template <typename T> + struct query_param_impl<T, id_big_int>: query_param + { + query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} + query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast<const T*> (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind_type::number; + b->buffer = &image_; + b->capacity = sizeof (image_); + b->size = &size_; + } + + private: + void + init (const T& v) + { + bool dummy; + std::size_t size (0); + value_traits<T, id_big_int>::set_image (image_, size, dummy, v); + size_ = static_cast<ub2> (size); + } + + private: + char image_[21]; + ub2 size_; + }; + + // id_float. + // + template <typename T> + struct query_param_impl<T, id_float>: query_param + { + query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} + query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast<const T*> (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind_type::binary_float; + b->buffer = &image_; + b->capacity = sizeof (float); + b->size = 0; + } + + private: + void + init (const T& v) + { + bool dummy; + value_traits<T, id_float>::set_image (image_, dummy, v); + } + + private: + float image_; + }; + + // id_double. + // + template <typename T> + struct query_param_impl<T, id_double>: query_param + { + query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} + query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast<const T*> (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind_type::binary_double; + b->buffer = &image_; + b->capacity = sizeof (double); + b->size = 0; + } + + private: + void + init (const T& v) + { + bool dummy; + value_traits<T, id_double>::set_image (image_, dummy, v); + } + + private: + double image_; + }; + + // id_big_float. + // + template <typename T> + struct query_param_impl<T, id_big_float>: query_param + { + query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} + query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast<const T*> (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind_type::number; + b->buffer = &image_; + b->capacity = sizeof (image_); + b->size = &size_; + } + + private: + void + init (const T& v) + { + bool dummy; + std::size_t size (0); + value_traits<T, id_big_float>::set_image (image_, size, dummy, v); + size_ = static_cast<ub2> (size); + } + + private: + char image_[21]; + ub2 size_; + }; + + // id_date. + // + template <typename T> + struct query_param_impl<T, id_date>: query_param + { + query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} + query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast<const T*> (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind_type::date; + b->buffer = &image_; + b->capacity = sizeof (image_); + b->size = 0; + } + + private: + void + init (const T& v) + { + bool dummy; + value_traits<T, id_date>::set_image (image_, dummy, v); + } + + private: + char image_[7]; + }; + + // id_timestamp + // + template <typename T> + struct query_param_impl<T, id_timestamp>: query_param + { + query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} + query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast<const T*> (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind_type::timestamp; + b->buffer = &image_; + b->capacity = sizeof (image_); + b->size = &size_; + } + + private: + void + init (const T& v) + { + bool dummy; + std::size_t size (0), cap (11); + value_traits<T, id_timestamp>::set_image (image_, size, cap, dummy, v); + size_ = static_cast<ub2> (size); + } + + private: + char image_[11]; + ub2 size_; + }; + + // id_string. + // + template <typename T> + struct query_param_impl<T, id_string>: query_param + { + query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} + query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast<const T*> (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind_type::string; + b->buffer = image_; + b->capacity = 4000; + b->size = &size_; + } + + private: + void + init (const T& v) + { + bool dummy; + std::size_t size (0); + value_traits<T, id_string>::set_image (image_, 4000, size, dummy, v); + size_ = static_cast<ub2> (size); + } + + private: + char image_[4000]; + ub2 size_; + }; + + // id_nstring + // + template <typename T> + struct query_param_impl<T, id_nstring>: query_param + { + query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} + query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast<const T*> (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind_type::string; + b->buffer = image_; + b->capacity = 4000; + b->size = &size_; + } + + private: + void + init (const T& v) + { + bool dummy; + std::size_t size (0); + value_traits<T, id_nstring>::set_image (image_, 4000, size, dummy, v); + size_ = static_cast<ub2> (size); + } + + private: + char image_[4000]; + ub2 size_; + }; + + // id_raw + // + template <typename T> + struct query_param_impl<T, id_raw>: query_param + { + query_param_impl (ref_bind<T> r) : query_param (&r.ref) {} + query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast<const T*> (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind_type::string; + b->buffer = image_; + b->capacity = 4000; + b->size = &size_; + } + + private: + void + init (const T& v) + { + bool dummy; + std::size_t size (0); + value_traits<T, id_raw>::set_image (image_, 4000, size, dummy, v); + size_ = static_cast<ub2> (size); + } + + private: + char image_[4000]; + ub2 size_; + }; + } +} + +// odb::query specialization for Oracle. +// +namespace odb +{ + template <typename T> + class query<T, oracle::query>: public query_selector<T>::type + { + public: + // We don't define any typedefs here since they may clash with + // column names defined by our base type. + // + + query () + { + } + + explicit + query (bool v) + : query_selector<T>::type (v) + { + } + + explicit + query (const char* q) + : query_selector<T>::type (q) + { + } + + explicit + query (const std::string& q) + : query_selector<T>::type (q) + { + } + + template <typename T2> + explicit + query (oracle::val_bind<T2> v) + : query_selector<T>::type (oracle::query (v)) + { + } + + template <typename T2> + explicit + query (oracle::ref_bind<T2> r) + : query_selector<T>::type (oracle::query (r)) + { + } + + query (const oracle::query& q) + : query_selector<T>::type (q) + { + } + + template <oracle::database_type_id ID> + query (const oracle::query_column<bool, ID>& qc) + : query_selector<T>::type (qc) + { + } + }; +} + +#include <odb/oracle/query.ixx> +#include <odb/oracle/query.txx> + +#include <odb/post.hxx> + +#endif // ODB_ORACLE_QUERY_HXX diff --git a/odb/oracle/query.ixx b/odb/oracle/query.ixx new file mode 100644 index 0000000..5e61f4e --- /dev/null +++ b/odb/oracle/query.ixx @@ -0,0 +1,28 @@ +// file : odb/oracle/query.ixx +// author : Constantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +namespace odb +{ + namespace oracle + { + template <typename T, database_type_id ID> + inline void query:: + append (val_bind<T> v) + { + add ( + details::shared_ptr<query_param> ( + new (details::shared) query_param_impl<T, ID> (v))); + } + + template <typename T, database_type_id ID> + inline void query:: + append (ref_bind<T> r) + { + add ( + details::shared_ptr<query_param> ( + new (details::shared) query_param_impl<T, ID> (r))); + } + } +} diff --git a/odb/oracle/query.txx b/odb/oracle/query.txx new file mode 100644 index 0000000..b8bd3c5 --- /dev/null +++ b/odb/oracle/query.txx @@ -0,0 +1,111 @@ +// file : odb/oracle/query.txx +// author : Constantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +namespace odb +{ + namespace oracle + { + // query + // + + template <database_type_id ID> + query:: + query (const query_column<bool, ID>& c) + : binding_ (0, 0) + { + // Cannot use IS TRUE here since database type can be a non- + // integral type. + // + append (c.table (), c.column ()); + append ("="); + append<bool, ID> (val_bind<bool> (true)); + } + + // query_column + // + template <typename T, database_type_id ID> + query query_column<T, ID>:: + in (const T& v1, const T& v2) const + { + query q (table_, column_); + q += "IN ("; + q.append<T, ID> (val_bind<T> (v1)); + q += ","; + q.append<T, ID> (val_bind<T> (v2)); + q += ")"; + return q; + } + + template <typename T, database_type_id ID> + query query_column<T, ID>:: + in (const T& v1, const T& v2, const T& v3) const + { + query q (table_, column_); + q += "IN ("; + q.append<T, ID> (val_bind<T> (v1)); + q += ","; + q.append<T, ID> (val_bind<T> (v2)); + q += ","; + q.append<T, ID> (val_bind<T> (v3)); + q += ")"; + return q; + } + + template <typename T, database_type_id ID> + query query_column<T, ID>:: + in (const T& v1, const T& v2, const T& v3, const T& v4) const + { + query q (table_, column_); + q += "IN ("; + q.append<T, ID> (val_bind<T> (v1)); + q += ","; + q.append<T, ID> (val_bind<T> (v2)); + q += ","; + q.append<T, ID> (val_bind<T> (v3)); + q += ","; + q.append<T, ID> (val_bind<T> (v4)); + q += ")"; + return q; + } + + template <typename T, database_type_id ID> + query query_column<T, ID>:: + in (const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) const + { + query q (table_, column_); + q += "IN ("; + q.append<T, ID> (val_bind<T> (v1)); + q += ","; + q.append<T, ID> (val_bind<T> (v2)); + q += ","; + q.append<T, ID> (val_bind<T> (v3)); + q += ","; + q.append<T, ID> (val_bind<T> (v4)); + q += ","; + q.append<T, ID> (val_bind<T> (v5)); + q += ")"; + return q; + } + + template <typename T, database_type_id ID> + template <typename I> + query query_column<T, ID>:: + in_range (I begin, I end) const + { + query q (table_, column_); + q += "IN ("; + + for (I i (begin); i != end; ++i) + { + if (i != begin) + q += ","; + + q.append<T, ID> (val_bind<T> (*i)); + } + q += ")"; + return q; + } + } +} diff --git a/odb/oracle/result.hxx b/odb/oracle/result.hxx new file mode 100644 index 0000000..88b6aaa --- /dev/null +++ b/odb/oracle/result.hxx @@ -0,0 +1,35 @@ +// file : odb/oracle/result.hxx +// author : Constantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#ifndef ODB_ORACLE_RESULT_HXX +#define ODB_ORACLE_RESULT_HXX + +#include <odb/pre.hxx> + +#include <odb/traits.hxx> +#include <odb/result.hxx> + +#include <odb/oracle/version.hxx> +#include <odb/oracle/forward.hxx> + +namespace odb +{ + namespace oracle + { + template <typename T, class_kind kind> + class result_impl; + } +} + +#include <odb/post.hxx> + +#endif // ODB_ORACLE_RESULT_HXX + +// Include result specializations so that the user code only needs +// to include this header. +// + +#include <odb/oracle/object-result.hxx> +#include <odb/oracle/view-result.hxx> diff --git a/odb/oracle/view-result.hxx b/odb/oracle/view-result.hxx new file mode 100644 index 0000000..abc0aff --- /dev/null +++ b/odb/oracle/view-result.hxx @@ -0,0 +1,68 @@ +// file : odb/oracle/view-result.hxx +// author : Constantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#ifndef ODB_ORACLE_VIEW_RESULT_HXX +#define ODB_ORACLE_VIEW_RESULT_HXX + +#include <odb/pre.hxx> + +#include <cstddef> // std::size_t + +#include <odb/details/shared-ptr.hxx> + +#include <odb/oracle/version.hxx> +#include <odb/oracle/forward.hxx> // query, view_statements +#include <odb/oracle/result.hxx> +#include <odb/oracle/statement.hxx> + +namespace odb +{ + namespace oracle + { + template <typename T> + class result_impl<T, class_view>: public odb::result_impl<T, class_view> + { + public: + typedef odb::result_impl<T, class_view> base_type; + + typedef typename base_type::view_type view_type; + typedef typename base_type::view_traits view_traits; + + typedef typename base_type::pointer_type pointer_type; + typedef typename base_type::pointer_traits pointer_traits; + + virtual + ~result_impl (); + + result_impl (const query&, + details::shared_ptr<select_statement>, + view_statements<view_type>&); + + virtual void + load (view_type&); + + virtual void + next (); + + virtual void + cache (); + + virtual std::size_t + size (); + + using base_type::current; + + private: + details::shared_ptr<select_statement> statement_; + view_statements<view_type>& statements_; + }; + } +} + +#include <odb/oracle/view-result.txx> + +#include <odb/post.hxx> + +#endif // ODB_ORACLE_VIEW_RESULT_HXX diff --git a/odb/oracle/view-result.txx b/odb/oracle/view-result.txx new file mode 100644 index 0000000..b2049b8 --- /dev/null +++ b/odb/oracle/view-result.txx @@ -0,0 +1,77 @@ +// file : odb/oracle/view-result.txx +// author : Constantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#include <odb/callback.hxx> +#include <odb/exceptions.hxx> + +#include <odb/oracle/view-statements.hxx> + +namespace odb +{ + namespace oracle + { + template <typename T> + result_impl<T, class_view>:: + ~result_impl () + { + } + + template <typename T> + result_impl<T, class_view>:: + result_impl (const query&, + details::shared_ptr<select_statement> statement, + view_statements<view_type>& statements) + : base_type (statements.connection ().database ()), + statement_ (statement), + statements_ (statements) + { + } + + template <typename T> + void result_impl<T, class_view>:: + load (view_type& view) + { + odb::database& db (this->database ()); + + view_traits::callback (db, view, callback_event::pre_load); + view_traits::init (view, statements_.image (), db); + statement_->stream_result (); + view_traits::callback (db, view, callback_event::post_load); + } + + template <typename T> + void result_impl<T, class_view>:: + next () + { + this->current (pointer_type ()); + + typename view_traits::image_type& im (statements_.image ()); + + if (im.version != statements_.image_version ()) + { + binding& b (statements_.image_binding ()); + view_traits::bind (b.bind, im); + statements_.image_version (im.version); + b.version++; + } + + this->end_ = this->end_ || + (statement_->fetch () == select_statement::success ? false : true); + } + + template <typename T> + void result_impl<T, class_view>:: + cache () + { + } + + template <typename T> + std::size_t result_impl<T, class_view>:: + size () + { + throw result_not_cached (); + } + } +} |