17 #pragma warning(disable:4355) 28 void execude_hardcoded(
sqlite_api::sqlite3* conn,
char const*
const query,
char const*
const errMsg)
31 int const res = sqlite3_exec(conn, query, 0, 0, &zErrMsg);
34 std::ostringstream ss;
35 ss << errMsg <<
" " << zErrMsg;
36 sqlite3_free(zErrMsg);
45 const char *zErrMsg = sqlite3_errmsg(conn);
46 std::ostringstream ss;
47 ss << errMsg << zErrMsg;
59 int connection_flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
60 std::string synchronous;
62 std::string dbname(connectString);
63 std::stringstream ssconn(connectString);
64 while (!ssconn.eof() && ssconn.str().find(
'=') != std::string::npos)
67 std::getline(ssconn, key,
'=');
68 std::getline(ssconn, val,
' ');
70 if (val.size()>0 && val[0]==
'\"')
72 std::string quotedVal = val.erase(0, 1);
74 if (quotedVal[quotedVal.size()-1] ==
'\"')
76 quotedVal.erase(val.size()-1);
80 std::getline(ssconn, val,
'\"');
81 quotedVal = quotedVal +
" " + val;
82 std::string keepspace;
83 std::getline(ssconn, keepspace,
' ');
89 if (
"dbname" == key ||
"db" == key)
93 else if (
"timeout" == key)
95 std::istringstream converter(val);
98 else if (
"synchronous" == key)
102 else if (
"shared_cache" == key &&
"true" == val)
104 connection_flags |= SQLITE_OPEN_SHAREDCACHE;
108 int res = sqlite3_open_v2(dbname.c_str(), &conn_, connection_flags, NULL);
109 check_sqlite_err(conn_, res,
"Cannot establish connection to the database. ");
111 if (!synchronous.empty())
113 std::string
const query(
"pragma synchronous=" + synchronous);
114 std::string
const errMsg(
"Query failed: " + query);
115 execude_hardcoded(conn_, query.c_str(), errMsg.c_str());
118 res = sqlite3_busy_timeout(conn_, timeout * 1000);
119 check_sqlite_err(conn_, res,
"Failed to set busy timeout for connection. ");
130 execude_hardcoded(conn_,
"BEGIN",
"Cannot begin transaction.");
135 execude_hardcoded(conn_,
"COMMIT",
"Cannot commit transaction.");
140 execude_hardcoded(conn_,
"ROLLBACK",
"Cannot rollback transaction.");
145 sqlite3_close(conn_);
virtual sqlite3_statement_backend * make_statement_backend()
virtual sqlite3_blob_backend * make_blob_backend()
SOCI_SQLITE3_DECL sqlite3_backend_factory const sqlite3
~sqlite3_session_backend()
std::string const & get_connect_string() const
std::string connectString
std::vector< ISM::CombinatorialTrainerParameters > parameters
sqlite3_session_backend(connection_parameters const ¶meters)
virtual sqlite3_rowid_backend * make_rowid_backend()