From e075f77af3a09c22a8bec660c69c9fa7a9808d8e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 18 Nov 2011 14:54:27 +0200 Subject: Implement remaining database constructors, update options --- odb/mssql/database.hxx | 126 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 97 insertions(+), 29 deletions(-) (limited to 'odb/mssql/database.hxx') 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 factory = std::auto_ptr (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 factory = + std::auto_ptr (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 factory = + std::auto_ptr (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 factory = std::auto_ptr (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 = std::auto_ptr (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 auto_environment_; -- cgit v1.1