aboutsummaryrefslogtreecommitdiff
path: root/odb/mssql/database.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-11-18 14:54:27 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-11-18 14:54:27 +0200
commite075f77af3a09c22a8bec660c69c9fa7a9808d8e (patch)
treef6aded862398269756ecdb96ac1198943ade8a4d /odb/mssql/database.hxx
parenta46dd03b3003b5e3bf87051ea49cea3d2f6848a8 (diff)
Implement remaining database constructors, update options
Diffstat (limited to 'odb/mssql/database.hxx')
-rw-r--r--odb/mssql/database.hxx126
1 files changed, 97 insertions, 29 deletions
diff --git a/odb/mssql/database.hxx b/odb/mssql/database.hxx
index d20d860..cabdbb4 100644
--- a/odb/mssql/database.hxx
+++ b/odb/mssql/database.hxx
@@ -32,35 +32,82 @@ namespace odb
{
class transaction_impl;
+ enum protocol
+ {
+ protocol_auto,
+ protocol_tcp, // TCP/IP.
+ protocol_lpc, // Shared memory (local procedure call).
+ protocol_np // Named pipes.
+ };
+
class LIBODB_MSSQL_EXPORT database: public odb::database
{
public:
- database (const std::string& connect_string,
+ typedef mssql::protocol protocol_type;
+
+ // Connect to the specified server using the latest available SQL
+ // Server Native Client ODBC driver by default. If user is empty,
+ // then use Windows authentication. If database is empty, then
+ // use the default database for this user.
+ //
+ database (const std::string& user,
+ const std::string& password,
+ const std::string& db,
+ const std::string& server,
+ const std::string& driver = "",
+ const std::string& extra_connect_string = "",
SQLHENV environment = 0,
std::auto_ptr<connection_factory> factory =
std::auto_ptr<connection_factory> (0));
- /*
+ // By default connect to the default instance on localhost using
+ // default protocol and the latest available SQL Server Native
+ // Client ODBC driver. If user is empty, then use Windows
+ // authentication. If database is empty, then use the default
+ // database for this user.
+ //
database (const std::string& user,
const std::string& password,
- const std::string& service,
+ const std::string& db,
+ protocol_type protocol = protocol_auto,
const std::string& host = "",
- unsigned int port = 0,
- ub2 charset = 0,
- ub2 ncharset = 0,
- OCIEnv* environment = 0,
+ const std::string& instance = "",
+ const std::string& driver = "",
+ const std::string& extra_connect_string = "",
+ SQLHENV environment = 0,
+ std::auto_ptr<connection_factory> factory =
+ std::auto_ptr<connection_factory> (0));
+
+ // Connect using TCP/IP to the specified host and port. If port is
+ // 0, use the default port (1433).
+ //
+ database (const std::string& user,
+ const std::string& password,
+ const std::string& db,
+ const std::string& host,
+ unsigned int port,
+ const std::string& driver = "",
+ const std::string& extra_connect_string = "",
+ SQLHENV environment = 0,
+ std::auto_ptr<connection_factory> factory =
+ std::auto_ptr<connection_factory> (0));
+
+ // Connect using a custom SQL Server Native Client ODBC driver
+ // conection string.
+ //
+ database (const std::string& connect_string,
+ SQLHENV environment = 0,
std::auto_ptr<connection_factory> factory =
std::auto_ptr<connection_factory> (0));
// Extract the database parameters from the command line. The
// following options are recognized:
//
- // --user
- // --password
- // --database
- // --service
- // --host
- // --port
+ // --user | -U
+ // --password | -P
+ // --database | -d
+ // --server | -S
+ // --driver
// --options-file
//
// For more information, see the output of the print_usage() function
@@ -68,11 +115,10 @@ namespace odb
// argv array and the argc count is updated accordingly. This
// constructor may throw the cli_exception exception.
//
- */
-
database (int& argc,
char* argv[],
bool erase = false,
+ const std::string& extra_connect_string = "",
SQLHENV environment = 0,
std::auto_ptr<connection_factory> =
std::auto_ptr<connection_factory> (0));
@@ -90,7 +136,6 @@ namespace odb
connection ();
public:
- /*
const std::string&
user () const
{
@@ -109,10 +154,10 @@ namespace odb
return db_;
}
- const std::string&
- service () const
+ protocol_type
+ protocol () const
{
- return service_;
+ return protocol_;
}
const std::string&
@@ -121,12 +166,35 @@ namespace odb
return host_;
}
+ const std::string&
+ instance () const
+ {
+ return instance_;
+ }
+
unsigned int
port () const
{
return port_;
}
- */
+
+ const std::string&
+ server () const
+ {
+ return server_;
+ }
+
+ const std::string&
+ driver () const
+ {
+ return driver_;
+ }
+
+ const std::string&
+ extra_connect_string () const
+ {
+ return extra_connect_string_;
+ }
const std::string&
connect_string () const
@@ -170,20 +238,20 @@ namespace odb
connection_ ();
private:
- /*
+ void
+ init ();
+
+ private:
std::string user_;
std::string password_;
-
std::string db_;
-
- std::string service_;
+ protocol_type protocol_;
std::string host_;
+ std::string instance_;
unsigned int port_;
-
- ub2 charset_;
- ub2 ncharset_;
- */
-
+ std::string server_;
+ std::string driver_;
+ std::string extra_connect_string_;
std::string connect_string_;
auto_handle<SQL_HANDLE_ENV> auto_environment_;