aboutsummaryrefslogtreecommitdiff
path: root/odb/oracle/statement.hxx
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-09-07 15:09:58 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-09-07 15:09:58 +0200
commit0ac0cd1b4993f5d8aa00057fdc9eb58ca6450615 (patch)
treecb00ee4c1d85dc2777c95a8ddc46298b7d6a169e /odb/oracle/statement.hxx
parent4c38968b151af31ebd9ffa381f7a00df7183a8d6 (diff)
Add implementations for insert, update, delete, and select statements
Diffstat (limited to 'odb/oracle/statement.hxx')
-rw-r--r--odb/oracle/statement.hxx182
1 files changed, 182 insertions, 0 deletions
diff --git a/odb/oracle/statement.hxx b/odb/oracle/statement.hxx
new file mode 100644
index 0000000..d59f3a6
--- /dev/null
+++ b/odb/oracle/statement.hxx
@@ -0,0 +1,182 @@
+// file : odb/oracle/statement.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#ifndef ODB_ORACLE_STATEMENT_HXX
+#define ODB_ORACLE_STATEMENT_HXX
+
+#include <odb/pre.hxx>
+
+#include <string>
+#include <cstddef> // std::size_t
+
+#include <odb/forward.hxx>
+
+#include <odb/details/shared-ptr.hxx>
+
+#include <odb/oracle/version.hxx>
+#include <odb/oracle/binding.hxx>
+#include <odb/oracle/forward.hxx>
+#include <odb/oracle/oracle-fwd.hxx>
+#include <odb/oracle/auto-handle.hxx>
+
+#include <odb/oracle/details/export.hxx>
+
+namespace odb
+{
+ namespace oracle
+ {
+ class LIBODB_ORACLE_EXPORT statement: public details::shared_base
+ {
+ public:
+ virtual
+ ~statement () = 0;
+
+ protected:
+ statement (connection&, const std::string& statement);
+
+ // Bind output parameters to this statement. This function must
+ // only be called once. Multiple calls to it will result in memory leaks
+ // due to lost OCIBind resources.
+ //
+ void
+ bind_param (bind*, std::size_t count);
+
+ // Bind input parameters to this statement. This function must
+ // only be called once. Multiple calls to it will result in memory leaks
+ // due to lost OCIDefine resources.
+ //
+ void
+ bind_result (bind*, std::size_t count);
+
+ protected:
+ connection& conn_;
+ auto_handle<OCIStmt> stmt_;
+ };
+
+ class LIBODB_ORACLE_EXPORT select_statement: public statement
+ {
+ public:
+ virtual
+ ~select_statement ();
+
+ select_statement (connection& conn,
+ const std::string& statement,
+ binding& cond,
+ binding& data);
+ enum result
+ {
+ success,
+ no_data
+ };
+
+ void
+ execute ();
+
+ // Number of rows already fetched.
+ //
+ std::size_t
+ fetched () const
+ {
+ return rows_;
+ }
+
+ result
+ fetch ();
+
+ void
+ free_result ();
+
+ private:
+ select_statement (const select_statement&);
+ select_statement& operator= (const select_statement&);
+
+ private:
+ bool end_;
+ std::size_t rows_;
+ };
+
+ class LIBODB_ORACLE_EXPORT insert_statement: public statement
+ {
+ public:
+ virtual
+ ~insert_statement ();
+
+ insert_statement (connection& conn,
+ const std::string& statement,
+ binding& data,
+ bool returning);
+
+ // Return true if successful and false if the row is a duplicate.
+ // All other errors are reported by throwing exceptions.
+ //
+ bool
+ execute ();
+
+ unsigned long long
+ id ();
+
+ private:
+ insert_statement (const insert_statement&);
+ insert_statement& operator= (const insert_statement&);
+
+ public:
+ struct id_bind_type
+ {
+ union
+ {
+ unsigned int int_;
+ unsigned long long long_long_;
+ } id;
+
+ sb2 ind;
+ };
+
+ private:
+ id_bind_type id_bind_;
+ };
+
+ class LIBODB_ORACLE_EXPORT update_statement: public statement
+ {
+ public:
+ virtual
+ ~update_statement ();
+
+ // Asssumes that cond.bind is a suffix of data.bind.
+ //
+ update_statement (connection& conn,
+ const std::string& statement,
+ binding& cond,
+ binding& data);
+ void
+ execute ();
+
+ private:
+ update_statement (const update_statement&);
+ update_statement& operator= (const update_statement&);
+ };
+
+ class LIBODB_ORACLE_EXPORT delete_statement: public statement
+ {
+ public:
+ virtual
+ ~delete_statement ();
+
+ delete_statement (connection& conn,
+ const std::string& statement,
+ binding& cond);
+
+ unsigned long long
+ execute ();
+
+ private:
+ delete_statement (const delete_statement&);
+ delete_statement& operator= (const delete_statement&);
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_ORACLE_STATEMENT_HXX