Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DbConnector::DbConnector(const ns4__ServerHostResponse &response)
- {
- try
- {
- driver = get_driver_instance();
- conn.reset(
- driver->connect(boost::str(boost::format("tcp://%1%:3306") % response.DatabaseHostName), response.Username, response.Password));
- conn->setSchema(response.DbSchema);
- query << "";
- }
- catch(std::exception &ex)
- {
- throw CustomException(boost::str(boost::format("Unable to connect to database: %1%") % response.DbSchema), ex.what());
- }
- catch(...)
- {
- throw StokedTcpException(boost::str(boost::format("Unable to connect to database: %1%") % response.DbSchema));
- }
- }
- void DbConnector::EscapeString(std::string &s) {
- if (conn)
- {
- std::shared_ptr<sql::mysql::MySQL_Connection> mysqlConn(dynamic_cast<sql::mysql::MySQL_Connection*>(conn.get()));
- if (mysqlConn)
- s = mysqlConn->escapeString(s);
- else
- throw CustomException("Cannot allocate connection object to escape mysql string!");
- }
- #include <mysql_connection.h>
- /usr/include/mysql_connection.h
- sql::mysql::MySQL_Connection * mysql_conn = dynamic_cast<sql::mysql::MySQL_Connection*>(con);
- std::string escaped = mysql_conn->escapeString( query );
- stmt->execute( escaped );
Add Comment
Please, Sign In to add comment