159
159
sqlite3_open(argv[optind], &(server->db));
160
160
if (server->db == NULL)
162
printf("sqlite3_open: could not open sqlite3 db\n");
166
if (drizzle_create(&(server->drizzle)) == NULL)
168
printf("drizzle_create:NULL\n");
172
drizzle_add_options(&(server->drizzle), DRIZZLE_FREE_OBJECTS);
173
drizzle_set_verbose(&(server->drizzle), server->verbose);
175
if (drizzle_con_create(&(server->drizzle), con_listen) == NULL)
177
printf("drizzle_con_create:NULL\n");
162
fprintf(stderr, "sqlite3_open: could not open sqlite3 db\n");
166
if ((server->drizzle= drizzle_create()) == NULL)
168
fprintf(stderr, "drizzle_create:NULL\n");
172
drizzle_add_options(server->drizzle, DRIZZLE_FREE_OBJECTS);
173
drizzle_set_verbose(server->drizzle, server->verbose);
175
if (drizzle_con_create(server->drizzle, con_listen) == NULL)
177
fprintf(stderr, "drizzle_con_create:NULL\n");
187
187
if (drizzle_con_listen(con_listen) != DRIZZLE_RETURN_OK)
189
printf("drizzle_con_listen:%s\n", drizzle_error(&(server->drizzle)));
189
fprintf(stderr, "drizzle_con_listen:%s\n", drizzle_error(server->drizzle));
195
(void)drizzle_con_accept(&(server->drizzle), &(server->con), &ret);
195
(void)drizzle_con_accept(server->drizzle, &(server->con), &ret);
196
196
if (ret != DRIZZLE_RETURN_OK)
198
printf("drizzle_con_accept:%s\n", drizzle_error(&(server->drizzle)));
198
fprintf(stderr, "drizzle_con_accept:%s\n", drizzle_error(server->drizzle));
242
242
drizzle_con_set_max_packet_size(&(server->con), DRIZZLE_MAX_PACKET_SIZE);
244
244
ret= drizzle_handshake_server_write(&(server->con));
245
DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_server_write",
245
DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_server_write", server->drizzle)
248
247
ret= drizzle_handshake_client_read(&(server->con));
249
DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_client_read", &(server->drizzle))
248
DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_client_read", server->drizzle)
251
250
if (drizzle_result_create(&(server->con), &(server->result)) == NULL)
252
DRIZZLE_RETURN_ERROR("drizzle_result_create", &(server->drizzle))
251
DRIZZLE_RETURN_ERROR("drizzle_result_create", server->drizzle)
254
253
ret= drizzle_result_write(&(server->con), &(server->result), true);
255
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", &(server->drizzle))
254
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", server->drizzle)
257
256
/* Command loop. */
270
DRIZZLE_RETURN_CHECK(ret, "drizzle_con_command_buffer", &(server->drizzle))
269
DRIZZLE_RETURN_CHECK(ret, "drizzle_con_command_buffer", server->drizzle)
272
271
if (server->verbose >= DRIZZLE_VERBOSE_INFO)
274
printf("Command=%u Data=%s\n", command,
273
fprintf(stderr, "Command=%u Data=%s\n", command,
275
274
data == NULL ? "NULL" : (char *)data);
278
277
if (drizzle_result_create(&(server->con), &(server->result)) == NULL)
279
DRIZZLE_RETURN_ERROR("drizzle_result_create", &(server->drizzle))
278
DRIZZLE_RETURN_ERROR("drizzle_result_create", server->drizzle)
281
280
if (command != DRIZZLE_COMMAND_QUERY ||
282
281
!strcasecmp((char *)data, "SHOW DATABASES"))
284
283
ret= drizzle_result_write(&(server->con), &(server->result), true);
285
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", &(server->drizzle))
284
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", server->drizzle)
287
286
if (command == DRIZZLE_COMMAND_FIELD_LIST)
289
288
drizzle_result_set_eof(&(server->result), true);
290
289
ret= drizzle_result_write(&(server->con), &(server->result), true);
291
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", &(server->drizzle))
290
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", server->drizzle)
321
320
if (sqlite_ret != SQLITE_OK)
323
322
if (sqlite_err == NULL)
324
printf("sqlite3_exec failed\n");
324
fprintf(stderr, "sqlite3_exec failed\n");
327
328
drizzle_result_set_error_code(&(server->result), (uint16_t)sqlite_ret);
328
329
drizzle_result_set_error(&(server->result), sqlite_err);
329
330
ret= drizzle_result_write(&(server->con), &(server->result), true);
330
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", &(server->drizzle))
331
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", server->drizzle)
332
printf("sqlite3_exec:%s\n", sqlite_err);
333
fprintf(stderr, "sqlite3_exec:%s\n", sqlite_err);
333
334
sqlite3_free(sqlite_err);
341
342
drizzle_result_set_column_count(&(server->result), 0);
342
343
ret= drizzle_result_write(&(server->con), &(server->result), true);
343
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", &(server->drizzle))
344
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", server->drizzle)
347
348
drizzle_result_set_eof(&(server->result), true);
348
349
ret= drizzle_result_write(&(server->con), &(server->result), true);
349
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", &(server->drizzle))
350
DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", server->drizzle)
364
365
drizzle_result_set_column_count(&(server->result), (uint16_t)field_count);
366
367
ret= drizzle_result_write(&(server->con), &(server->result), false);
367
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_result_write", &(server->drizzle))
368
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_result_write", server->drizzle)
369
370
if (drizzle_column_create(&(server->result), &(server->column)) == NULL)
371
DRIZZLE_RETURN_CHECK_VAL(DRIZZLE_RETURN_MEMORY, "drizzle_column_create",
372
DRIZZLE_RETURN_CHECK_VAL(DRIZZLE_RETURN_MEMORY, "drizzle_column_create", server->drizzle)
375
375
drizzle_column_set_catalog(&(server->column), "sqlite");
388
388
drizzle_column_set_orig_name(&(server->column), columns[x]);
390
390
ret= drizzle_column_write(&(server->result), &(server->column));
391
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_column_write", &(server->drizzle))
391
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_column_write", server->drizzle)
394
394
drizzle_column_free(&(server->column));
396
396
drizzle_result_set_eof(&(server->result), true);
398
398
ret= drizzle_result_write(&(server->con), &(server->result), false);
399
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_result_write", &(server->drizzle))
399
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_result_write", server->drizzle)
402
402
for (x= 0; x < field_count; x++)
414
414
ret= drizzle_row_write(&(server->result));
415
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_row_write", &(server->drizzle))
415
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_row_write", server->drizzle)
417
417
for (x= 0; x < field_count; x++)
419
419
ret= drizzle_field_write(&(server->result), (drizzle_field_t)fields[x],
420
420
sizes[x], sizes[x]);
421
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_field_write", &(server->drizzle))
421
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_field_write", server->drizzle)
440
440
drizzle_result_set_column_count(&(server->result), 1);
442
442
ret= drizzle_result_write(&(server->con), &(server->result), false);
443
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_result_write", &(server->drizzle))
443
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_result_write", server->drizzle)
445
445
if (drizzle_column_create(&(server->result), &(server->column)) == NULL)
447
DRIZZLE_RETURN_CHECK_VAL(DRIZZLE_RETURN_MEMORY, "drizzle_column_create",
447
DRIZZLE_RETURN_CHECK_VAL(DRIZZLE_RETURN_MEMORY, "drizzle_column_create", server->drizzle)
451
450
drizzle_column_set_catalog(&(server->column), "sqlite");
459
458
drizzle_column_set_orig_name(&(server->column), "version");
461
460
ret= drizzle_column_write(&(server->result), &(server->column));
462
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_column_write", &(server->drizzle))
461
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_column_write", server->drizzle)
464
463
drizzle_column_free(&(server->column));
466
465
drizzle_result_set_eof(&(server->result), true);
468
467
ret= drizzle_result_write(&(server->con), &(server->result), false);
469
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_result_write", &(server->drizzle))
468
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_result_write", server->drizzle)
471
470
/* This is needed for MySQL and old Drizzle protocol. */
472
471
drizzle_result_calc_row_size(&(server->result), fields, sizes);
474
473
ret= drizzle_row_write(&(server->result));
475
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_row_write", &(server->drizzle))
474
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_row_write", server->drizzle)
477
476
ret= drizzle_field_write(&(server->result), fields[0], sizes[0], sizes[0]);
478
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_field_write", &(server->drizzle))
477
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_field_write", server->drizzle)
480
479
ret= drizzle_result_write(&(server->con), &(server->result), true);
481
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_result_write", &(server->drizzle))
480
DRIZZLE_RETURN_CHECK_VAL(ret, "drizzle_result_write", server->drizzle)
483
482
return DRIZZLE_RETURN_OK;
486
485
static void usage(char *name)
488
printf("\nusage: %s [-c <count>] [-h <host>] [-m] [-p <port>] [-v] "
489
"<sqlite3 db file>\n", name);
490
printf("\t-c <count> - Number of connections to accept before exiting\n");
491
printf("\t-h <host> - Host to listen on\n");
492
printf("\t-m - Use the MySQL protocol\n");
493
printf("\t-p <port> - Port to listen on\n");
494
printf("\t-v - Increase verbosity level\n");
487
fprintf(stderr, "\nusage: %s [-c <count>] [-h <host>] [-m] [-p <port>] [-v] " "<sqlite3 db file>\n", name);
488
fprintf(stderr, "\t-c <count> - Number of connections to accept before exiting\n");
489
fprintf(stderr, "\t-h <host> - Host to listen on\n");
490
fprintf(stderr, "\t-m - Use the MySQL protocol\n");
491
fprintf(stderr, "\t-p <port> - Port to listen on\n");
492
fprintf(stderr, "\t-v - Increase verbosity level\n");