358
if (drizzleclient_query(drizzle, sql_statement))
361
if (drizzle_query_str(con, &result, sql_statement, &ret) == NULL ||
362
ret != DRIZZLE_RETURN_OK)
360
db_error_with_table(drizzle, tablename);
364
db_error(con, &result, ret, tablename);
365
if (drizzleclient_info(drizzle)) /* If NULL-pointer, print nothing */
369
if (strcmp(drizzle_result_info(&result), ""))
367
371
fprintf(stdout, "%s.%s: %s\n", current_db, tablename,
368
drizzleclient_info(drizzle));
372
drizzle_result_info(&result));
375
drizzle_result_free(&result);
376
static void lock_table(DRIZZLE *drizzle, int tablecount, char **raw_tablename)
380
static void lock_table(drizzle_con_st *con, int tablecount, char **raw_tablename)
380
384
char tablename[FN_REFLEN];
385
drizzle_result_st result;
386
drizzle_return_t ret;
383
389
fprintf(stdout, "Locking tables for write\n");
388
394
query.append(tablename);
389
395
query.append(" WRITE,");
391
if (drizzleclient_real_query(drizzle, query.c_str(), query.length()-1))
392
db_error(drizzle); /* We shall countinue here, if --force was given */
397
if (drizzle_query(con, &result, query.c_str(), query.length()-1,
399
ret != DRIZZLE_RETURN_OK)
401
db_error(con, &result, ret, NULL);
402
/* We shall countinue here, if --force was given */
405
drizzle_result_free(&result);
398
static DRIZZLE *db_connect(char *host, char *database,
399
char *user, char *passwd)
409
static drizzle_con_st *db_connect(char *host, char *database,
410
char *user, char *passwd)
414
drizzle_return_t ret;
403
417
fprintf(stdout, "Connecting to %s\n", host ? host : "localhost");
404
if (!(drizzle= drizzleclient_create(NULL)))
407
drizzleclient_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
409
drizzleclient_options(drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
410
if (!(drizzleclient_connect(drizzle,host,user,passwd,
411
database,opt_drizzle_port,opt_drizzle_unix_port,
418
if (!(drizzle= drizzle_create(NULL)))
420
if (!(con= drizzle_con_add_tcp(drizzle,NULL,host,opt_drizzle_port,user,passwd,
421
database, DRIZZLE_CON_NONE)))
426
if ((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
414
428
ignore_errors=0; /* NO RETURN FROM db_error */
429
db_error(con, NULL, ret, NULL);
417
drizzle->reconnect= 0;
419
433
fprintf(stdout, "Selecting database %s\n", database);
420
if (drizzleclient_select_db(drizzle, database))
430
static void db_disconnect(char *host, DRIZZLE *drizzle)
440
static void db_disconnect(char *host, drizzle_con_st *con)
433
443
fprintf(stdout, "Disconnecting from %s\n", host ? host : "localhost");
434
drizzleclient_close(drizzle);
444
drizzle_free(drizzle_con_drizzle(con));
439
static void safe_exit(int error, DRIZZLE *drizzle)
449
static void safe_exit(int error, drizzle_con_st *con)
441
451
if (ignore_errors)
444
drizzleclient_close(drizzle);
454
drizzle_free(drizzle_con_drizzle(con));
450
static void db_error_with_table(DRIZZLE *drizzle, char *table)
452
my_printf_error(0,"Error: %d, %s, when using table: %s",
453
MYF(0), drizzleclient_errno(drizzle), drizzleclient_error(drizzle), table);
454
safe_exit(1, drizzle);
459
static void db_error(DRIZZLE *drizzle)
461
my_printf_error(0,"Error: %d %s", MYF(0), drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
462
safe_exit(1, drizzle);
460
static void db_error(drizzle_con_st *con, drizzle_result_st *result,
461
drizzle_return_t ret, char *table)
463
if (ret == DRIZZLE_RETURN_ERROR_CODE)
465
my_printf_error(0,"Error: %d, %s%s%s", MYF(0),
466
drizzle_result_error_code(result),
467
drizzle_result_error(result),
468
table ? ", when using table: " : "", table ? table : "");
469
drizzle_result_free(result);
473
my_printf_error(0,"Error: %d, %s%s%s", MYF(0), ret, drizzle_con_error(con),
474
table ? ", when using table: " : "", table ? table : "");
521
536
char *raw_table_name= (char *)arg;
537
drizzle_con_st *con= NULL;
538
drizzle_result_st result;
539
drizzle_return_t ret;
524
if (!(drizzle= db_connect(current_host,current_db,current_user,opt_password)))
541
if (!(con= db_connect(current_host,current_db,current_user,opt_password)))
529
if (drizzleclient_query(drizzle, "/*!40101 set @@character_set_database=binary */;"))
546
if (drizzle_query_str(con, &result,
547
"/*!40101 set @@character_set_database=binary */;",
549
ret != DRIZZLE_RETURN_OK)
531
db_error(drizzle); /* We shall countinue here, if --force was given */
551
db_error(con, &result, ret, NULL);
552
/* We shall countinue here, if --force was given */
536
557
We are not currently catching the error here.
538
if((error= write_to_table(raw_table_name, drizzle)))
559
if((error= write_to_table(raw_table_name, con)))
539
560
if (exitcode == 0)
544
db_disconnect(current_host, drizzle);
565
db_disconnect(current_host, con);
546
567
pthread_mutex_lock(&counter_mutex);
628
if (!(drizzle= db_connect(current_host,current_db,current_user,opt_password)))
648
drizzle_con_st *con= 0;
649
drizzle_result_st result;
650
drizzle_return_t ret;
651
if (!(con= db_connect(current_host,current_db,current_user,opt_password)))
630
653
free_defaults(argv_to_free);
631
654
return(1); /* purecov: deadcode */
634
if (drizzleclient_query(drizzle, "/*!40101 set @@character_set_database=binary */;"))
657
if (drizzle_query_str(con, &result,
658
"/*!40101 set @@character_set_database=binary */;",
660
ret != DRIZZLE_RETURN_OK)
636
db_error(drizzle); /* We shall countinue here, if --force was given */
662
db_error(con, &result, ret, NULL);
663
/* We shall countinue here, if --force was given */
667
drizzle_result_free(&result);
641
lock_table(drizzle, argc, argv);
670
lock_table(con, argc, argv);
642
671
for (; *argv != NULL; argv++)
643
if ((error= write_to_table(*argv, drizzle)))
672
if ((error= write_to_table(*argv, con)))
644
673
if (exitcode == 0)
646
db_disconnect(current_host, drizzle);
675
db_disconnect(current_host, con);
648
677
free(opt_password);
649
678
free_defaults(argv_to_free);