8 #define SOCI_ODBC_SOURCE 21 : henv_(0), hdbc_(0), product_(prod_uninitialized)
26 rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &
henv_);
29 throw soci_error(
"Unable to get environment handle");
33 rc = SQLSetEnvAttr(
henv_, SQL_ATTR_ODBC_VERSION, (
void*)SQL_OV_ODBC3, 0);
37 "Setting ODBC version");
41 rc = SQLAllocHandle(SQL_HANDLE_DBC,
henv_, &
hdbc_);
45 "Allocating connection handle");
48 SQLCHAR outConnString[1024];
49 SQLSMALLINT strLength;
54 SQLHWND hwnd_for_prompt = NULL;
55 unsigned completion = SQL_DRIVER_COMPLETE;
56 std::string completionString;
63 if (std::sscanf(completionString.c_str(),
"%u", &completion) != 1)
65 throw soci_error(
"Invalid non-numeric driver completion option value \"" +
66 completionString +
"\".");
71 if (completion != SQL_DRIVER_NOPROMPT)
72 hwnd_for_prompt = ::GetDesktopWindow();
76 rc = SQLDriverConnect(
hdbc_, hwnd_for_prompt,
77 (SQLCHAR *)connectString.c_str(),
78 (SQLSMALLINT)connectString.size(),
79 outConnString, 1024, &strLength,
80 static_cast<SQLUSMALLINT
>(completion));
85 "Error Connecting to database");
100 SQLRETURN rc = SQLSetConnectAttr(
hdbc_, SQL_ATTR_AUTOCOMMIT,
101 (SQLPOINTER)SQL_AUTOCOMMIT_OFF, 0 );
105 "Begin Transaction");
111 SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC,
hdbc_, SQL_COMMIT);
122 SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC,
hdbc_, SQL_ROLLBACK);
132 session & s, std::string
const & sequence,
long & value)
139 query =
"select next value for " + sequence +
" from rdb$database";
143 query =
"select " + sequence +
".nextval from dual";
147 query =
"select nextval('" + sequence +
"')";
167 s << query,
into(value);
173 session & s, std::string
const & table,
long & value)
180 query =
"select ident_current('" + table +
"')";
184 query =
"select last_insert_id()";
188 query =
"select last_insert_rowid()";
208 s << query,
into(value);
215 SQLRETURN rc = SQLSetConnectAttr(
hdbc_, SQL_ATTR_AUTOCOMMIT,
216 (SQLPOINTER)SQL_AUTOCOMMIT_ON, 0 );
227 SQLRETURN rc = SQLDisconnect(
hdbc_);
234 rc = SQLFreeHandle(SQL_HANDLE_DBC,
hdbc_);
238 "SQLFreeHandle DBC");
241 rc = SQLFreeHandle(SQL_HANDLE_ENV,
henv_);
245 "SQLFreeHandle ENV");
271 char product_name[1024];
272 SQLSMALLINT len =
sizeof(product_name);
273 SQLRETURN rc = SQLGetInfo(
hdbc_, SQL_DBMS_NAME, product_name, len, &len);
277 "SQLGetInfo(SQL_DBMS_NAME)");
280 if (strcmp(product_name,
"Firebird") == 0)
282 else if (strcmp(product_name,
"Microsoft SQL Server") == 0)
284 else if (strcmp(product_name,
"MySQL") == 0)
286 else if (strcmp(product_name,
"Oracle") == 0)
288 else if (strcmp(product_name,
"PostgreSQL") == 0)
290 else if (strcmp(product_name,
"SQLite") == 0)
details::into_container< T, details::no_indicator > into(T &t)
virtual odbc_blob_backend * make_blob_backend()
database_product product_
virtual odbc_statement_backend * make_statement_backend()
odbc_session_backend(connection_parameters const ¶meters)
bool is_odbc_error(SQLRETURN rc)
std::string const & get_connect_string() const
SOCI_ODBC_DECL char const * odbc_option_driver_complete
virtual odbc_rowid_backend * make_rowid_backend()
std::string connection_string_
database_product get_database_product()
std::string connectString
virtual bool get_next_sequence_value(session &s, std::string const &sequence, long &value)
virtual bool get_last_insert_id(session &s, std::string const &table, long &value)
std::vector< ISM::CombinatorialTrainerParameters > parameters
bool get_option(const char *name, std::string &value) const