aboutsummaryrefslogtreecommitdiff
path: root/odb/mssql/database.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-11-17 08:44:01 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-11-17 08:44:01 +0200
commit00d972abb9dcbe7c99cd9b94cefc725024cfb4bc (patch)
tree95ad5e69205d4222f9ab34ca041fcfa78cc9b997 /odb/mssql/database.cxx
parentbc85d6a1c8d5296428c121cd1b51d470d5c0e963 (diff)
Add initial database class implementation
Diffstat (limited to 'odb/mssql/database.cxx')
-rw-r--r--odb/mssql/database.cxx246
1 files changed, 246 insertions, 0 deletions
diff --git a/odb/mssql/database.cxx b/odb/mssql/database.cxx
new file mode 100644
index 0000000..b6ef146
--- /dev/null
+++ b/odb/mssql/database.cxx
@@ -0,0 +1,246 @@
+// file : odb/mssql/database.cxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : ODB NCUEL; see accompanying LICENSE file
+
+//@@ disabled functionality
+
+#include <sstream>
+
+#include <odb/mssql/odbc.hxx>
+#include <odb/mssql/database.hxx>
+#include <odb/mssql/exceptions.hxx>
+#include <odb/mssql/error.hxx>
+
+#include <odb/mssql/details/options.hxx>
+
+using namespace std;
+
+namespace odb
+{
+ namespace mssql
+ {
+ database::
+ database (const string& c, SQLHENV e, auto_ptr<connection_factory> f)
+ : connect_string_ (c), environment_ (e), factory_ (f)
+ {
+ if (environment_ == 0)
+ {
+ SQLRETURN r (
+ SQLAllocHandle (SQL_HANDLE_ENV,
+ SQL_NULL_HANDLE,
+ &environment_));
+
+ if (!SQL_SUCCEEDED (r))
+ throw database_exception (
+ 0, "?????", "unable to allocate environment handle");
+
+ auto_environment_.reset (environment_);
+
+ // Set ODBC version.
+ //
+ r = SQLSetEnvAttr (environment_,
+ SQL_ATTR_ODBC_VERSION,
+ (SQLPOINTER) SQL_OV_ODBC3,
+ 0);
+
+ if (!SQL_SUCCEEDED (r))
+ translate_error (environment_, SQL_HANDLE_ENV);
+ }
+ }
+
+ /*
+ database::
+ database (const string& user,
+ const string& password,
+ const string& service,
+ const string& host,
+ unsigned int port,
+ ub2 charset,
+ ub2 ncharset,
+ OCIEnv* environment,
+ auto_ptr<connection_factory> factory)
+ : user_ (user),
+ password_ (password),
+ service_ (service),
+ host_ (host),
+ port_ (port),
+ charset_ (charset),
+ ncharset_ (ncharset),
+ environment_ (environment),
+ factory_ (factory)
+ {
+ if (environment_ == 0)
+ {
+ sword s (OCIEnvNlsCreate (&environment_,
+ OCI_THREADED,
+ 0, 0, 0, 0, 0, 0,
+ charset,
+ ncharset));
+
+ if (s == OCI_ERROR)
+ translate_error (environment_);
+
+ auto_environment_.reset (environment_);
+ }
+
+ ostringstream ss;
+
+ if (!host.empty ())
+ {
+ ss << "//" << host_;
+
+ if (port != 0)
+ ss << ":" << port;
+ }
+
+ if (!service_.empty ())
+ {
+ if (!host.empty ())
+ ss << "/" << service_;
+ else
+ ss << service_;
+ }
+
+ // @@ Quote FQ connect identifier.
+ //
+ db_ = ss.str ();
+
+ if (factory_.get () == 0)
+ factory_.reset (new connection_pool_factory ());
+
+ factory_->database (*this);
+ }
+ */
+
+ /*
+ database::
+ database (int& argc,
+ char* argv[],
+ bool erase,
+ ub2 charset,
+ ub2 ncharset,
+ OCIEnv* environment,
+ auto_ptr<connection_factory> factory)
+ : port_ (0),
+ charset_ (charset),
+ ncharset_ (ncharset),
+ environment_ (environment),
+ factory_ (factory)
+ {
+ if (environment_ == 0)
+ {
+ sword s (OCIEnvNlsCreate (&environment_,
+ OCI_THREADED,
+ 0, 0, 0, 0, 0, 0,
+ charset,
+ ncharset));
+
+ if (s == OCI_ERROR)
+ translate_error (environment_);
+
+ auto_environment_.reset (environment_);
+ }
+
+ using namespace details;
+
+ try
+ {
+ cli::argv_file_scanner scan (argc, argv, "--options-file", erase);
+ options ops (scan, cli::unknown_mode::skip, cli::unknown_mode::skip);
+
+ if (ops.user_specified ())
+ user_ = ops.user ();
+
+ if (ops.password_specified ())
+ password_ = ops.password ();
+
+ if (ops.database_specified ())
+ {
+ if (ops.host_specified () ||
+ ops.port_specified () ||
+ ops.service_specified ())
+
+ throw cli_exception ("--host, --port, or --service options "
+ "cannot be specified together with "
+ "--database option");
+ db_ = ops.database ();
+ }
+ else
+ {
+ bool host_present (false);
+ ostringstream oss;
+
+ if (ops.host_specified () && !ops.host ().empty ())
+ {
+ host_present = true;
+
+ host_ = ops.host ();
+ oss << "//" << host_;
+
+ if (ops.port_specified ())
+ {
+ port_ = ops.port ();
+
+ if (port_ != 0)
+ oss << ":" << port_;
+ }
+ }
+
+ if (ops.service_specified () && !ops.service ().empty ())
+ {
+ service_ = ops.service ();
+
+ if (host_present)
+ oss << "/" << service_;
+ else
+ oss << service_;
+ }
+
+ db_ = oss.str ();
+ }
+
+ // @@ Quote FQ connect identifier.
+ //
+ }
+ catch (const cli::exception& e)
+ {
+ ostringstream oss;
+ oss << e;
+ throw cli_exception (oss.str ());
+ }
+
+ if (factory_.get () == 0)
+ factory_.reset (new connection_pool_factory ());
+
+ factory_->database (*this);
+ }
+ */
+
+ void database::
+ print_usage (std::ostream& os)
+ {
+ details::options::print_usage (os);
+ }
+
+ database::
+ ~database ()
+ {
+ }
+
+ /*
+ transaction_impl* database::
+ begin ()
+ {
+ return new transaction_impl (*this);
+ }
+
+ odb::connection* database::
+ connection_ ()
+ {
+ connection_ptr c (factory_->connect ());
+ return c.release ();
+ }
+ */
+ }
+}