9 #define SOCI_MYSQL_SOURCE 22 #pragma warning(disable:4355) 33 void skip_white(std::string::const_iterator *i,
34 std::string::const_iterator
const & end,
bool endok)
46 throw soci_error(
"Unexpected end of connection string.");
49 if (std::isspace(**i))
60 std::string param_name(std::string::const_iterator *i,
61 std::string::const_iterator
const & end)
66 if (*i == end or (not std::isalpha(**i) and **i !=
'_'))
76 string param_value(string::const_iterator *i,
77 string::const_iterator
const & end)
79 string err =
"Malformed connection string.";
116 if (not quot and std::isspace(**i))
134 bool valid_int(
const string & s)
137 const char *cstr = s.c_str();
139 long n = std::strtol(cstr, &tail, 10);
140 if (errno != 0 or n > INT_MAX or n < INT_MIN)
152 string *host,
bool *host_p,
153 string *user,
bool *user_p,
154 string *password,
bool *password_p,
155 string *db,
bool *db_p,
156 string *unix_socket,
bool *unix_socket_p,
157 int *port,
bool *port_p,
string *ssl_ca,
bool *ssl_ca_p,
158 string *ssl_cert,
bool *ssl_cert_p,
string *ssl_key,
bool *ssl_key_p,
159 int *local_infile,
bool *local_infile_p,
160 string *charset,
bool *charset_p)
166 *unix_socket_p =
false;
171 *local_infile_p =
false;
173 string err =
"Malformed connection string.";
174 string::const_iterator i = connectString.begin(),
175 end = connectString.end();
178 skip_white(&i, end,
true);
183 string par = param_name(&i, end);
184 skip_white(&i, end,
false);
193 skip_white(&i, end,
false);
194 string val = param_value(&i, end);
195 if (par ==
"port" and not *port_p)
197 if (not valid_int(val))
201 *port = std::atoi(val.c_str());
208 else if (par ==
"host" and not *host_p)
213 else if (par ==
"user" and not *user_p)
218 else if ((par ==
"pass" or par ==
"password") and not *password_p)
223 else if ((par ==
"db" or par ==
"dbname" or par ==
"service") and
229 else if (par ==
"unix_socket" and not *unix_socket_p)
232 *unix_socket_p =
true;
234 else if (par ==
"sslca" and not *ssl_ca_p)
239 else if (par ==
"sslcert" and not *ssl_cert_p)
244 else if (par ==
"sslkey" and not *ssl_key_p)
249 else if (par ==
"local_infile" and not *local_infile_p)
251 if (not valid_int(val))
255 *local_infile = std::atoi(val.c_str());
256 if (*local_infile != 0 and *local_infile != 1)
260 *local_infile_p =
true;
261 }
else if (par ==
"charset" and not *charset_p)
278 string host, user, password, db, unix_socket, ssl_ca, ssl_cert, ssl_key,
280 int port, local_infile;
281 bool host_p, user_p, password_p, db_p, unix_socket_p, port_p,
282 ssl_ca_p, ssl_cert_p, ssl_key_p, local_infile_p, charset_p;
284 &password, &password_p, &db, &db_p,
285 &unix_socket, &unix_socket_p, &port, &port_p,
286 &ssl_ca, &ssl_ca_p, &ssl_cert, &ssl_cert_p, &ssl_key, &ssl_key_p,
287 &local_infile, &local_infile_p, &charset, &charset_p);
288 conn_ = mysql_init(NULL);
295 if (0 != mysql_options(conn_, MYSQL_SET_CHARSET_NAME, charset.c_str()))
298 throw soci_error(
"mysql_options(MYSQL_SET_CHARSET_NAME) failed.");
303 mysql_ssl_set(conn_, ssl_key_p ? ssl_key.c_str() : NULL,
304 ssl_cert_p ? ssl_cert.c_str() : NULL,
305 ssl_ca_p ? ssl_ca.c_str() : NULL, 0, 0);
307 if (local_infile_p and local_infile == 1)
309 if (0 != mysql_options(conn_, MYSQL_OPT_LOCAL_INFILE, NULL))
313 "mysql_options() failed when trying to set local-infile.");
316 if (mysql_real_connect(conn_,
317 host_p ? host.c_str() : NULL,
318 user_p ? user.c_str() : NULL,
319 password_p ? password.c_str() : NULL,
320 db_p ? db.c_str() : NULL,
322 unix_socket_p ? unix_socket.c_str() : NULL,
323 #ifdef CLIENT_MULTI_RESULTS 324 CLIENT_FOUND_ROWS | CLIENT_MULTI_RESULTS) == NULL)
326 CLIENT_FOUND_ROWS) == NULL)
329 string errMsg = mysql_error(conn_);
330 unsigned int errNum = mysql_errno(conn_);
345 void hard_exec(MYSQL *conn,
const string & query)
347 if (0 != mysql_real_query(conn, query.c_str(),
348 static_cast<unsigned long>(query.size())))
358 hard_exec(conn_,
"BEGIN");
363 hard_exec(conn_,
"COMMIT");
368 hard_exec(conn_,
"ROLLBACK");
virtual mysql_statement_backend * make_statement_backend()
virtual mysql_rowid_backend * make_rowid_backend()
std::string const & get_connect_string() const
virtual mysql_blob_backend * make_blob_backend()
std::string connectString
std::vector< ISM::CombinatorialTrainerParameters > parameters
mysql_session_backend(connection_parameters const ¶meters)