Guest User

Untitled

a guest
Nov 16th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. DbConnector::DbConnector(const ns4__ServerHostResponse &response)
  2. {
  3. try
  4. {
  5. driver = get_driver_instance();
  6. conn.reset(
  7. driver->connect(boost::str(boost::format("tcp://%1%:3306") % response.DatabaseHostName), response.Username, response.Password));
  8. conn->setSchema(response.DbSchema);
  9. query << "";
  10.  
  11. }
  12. catch(std::exception &ex)
  13. {
  14. throw CustomException(boost::str(boost::format("Unable to connect to database: %1%") % response.DbSchema), ex.what());
  15. }
  16. catch(...)
  17. {
  18. throw StokedTcpException(boost::str(boost::format("Unable to connect to database: %1%") % response.DbSchema));
  19. }
  20. }
  21.  
  22. void DbConnector::EscapeString(std::string &s) {
  23. if (conn)
  24. {
  25. std::shared_ptr<sql::mysql::MySQL_Connection> mysqlConn(dynamic_cast<sql::mysql::MySQL_Connection*>(conn.get()));
  26. if (mysqlConn)
  27. s = mysqlConn->escapeString(s);
  28. else
  29. throw CustomException("Cannot allocate connection object to escape mysql string!");
  30. }
  31.  
  32. #include <mysql_connection.h>
  33.  
  34. /usr/include/mysql_connection.h
  35.  
  36. sql::mysql::MySQL_Connection * mysql_conn = dynamic_cast<sql::mysql::MySQL_Connection*>(con);
  37. std::string escaped = mysql_conn->escapeString( query );
  38. stmt->execute( escaped );
Add Comment
Please, Sign In to add comment