21 #define SQLITE_SERVER_VERSION "SQLite Server using libdrizzle 0.1"
23 #define DRIZZLE_RETURN_CHECK(__ret, __function, __drizzle) \
25 if ((__ret) != DRIZZLE_RETURN_OK) \
26 DRIZZLE_RETURN_ERROR(__function, __drizzle) \
29 #define DRIZZLE_RETURN_ERROR(__function, __drizzle) \
31 printf(__function ":%s\n", drizzle_error(__drizzle)); \
35 #define DRIZZLE_RETURN_CHECK_VAL(__ret, __function, __drizzle) \
37 if ((__ret) != DRIZZLE_RETURN_OK) \
39 printf(__function ":%s\n", drizzle_error(__drizzle)); \
57 static int row_cb(
void *data,
int field_count,
char **fields,
char **columns);
59 static void usage(
char *name);
61 int main(
int argc,
char *argv[])
65 const char *host= NULL;
75 while((c = getopt(argc, argv,
"c:h:mp:v")) != -1)
80 count= (uint32_t)atoi(optarg);
92 port= (in_port_t)atoi(optarg);
105 if (argc != (optind + 1))
111 sqlite3_open(argv[optind], &(server.
db));
112 if (server.
db == NULL)
114 printf(
"sqlite3_open: could not open sqlite3 db\n");
120 printf(
"drizzle_create:NULL\n");
129 printf(
"drizzle_con_create:NULL\n");
169 sqlite3_close(server.
db);
188 (
const uint8_t *)
"ABCDEFGHIJKLMNOPQRST");
226 printf(
"Command=%u Data=%s\n", command,
227 data == NULL ?
"NULL" : (
char *)data);
234 !strcasecmp((
char *)data,
"SHOW DATABASES"))
249 if (strstr((
char *)data,
"@@version") != NULL)
261 if (!strcasecmp((
char *)data,
"SHOW TABLES"))
263 sqlite_ret= sqlite3_exec(server->
db,
264 "SELECT name FROM sqlite_master WHERE type='table'",
265 row_cb, server, &sqlite_err);
269 sqlite_ret= sqlite3_exec(server->
db, (
char *)data,
row_cb, server,
273 if (sqlite_ret != SQLITE_OK)
275 if (sqlite_err == NULL)
276 printf(
"sqlite3_exec failed\n");
284 printf(
"sqlite3_exec:%s\n", sqlite_err);
285 sqlite3_free(sqlite_err);
291 if (server->
rows == 0)
306 static int row_cb(
void *data,
int field_count,
char **fields,
char **columns)
334 for (x= 0; x < field_count; x++)
338 0 : (uint32_t)strlen(fields[x]));
354 for (x= 0; x < field_count; x++)
356 if (fields[x] == NULL)
359 sizes[x]= strlen(fields[x]);
369 for (x= 0; x < field_count; x++)
438 printf(
"\nusage: %s [-c <count>] [-h <host>] [-m] [-p <port>] [-v] "
439 "<sqlite3 db file>\n", name);
440 printf(
"\t-c <count> - Number of connections to accept before exiting\n");
441 printf(
"\t-h <host> - Host to listen on\n");
442 printf(
"\t-m - Use the MySQL protocol\n");
443 printf(
"\t-p <port> - Port to listen on\n");
444 printf(
"\t-v - Increase verbosity level\n");