diff --git a/src/backends/mysql/session.cpp b/src/backends/mysql/session.cpp index c469469f0..9cea6776e 100644 --- a/src/backends/mysql/session.cpp +++ b/src/backends/mysql/session.cpp @@ -154,7 +154,8 @@ void parse_connect_string(const string & connectString, string *db, bool *db_p, string *unix_socket, bool *unix_socket_p, int *port, bool *port_p, string *ssl_ca, bool *ssl_ca_p, - string *ssl_cert, bool *ssl_cert_p, string *ssl_key, bool *ssl_key_p) + string *ssl_cert, bool *ssl_cert_p, string *ssl_key, bool *ssl_key_p, + int *local_infile, bool *local_infile_p) { *host_p = false; *user_p = false; @@ -165,6 +166,7 @@ void parse_connect_string(const string & connectString, *ssl_ca_p = false; *ssl_cert_p = false; *ssl_key_p = false; + *local_infile_p = false; string err = "Malformed connection string."; string::const_iterator i = connectString.begin(), end = connectString.end(); @@ -240,6 +242,19 @@ void parse_connect_string(const string & connectString, *ssl_key = val; *ssl_key_p = true; } + else if (par == "local_infile" and not *local_infile_p) + { + if (not valid_int(val)) + { + throw soci_error(err); + } + *local_infile = std::atoi(val.c_str()); + if (*local_infile != 0 and *local_infile != 1) + { + throw soci_error(err); + } + *local_infile_p = true; + } else { throw soci_error(err); @@ -253,19 +268,33 @@ mysql_session_backend::mysql_session_backend( std::string const & connectString) { string host, user, password, db, unix_socket, ssl_ca, ssl_cert, ssl_key; - int port; - bool host_p, user_p, password_p, db_p, unix_socket_p, port_p, ssl_ca_p, ssl_cert_p, ssl_key_p; + int port, local_infile; + bool host_p, user_p, password_p, db_p, unix_socket_p, port_p, + ssl_ca_p, ssl_cert_p, ssl_key_p, local_infile_p; parse_connect_string(connectString, &host, &host_p, &user, &user_p, &password, &password_p, &db, &db_p, - &unix_socket, &unix_socket_p, &port, &port_p, &ssl_ca, &ssl_ca_p, &ssl_cert, &ssl_cert_p, &ssl_key, &ssl_key_p); + &unix_socket, &unix_socket_p, &port, &port_p, + &ssl_ca, &ssl_ca_p, &ssl_cert, &ssl_cert_p, &ssl_key, &ssl_key_p, + &local_infile, &local_infile_p); conn_ = mysql_init(NULL); if (conn_ == NULL) { throw soci_error("mysql_init() failed."); } - if(ssl_ca_p) + if (ssl_ca_p) + { + mysql_ssl_set(conn_, ssl_key_p ? ssl_key.c_str() : NULL, + ssl_cert_p ? ssl_cert.c_str() : NULL, + ssl_ca_p ? ssl_ca.c_str() : NULL, 0, 0); + } + if (local_infile_p and local_infile == 1) { - mysql_ssl_set(conn_, ssl_key_p ? ssl_key.c_str() : NULL, ssl_cert_p ? ssl_cert.c_str() : NULL, ssl_ca_p ? ssl_ca.c_str() : NULL, 0, 0); + if (0 != mysql_options(conn_, MYSQL_OPT_LOCAL_INFILE, NULL)) + { + clean_up(); + throw soci_error( + "mysql_options() failed when trying to set local-infile."); + } } if (mysql_real_connect(conn_, host_p ? host.c_str() : NULL,