connectioninfo.H 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #define BENCHMARK_DB_HOST "tfb-database"
  2. #define MYSQL_MAX_CONNECTIONS 3000
  3. #include <stdexcept>
  4. using namespace std;
  5. #ifdef _mysql_h
  6. MYSQL* doConnect(void*) {
  7. //printf("doConnect()\n");
  8. MYSQL* tmp=mysql_init(NULL);
  9. if(tmp==NULL) throw bad_alloc();
  10. if (mysql_real_connect(tmp, BENCHMARK_DB_HOST,
  11. "benchmarkdbuser", "benchmarkdbpass", "hello_world", 0, NULL, 0) == NULL) {
  12. string s(mysql_error(tmp));
  13. mysql_close(tmp);
  14. throw runtime_error(s);
  15. }
  16. mysql_set_character_set(tmp, "utf8");
  17. mysql_options(tmp, MYSQL_SET_CHARSET_NAME, "utf8");
  18. return tmp;
  19. }
  20. void doDisconnect(void*,MYSQL* conn) {
  21. mysql_close(conn);
  22. }
  23. #endif
  24. #ifdef LIBPQ_FE_H
  25. PGconn* doConnect_pg(void*) {
  26. //printf("doConnect_pg()\n");
  27. const char* connString="host='" BENCHMARK_DB_HOST
  28. "' user='benchmarkdbuser' password='benchmarkdbpass' dbname='hello_world' sslmode='allow'";
  29. PGconn* conn;
  30. conn = PQconnectdb(connString);
  31. if(conn==NULL) throw bad_alloc();
  32. if (PQstatus(conn) != CONNECTION_OK)
  33. {
  34. string err=PQerrorMessage(conn);
  35. PQfinish(conn);
  36. throw runtime_error(err);
  37. }
  38. return conn;
  39. }
  40. void doDisconnect_pg(void*,PGconn* conn) {
  41. PQfinish(conn);
  42. }
  43. #endif