Created
March 7, 2016 15:40
-
-
Save vyskocilm/6a6a2fe42ca7327f7d1d to your computer and use it in GitHub Desktop.
PoC of using embeded mariadb with tntnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <mysql/mysql.h> | |
#include <tntdb.h> | |
// g++ -ggdb -std=c++11 test.cc -ltntdb -lcxxtools -lmysqld | |
static char *server_args[] = { | |
"this_program", /* this string is not used */ | |
"--datadir=./__db__", | |
"--key_buffer_size=32M" | |
}; | |
static char *server_groups[] = { | |
"embedded", | |
"server", | |
"this_program_SERVER", | |
(char *)NULL | |
}; | |
int main (int argc, char** argv) { | |
bool run_embeded = false; | |
if (argc == 2) { | |
run_embeded = !strcmp (argv[1], "embeded"); | |
} | |
if (run_embeded) | |
fprintf (stderr, "EMBEDED\n"); | |
else | |
fprintf (stderr, "NOT EMBEDED\n"); | |
if (run_embeded) | |
{ | |
if (mysql_library_init(sizeof (server_args) / sizeof (char*), server_args, server_groups)) { | |
fprintf(stderr, "could not initialize MySQL library\n"); | |
exit(1); | |
} | |
} | |
static const char* url = "mysql:db=box_utf8;user=root"; | |
tntdb::Connection conn = tntdb::connectCached (url); | |
auto row = conn.selectRow ("SELECT COUNT(*) FROM t_SECRET_TABLE"); | |
size_t ret_get0; | |
row[0].get (ret_get0); | |
std::cout << "count" << ret_get0 << std::endl; | |
if (run_embeded) | |
mysql_library_end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment