mysql_connection.cc 655 B

12345678910111213141516171819202122
  1. #include <stdio.h>
  2. #include <zdb.h>
  3. #include "common.h"
  4. #include "mysql_connection.h"
  5. #include <string>
  6. std::string MySQLConnection::executeQuery(const char* query)
  7. {
  8. URL_T url = URL_new(("mysql://" + user + ":" + password + "@" + host + ":3306/" + database).c_str());
  9. ConnectionPool_T pool = ConnectionPool_new(url);
  10. ConnectionPool_start(pool);
  11. Connection_T con = ConnectionPool_getConnection(pool);
  12. ResultSet_T r = Connection_executeQuery(con, query);
  13. std::string result = ResultSet_next(r) ? ResultSet_getString(r, 1) : "";
  14. Connection_close(con);
  15. ConnectionPool_free(&pool);
  16. URL_free(&url);
  17. return result;
  18. }