846
846
** DB_error -- prints DRIZZLE error message and exits the program.
848
static void DB_error(drizzle_con_st *con, const char *when)
848
static void DB_error(drizzle_result_st *res, drizzle_return_t ret,
851
if (ret == DRIZZLE_RETURN_ERROR_CODE)
853
maybe_die(EX_DRIZZLEERR, _("Got error: %s %s"),
854
drizzle_result_error_code(res), when);
855
drizzle_result_free(res);
858
maybe_die(EX_DRIZZLEERR, _("Got error: %s %s"), ret, when);
851
maybe_die(EX_DRIZZLEERR, _("Got error: %s %s"), drizzle_con_error(con), when);
936
944
static int drizzleclient_query_with_error_report(drizzle_con_st *con,
937
945
drizzle_result_st *result,
946
const char *query, bool quick)
940
948
drizzle_return_t ret;
942
950
if (drizzle_query_str(con, result, query, &ret) == NULL ||
943
ret != DRIZZLE_RETURN_OK ||
944
drizzle_result_buffer(result) != DRIZZLE_RETURN_OK)
951
ret != DRIZZLE_RETURN_OK)
953
if (ret == DRIZZLE_RETURN_ERROR_CODE)
955
maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
956
query, drizzle_result_error(result),
957
drizzle_result_error_code(result));
958
drizzle_result_free(result);
962
maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
963
query, drizzle_con_error(con), ret);
969
ret= drizzle_column_buffer(result);
971
ret= drizzle_result_buffer(result);
972
if (ret != DRIZZLE_RETURN_OK)
974
drizzle_result_free(result);
946
975
maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
947
query, drizzle_con_error(con), ret);
976
query, drizzle_con_error(con), ret);
1005
1035
static int connect_to_db(char *host, char *user,char *passwd)
1037
drizzle_return_t ret;
1007
1039
verbose_msg(_("-- Connecting to %s...\n"), host ? host : "localhost");
1008
1040
drizzle_create(&drizzle);
1009
1041
drizzle_con_create(&drizzle, &dcon);
1010
1042
drizzle_con_set_tcp(&dcon, host, opt_drizzle_port);
1011
1043
drizzle_con_set_auth(&dcon, user, passwd);
1012
if (drizzle_con_connect(&dcon) != DRIZZLE_RETURN_OK)
1044
ret= drizzle_con_connect(&dcon);
1045
if (ret != DRIZZLE_RETURN_OK)
1014
DB_error(&dcon, "when trying to connect");
1047
DB_error(NULL, ret, "when trying to connect");
1416
1449
snprintf(buff, sizeof(buff), "show create table %s", result_table);
1418
if (drizzleclient_query_with_error_report(&dcon, &result, buff))
1451
if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1423
1456
if (!(sql_file= open_sql_file_for_table(table)))
1458
drizzle_result_free(&result);
1426
1462
write_header(sql_file, db);
1449
1485
check_io(sql_file);
1450
1486
drizzle_result_free(&result);
1452
1489
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1454
if (drizzleclient_query_with_error_report(&dcon, &result, query_buff))
1492
if (drizzleclient_query_with_error_report(&dcon, &result, query_buff, false))
1457
1495
fclose(sql_file);
1508
1546
snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1510
if (drizzleclient_query_with_error_report(&dcon, &result, query_buff))
1548
if (drizzleclient_query_with_error_report(&dcon, &result, query_buff, false))
1513
1551
/* Make an sql-file, if path was given iow. option -T was given */
1601
1639
*num_fields= drizzle_result_row_count(&result);
1602
1640
drizzle_result_free(&result);
1603
1642
if (!opt_no_create_info)
1605
1644
/* Make an sql-file, if path was given iow. option -T was given */
1606
1645
char buff[20+FN_REFLEN];
1607
1646
uint32_t keynr,primary_key;
1608
1647
snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1609
if (drizzleclient_query_with_error_report(dcon, &result, buff))
1648
if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1611
if (drizzleclient_errno(drizzle) == ER_WRONG_OBJECT)
1614
fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1617
fprintf(stderr, _("%s: Can't get keys for table %s (%s)\n"),
1618
my_progname, result_table, drizzleclient_error(drizzle));
1650
fprintf(stderr, _("%s: Can't get keys for table %s\n"),
1651
my_progname, result_table);
1620
1653
fclose(sql_file);
1643
drizzleclient_data_seek(result,0);
1676
drizzle_row_seek(&result,0);
1645
while ((row= drizzleclient_fetch_row(result)))
1678
while ((row= drizzle_row_next(&result)))
1649
print_xml_row(sql_file, "key", result, &row);
1682
print_xml_row(sql_file, "key", &result, &row);
1681
1714
/* Get DRIZZLE specific create options */
1682
1715
if (create_options)
1684
char show_name_buff[NAME_LEN*2+2+24];
1717
char show_name_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE*2+2+24];
1686
1719
/* Check memory for quote_for_like() */
1687
1720
snprintf(buff, sizeof(buff), "show table status like %s",
1688
1721
quote_for_like(table, show_name_buff));
1690
if (drizzleclient_query_with_error_report(dcon, &result, buff))
1723
if (!drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1692
if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
1693
{ /* If old DRIZZLE version */
1694
verbose_msg(_("-- Warning: Couldn't get status information for " \
1695
"table %s (%s)\n"), result_table,drizzleclient_error(drizzle));
1725
if (!(row= drizzle_row_next(&result)))
1728
_("Error: Couldn't read status information for table %s\n"),
1698
else if (!(row= drizzleclient_fetch_row(result)))
1701
_("Error: Couldn't read status information for table %s (%s)\n"),
1702
result_table,drizzleclient_error(drizzle));
1707
print_xml_row(sql_file, "options", result, &row);
1710
fputs("/*!",sql_file);
1711
print_value(sql_file,result,row,"engine=","Engine",0);
1712
print_value(sql_file,result,row,"","Create_options",0);
1713
print_value(sql_file,result,row,"comment=","Comment",1);
1734
print_xml_row(sql_file, "options", &result, &row);
1737
fputs("/*!",sql_file);
1738
print_value(sql_file,&result,row,"engine=","Engine",0);
1739
print_value(sql_file,&result,row,"","Create_options",0);
1740
print_value(sql_file,&result,row,"comment=","Comment",1);
1715
fputs(" */",sql_file);
1742
fputs(" */",sql_file);
1746
drizzle_result_free(&result);
1719
drizzleclient_free_result(result); /* Is always safe to free */
1723
1750
fputs(";\n", sql_file);
1822
1849
static void dump_table(char *table, char *db)
1824
1851
char ignore_flag;
1825
char buf[200], table_buff[NAME_LEN+3];
1852
char table_buff[DRIZZLE_MAX_TABLE_SIZE+3];
1826
1853
string query_string;
1827
char table_type[NAME_LEN];
1828
char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table;
1854
char table_type[DRIZZLE_MAX_TABLE_SIZE];
1855
char *result_table, table_buff2[DRIZZLE_MAX_TABLE_SIZE*2+3], *opt_quoted_table;
1830
1857
uint32_t rownr, row_break, total_length, init_length;
1831
1858
uint64_t num_fields= 0;
1832
drizzle_result_st *res;
1833
DRIZZLE_FIELD *field;
1859
drizzle_return_t ret;
1860
drizzle_result_st result;
1861
drizzle_column_st *column;
1923
1951
query_string.append( order_by);
1926
if (drizzleclient_real_query(drizzle, query_string.c_str(), query_string.length()))
1954
if (drizzle_query(&dcon, &result, query_string.c_str(),
1955
query_string.length(), &ret) == NULL ||
1956
ret != DRIZZLE_RETURN_OK)
1928
DB_error(drizzle, _("when executing 'SELECT INTO OUTFILE'"));
1958
DB_error(&result, ret, _("when executing 'SELECT INTO OUTFILE'"));
1962
drizzle_result_free(&result);
1968
2000
fputs("\n", md_result_file);
1969
2001
check_io(md_result_file);
1971
if (drizzleclient_query_with_error_report(dcon, &result,
1972
query_string.c_str()))
1974
DB_error(drizzle, _("when retrieving data from server"));
1978
res=drizzleclient_use_result(drizzle);
1980
res=drizzleclient_store_result(drizzle);
1983
DB_error(drizzle, _("when retrieving data from server"));
2003
if (drizzleclient_query_with_error_report(&dcon, &result,
2004
query_string.c_str(), quick))
1987
2009
verbose_msg(_("-- Retrieving rows...\n"));
1988
if (drizzleclient_num_fields(res) != num_fields)
2010
if (drizzle_result_column_count(&result) != num_fields)
1990
2012
fprintf(stderr,_("%s: Error in field count for table: %s ! Aborting.\n"),
1991
2013
my_progname, result_table);
1992
2014
error= EX_CONSCHECK;
2015
drizzle_result_free(&result);
2019
2042
check_io(md_result_file);
2022
while ((row= drizzleclient_fetch_row(res)))
2025
uint32_t *lengths= drizzleclient_fetch_lengths(res);
2055
drizzle_row_free(&result, row);
2057
row= drizzle_row_buffer(&result, &ret);
2058
if (ret != DRIZZLE_RETURN_OK)
2061
_("%s: Error reading rows for table: %s (%d:%s) ! Aborting.\n"),
2062
my_progname, result_table, ret, drizzle_con_error(&dcon));
2063
drizzle_result_free(&result);
2068
row= drizzle_row_next(&result);
2073
lengths= drizzle_row_field_sizes(&result);
2027
2076
if ((rownr % show_progress_size) == 0)
2041
2090
check_io(md_result_file);
2044
for (i= 0; i < drizzleclient_num_fields(res); i++)
2093
for (i= 0; i < drizzle_result_column_count(&result); i++)
2047
2096
uint32_t length= lengths[i];
2049
if (!(field= drizzleclient_fetch_field(res)))
2098
if (!(column= drizzle_column_next(&result)))
2050
2099
die(EX_CONSCHECK,
2051
2100
_("Not enough fields from table %s! Aborting.\n"),
2056
2105
we have not a BLOB but a TEXT column.
2057
2106
we'll dump in hex only BLOB columns.
2059
is_blob= (opt_hex_blob && field->charsetnr == 63 &&
2060
(field->type == DRIZZLE_TYPE_VARCHAR ||
2061
field->type == DRIZZLE_TYPE_BLOB)) ? 1 : 0;
2108
is_blob= (opt_hex_blob && drizzle_column_charset(column) == 63 &&
2109
(drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_VARCHAR ||
2110
drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_BLOB)) ? 1 : 0;
2062
2111
if (extended_insert && !opt_xml)
2088
2137
if (opt_hex_blob && is_blob)
2090
2139
extended_row.append("0x");
2091
drizzleclient_drizzleclient_octet2hex(tmp_str, row[i], length);
2140
drizzle_hex_string(tmp_str, row[i], length);
2092
2141
extended_row.append(tmp_str);
2096
2145
extended_row.append("'");
2097
drizzleclient_escape_string(tmp_str,
2146
drizzle_escape_string(tmp_str, row[i],length);
2099
2147
extended_row.append(tmp_str);
2100
2148
extended_row.append("'");
2138
2186
/* Define xsi:type="xs:hexBinary" for hex encoded data */
2139
2187
print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2140
field->name, "xsi:type=", "xs:hexBinary", NULL);
2188
drizzle_column_name(column), "xsi:type=", "xs:hexBinary", NULL);
2141
2189
print_blob_as_hex(md_result_file, row[i], length);
2145
2193
print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2194
drizzle_column_name(column), NULL);
2147
2195
print_quoted_xml(md_result_file, row[i], length);
2149
2197
fputs("</field>\n", md_result_file);
2165
2213
print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2214
drizzle_column_name(column), NULL);
2167
2215
fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
2168
2216
md_result_file);
2169
2217
fputs("</field>\n", md_result_file);
2231
2279
fputs(";\n", md_result_file); /* If not empty table */
2232
2280
fflush(md_result_file);
2233
2281
check_io(md_result_file);
2234
if (drizzleclient_errno(drizzle))
2236
snprintf(buf, sizeof(buf),
2237
_("%s: Error %d: %s when dumping table %s at row: %d\n"),
2239
drizzleclient_errno(drizzle),
2240
drizzleclient_error(drizzle),
2244
error= EX_CONSCHECK;
2248
2283
/* Moved enable keys to before unlock per bug 15977 */
2249
2284
if (opt_disable_keys)
2275
2310
static char *getTableName(int reset)
2277
static drizzle_result_st *res= NULL;
2312
static drizzle_result_st result;
2313
static bool have_result= false;
2282
if (!(res= drizzleclient_list_tables(drizzle,NULL)))
2318
if (drizzleclient_query_with_error_report(&dcon, &result, "SHOW TABLES", false))
2285
if ((row= drizzleclient_fetch_row(res)))
2286
return((char*) row[0]);
2323
if ((row= drizzle_row_next(&result)))
2289
drizzleclient_data_seek(res,0); /* We want to read again */
2327
drizzle_row_seek(&result, 0);
2292
drizzleclient_free_result(res);
2330
drizzle_result_free(&result);
2296
2334
} /* getTableName */
2299
2337
static int dump_all_databases()
2301
2339
drizzle_row_t row;
2302
drizzle_result_st *tableres;
2340
drizzle_result_st tableres;
2305
if (drizzleclient_query_with_error_report(dcon, &tableres, "SHOW DATABASES"))
2343
if (drizzleclient_query_with_error_report(&dcon, &tableres, "SHOW DATABASES", false))
2307
while ((row= drizzleclient_fetch_row(tableres)))
2345
while ((row= drizzle_row_next(&tableres)))
2309
2347
if (dump_all_tables_in_db(row[0]))
2350
drizzle_result_free(&tableres);
2314
2353
/* dump_all_databases */
2344
2383
int init_dumping_tables(char *qdatabase)
2348
2385
if (!opt_create_db)
2350
2387
char qbuf[256];
2351
2388
drizzle_row_t row;
2352
drizzle_result_st *dbinfo;
2389
drizzle_result_st result;
2390
drizzle_return_t ret;
2354
2392
snprintf(qbuf, sizeof(qbuf),
2355
2393
"SHOW CREATE DATABASE IF NOT EXISTS %s",
2358
if (drizzleclient_query(drizzle, qbuf) || !(dbinfo = drizzleclient_store_result(drizzle)))
2396
if (drizzle_query_str(&dcon, &result, qbuf, &ret) == NULL ||
2397
ret != DRIZZLE_RETURN_OK)
2399
if (ret == DRIZZLE_RETURN_ERROR_CODE)
2400
drizzle_result_free(&result);
2360
2402
/* Old server version, dump generic CREATE DATABASE */
2361
2403
if (opt_drop_database)
2362
2404
fprintf(md_result_file,
2371
if (opt_drop_database)
2372
fprintf(md_result_file,
2373
"\nDROP DATABASE IF EXISTS %s;\n",
2375
row = drizzleclient_fetch_row(dbinfo);
2413
if (drizzle_result_buffer(&result) == DRIZZLE_RETURN_OK)
2378
fprintf(md_result_file,"\n%s;\n",row[1]);
2415
if (opt_drop_database)
2416
fprintf(md_result_file,
2417
"\nDROP DATABASE IF EXISTS %s;\n",
2419
row = drizzle_row_next(&result);
2420
if (row != NULL && row[1])
2422
fprintf(md_result_file,"\n%s;\n",row[1]);
2380
drizzleclient_free_result(dbinfo);
2425
drizzle_result_free(&result);
2387
2432
static int init_dumping(char *database, int init_func(char*))
2389
if (drizzleclient_get_server_version(drizzle) >= 50003 &&
2390
!my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
2434
drizzle_result_st result;
2435
drizzle_return_t ret;
2437
if (!my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
2393
if (drizzleclient_select_db(drizzle, database))
2440
if (drizzle_select_db(&dcon, &result, database, &ret) == NULL ||
2441
ret != DRIZZLE_RETURN_OK)
2395
DB_error(drizzle, _("when selecting the database"));
2443
DB_error(&result, ret, _("when executing 'SELECT INTO OUTFILE'"));
2396
2444
return 1; /* If --force */
2446
drizzle_result_free(&result);
2398
2448
if (!path && !opt_xml)
2400
2450
if (opt_databases || opt_alldbs)
2437
2487
uint32_t numrows;
2438
char table_buff[NAME_LEN*2+3];
2439
char hash_key[2*NAME_LEN+2]; /* "db.tablename" */
2488
char table_buff[DRIZZLE_MAX_TABLE_SIZE*2+3];
2489
char hash_key[DRIZZLE_MAX_DB_SIZE+DRIZZLE_MAX_TABLE_SIZE+2]; /* "db.tablename" */
2440
2490
char *afterdot;
2491
drizzle_result_st result;
2492
drizzle_return_t ret;
2442
2494
afterdot= strcpy(hash_key, database) + strlen(database);
2443
2495
*afterdot++= '.';
2459
2511
query.append( " READ LOCAL,");
2462
if (numrows && drizzleclient_real_query(drizzle, query.c_str(), query.length()-1))
2463
DB_error(drizzle, _("when using LOCK TABLES"));
2464
/* We shall continue here, if --force was given */
2516
if (drizzle_query(&dcon, &result, query.c_str(),
2517
query.length()-1, &ret) == NULL ||
2518
ret != DRIZZLE_RETURN_OK)
2520
DB_error(&result, ret, _("when using LOCK TABLES"));
2521
/* We shall continue here, if --force was given */
2524
drizzle_result_free(&result);
2467
2528
if (flush_logs)
2469
if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
2470
DB_error(drizzle, _("when doing refresh"));
2471
/* We shall continue here, if --force was given */
2530
if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
2531
ret != DRIZZLE_RETURN_OK)
2533
DB_error(&result, ret, _("when doing refresh"));
2534
/* We shall continue here, if --force was given */
2537
drizzle_result_free(&result);
2473
2539
while ((table= getTableName(0)))
2486
2552
check_io(md_result_file);
2488
2554
if (lock_tables)
2489
drizzleclient_query_with_error_report(dcon, &result, "UNLOCK TABLES");
2556
if (!drizzleclient_query_with_error_report(&dcon, &result, "UNLOCK TABLES", false))
2557
drizzle_result_free(&result);
2492
2561
} /* dump_all_tables_in_db */
2506
2575
static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root)
2509
drizzle_result_st *table_res;
2578
drizzle_result_st result;
2510
2579
drizzle_row_t row;
2511
char query[50 + 2*NAME_LEN];
2580
char query[50 + 2*DRIZZLE_MAX_TABLE_SIZE];
2512
2581
char show_name_buff[FN_REFLEN];
2515
2585
/* Check memory for quote_for_like() */
2517
2587
snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2518
2588
quote_for_like(old_table_name, show_name_buff));
2520
if (drizzleclient_query_with_error_report(dcon, &result, query))
2590
if (drizzleclient_query_with_error_report(&dcon, &result, query, false))
2523
if ((table_res= drizzleclient_store_result(drizzle)))
2593
num_rows= drizzle_result_row_count(&result);
2525
uint64_t num_rows= drizzleclient_num_rows(table_res);
2531
TODO: Return all matching rows
2533
row= drizzleclient_fetch_row(table_res);
2534
lengths= drizzleclient_fetch_lengths(table_res);
2535
name= strmake_root(root, row[0], lengths[0]);
2537
drizzleclient_free_result(table_res);
2599
TODO: Return all matching rows
2601
row= drizzle_row_next(&result);
2602
lengths= drizzle_row_field_sizes(&result);
2603
name= strmake_root(root, row[0], lengths[0]);
2605
drizzle_result_free(&result);
2543
2611
static int dump_selected_tables(char *db, char **table_names, int tables)
2545
char table_buff[NAME_LEN*2+3];
2613
char table_buff[DRIZZLE_MAX_TABLE_SIZE*2+3];
2546
2614
string lock_tables_query("LOCK TABLES ");
2548
2616
char **dump_tables, **pos, **end;
2617
drizzle_result_st result;
2618
drizzle_return_t ret;
2551
2621
if (init_dumping(db, init_dumping_tables))
2583
2653
if (lock_tables)
2585
if (drizzleclient_real_query(drizzle, lock_tables_query.c_str(),
2586
lock_tables_query.length()-1))
2655
if (drizzle_query(&dcon, &result, lock_tables_query.c_str(),
2656
lock_tables_query.length()-1, &ret) == NULL ||
2657
ret != DRIZZLE_RETURN_OK)
2588
2659
if (!ignore_errors)
2590
2661
free_root(&root, MYF(0));
2592
DB_error(drizzle, _("when doing LOCK TABLES"));
2593
/* We shall countinue here, if --force was given */
2663
DB_error(&result, ret, _("when doing LOCK TABLES"));
2664
/* We shall countinue here, if --force was given */
2667
drizzle_result_free(&result);
2596
2669
if (flush_logs)
2598
if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
2671
if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
2672
ret != DRIZZLE_RETURN_OK)
2600
2674
if (!ignore_errors)
2601
2675
free_root(&root, MYF(0));
2602
DB_error(drizzle, _("when doing refresh"));
2676
DB_error(&result, ret, _("when doing refresh"));
2677
/* We shall countinue here, if --force was given */
2604
/* We shall countinue here, if --force was given */
2680
drizzle_result_free(&result);
2607
2683
print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
2619
2695
check_io(md_result_file);
2621
2697
if (lock_tables)
2622
drizzleclient_query_with_error_report(dcon, &result, "UNLOCK TABLES");
2699
if (!(drizzleclient_query_with_error_report(&dcon, &result, "UNLOCK TABLES", false)))
2700
drizzle_result_free(&result);
2624
2703
} /* dump_selected_tables */
2630
2709
drizzle_result_st master;
2631
2710
const char *comment_prefix=
2632
2711
(opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2633
if (drizzleclient_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
2712
if (drizzleclient_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS", false))
2639
row= drizzleclient_fetch_row(master);
2718
row= drizzle_row_next(&master);
2640
2719
if (row && row[0] && row[1])
2642
2721
/* SHOW MASTER STATUS reports file and position */
2654
2733
/* SHOW MASTER STATUS reports nothing and --force is not enabled */
2655
2734
my_printf_error(0, _("Error: Binlogging on server not active"),
2657
drizzleclient_free_result(master);
2736
drizzle_result_free(&master);
2658
2737
maybe_exit(EX_DRIZZLEERR);
2661
drizzleclient_free_result(master);
2740
drizzle_result_free(&master);
2666
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
2745
static int do_stop_slave_sql(drizzle_con_st *drizzle_con)
2668
drizzle_result_st *slave;
2747
drizzle_result_st slave;
2669
2748
/* We need to check if the slave sql is running in the first place */
2670
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2749
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2674
drizzle_row_t row= drizzleclient_fetch_row(slave);
2753
drizzle_row_t row= drizzle_row_next(&slave);
2675
2754
if (row && row[11])
2677
2756
/* if SLAVE SQL is not running, we don't stop it */
2678
2757
if (!strcmp(row[11],"No"))
2680
drizzleclient_free_result(slave);
2759
drizzle_result_free(&slave);
2681
2760
/* Silently assume that they don't have the slave running */
2686
drizzleclient_free_result(slave);
2765
drizzle_result_free(&slave);
2688
2767
/* now, stop slave if running */
2689
if (drizzleclient_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
2768
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "STOP SLAVE SQL_THREAD", false))
2770
drizzle_result_free(&slave);
2713
static int do_show_slave_status(DRIZZLE *drizzle_con)
2793
static int do_show_slave_status(drizzle_con_st *drizzle_con)
2715
drizzle_result_st *slave;
2795
drizzle_result_st slave;
2716
2796
const char *comment_prefix=
2717
2797
(opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2718
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2798
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2720
2800
if (!ignore_errors)
2750
2830
check_io(md_result_file);
2752
drizzleclient_free_result(slave);
2832
drizzle_result_free(&slave);
2757
static int do_start_slave_sql(DRIZZLE *drizzle_con)
2837
static int do_start_slave_sql(drizzle_con_st *drizzle_con)
2759
drizzle_result_st *slave;
2839
drizzle_result_st slave;
2760
2840
/* We need to check if the slave sql is stopped in the first place */
2761
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2841
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2765
drizzle_row_t row= drizzleclient_fetch_row(slave);
2845
drizzle_row_t row= drizzle_row_next(&slave);
2766
2846
if (row && row[11])
2768
2848
/* if SLAVE SQL is not running, we don't start it */
2769
2849
if (!strcmp(row[11],"Yes"))
2771
drizzleclient_free_result(slave);
2851
drizzle_result_free(&slave);
2772
2852
/* Silently assume that they don't have the slave running */
2856
drizzle_result_free(&slave);
2777
drizzleclient_free_result(slave);
2779
2859
/* now, start slave if stopped */
2780
if (drizzleclient_query_with_error_report(drizzle_con, 0, "START SLAVE"))
2860
if (drizzleclient_query_with_error_report(drizzle_con, &slave, "START SLAVE", false))
2782
2862
my_printf_error(0, _("Error: Unable to start slave"), MYF(0));
2865
drizzle_result_free(&slave);
2790
static int do_flush_tables_read_lock(DRIZZLE *drizzle_con)
2871
static int do_flush_tables_read_lock(drizzle_con_st *drizzle_con)
2793
2874
We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
2798
2879
update starts between the two FLUSHes, we have that bad stall.
2801
( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
2882
( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES", false) ||
2802
2883
drizzleclient_query_with_error_report(drizzle_con, 0,
2803
"FLUSH TABLES WITH READ LOCK") );
2884
"FLUSH TABLES WITH READ LOCK", false) );
2807
static int do_unlock_tables(DRIZZLE *drizzle_con)
2888
static int do_unlock_tables(drizzle_con_st *drizzle_con)
2809
return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
2890
return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES", false);
2812
static int get_bin_log_name(DRIZZLE *drizzle_con,
2893
static int get_bin_log_name(drizzle_con_st *drizzle_con,
2813
2894
char* buff_log_name, uint32_t buff_len)
2815
drizzle_result_st *res;
2896
drizzle_result_st res;
2816
2897
drizzle_row_t row;
2818
if (drizzleclient_query(drizzle_con, "SHOW MASTER STATUS") ||
2819
!(res= drizzleclient_store_result(drizzle)))
2899
if (drizzleclient_query_with_error_report(drizzle_con, &res, "SHOW MASTER STATUS", false))
2822
if (!(row= drizzleclient_fetch_row(res)))
2902
if (!(row= drizzle_row_next(&res)))
2824
drizzleclient_free_result(res);
2904
drizzle_result_free(&res);
2831
2911
strncpy(buff_log_name, row[0], buff_len - 1);
2833
drizzleclient_free_result(res);
2913
drizzle_result_free(&res);
2837
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
2917
static int purge_bin_logs_to(drizzle_con_st *drizzle_con, char* log_name)
2840
2920
string str= "PURGE BINARY LOGS TO '";
2841
2921
str.append(log_name);
2842
2922
str.append("'");
2843
err = drizzleclient_query_with_error_report(drizzle_con, 0, str.c_str());
2923
drizzle_result_st res;
2924
err= drizzleclient_query_with_error_report(drizzle_con, &res, str.c_str(),
2928
drizzle_result_free(&res);
2848
static int start_transaction(DRIZZLE *drizzle_con)
2933
static int start_transaction(drizzle_con_st *drizzle_con)
2850
2935
return (drizzleclient_query_with_error_report(drizzle_con, 0,
2851
2936
"SET SESSION TRANSACTION ISOLATION "
2852
"LEVEL REPEATABLE READ") ||
2937
"LEVEL REPEATABLE READ", false) ||
2853
2938
drizzleclient_query_with_error_report(drizzle_con, 0,
2854
2939
"START TRANSACTION "
2855
"WITH CONSISTENT SNAPSHOT"));
2940
"WITH CONSISTENT SNAPSHOT", false));
2902
2987
const char *prefix, const char *name,
2903
2988
int string_value)
2905
DRIZZLE_FIELD *field;
2906
drizzleclient_field_seek(result, 0);
2990
drizzle_column_st *column;
2991
drizzle_column_seek(result, 0);
2908
for ( ; (field= drizzleclient_fetch_field(result)) ; row++)
2993
for ( ; (column= drizzle_column_next(result)) ; row++)
2910
if (!strcmp(field->name,name))
2995
if (!strcmp(drizzle_column_name(column),name))
2912
2997
if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */
2933
3018
static const char* fetch_named_row(drizzle_result_st *result, drizzle_row_t row, const char *name)
2935
DRIZZLE_FIELD *field;
2936
drizzleclient_field_seek(result, 0);
2937
for ( ; (field= drizzleclient_fetch_field(result)) ; row++)
3020
drizzle_column_st *column;
3021
drizzle_column_seek(result, 0);
3023
for ( ; (column= drizzle_column_next(result)) ; row++)
2939
if (!strcmp(field->name,name))
3025
if (!strcmp(drizzle_column_name(column),name))
2941
3027
if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */
2943
drizzleclient_field_seek(result, 0);
3029
drizzle_column_seek(result, 0);
2948
drizzleclient_field_seek(result, 0);
3034
drizzle_column_seek(result, 0);
2979
3065
char result= IGNORE_NONE;
2980
3066
char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
2981
3067
const char *number_of_rows= NULL;
2982
drizzle_result_st *res= NULL;
3068
drizzle_result_st res;
2983
3069
drizzle_row_t row;
2985
3071
/* Check memory for quote_for_like() */
2986
3072
assert(2*sizeof(table_name) < sizeof(show_name_buff));
2987
3073
snprintf(buff, sizeof(buff), "show table status like %s",
2988
3074
quote_for_like(table_name, show_name_buff));
2989
if (drizzleclient_query_with_error_report(drizzle, &res, buff))
3075
if (drizzleclient_query_with_error_report(&dcon, &res, buff, false))
2991
if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
2992
{ /* If old DRIZZLE version */
2993
verbose_msg(_("-- Warning: Couldn't get status information for "
2994
"table %s (%s)\n"), table_name, drizzleclient_error(drizzle));
2995
return(result); /* assume table is ok */
2998
if (!(row= drizzleclient_fetch_row(res)))
3079
if (!(row= drizzle_row_next(&res)))
3000
3081
fprintf(stderr,
3001
_("Error: Couldn't read status information for table %s (%s)\n"),
3002
table_name, drizzleclient_error(drizzle));
3003
drizzleclient_free_result(res);
3082
_("Error: Couldn't read status information for table %s\n"),
3084
drizzle_result_free(&res);
3004
3085
return(result); /* assume table is ok */
3008
if ((number_of_rows= fetch_named_row(res, row, "Rows")) != NULL)
3089
if ((number_of_rows= fetch_named_row(&res, row, "Rows")) != NULL)
3010
3091
total_rows= strtoul(number_of_rows, NULL, 10);
3053
3134
static char *primary_key_fields(const char *table_name)
3055
drizzle_result_st *res= NULL;
3136
drizzle_result_st res;
3137
drizzle_return_t ret;
3056
3138
drizzle_row_t row;
3057
3139
/* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3058
char show_keys_buff[15 + NAME_LEN * 2 + 3];
3140
char show_keys_buff[15 + DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
3059
3141
uint32_t result_length= 0;
3060
3142
char *result= 0;
3061
char buff[NAME_LEN * 2 + 3];
3143
char buff[DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
3062
3144
char *quoted_field;
3064
3146
snprintf(show_keys_buff, sizeof(show_keys_buff),
3065
3147
"SHOW KEYS FROM %s", table_name);
3066
if (drizzleclient_query(drizzle, show_keys_buff) ||
3067
!(res= drizzleclient_store_result(drizzle)))
3148
if (drizzle_query_str(&dcon, &res, show_keys_buff, &ret) == NULL ||
3149
ret != DRIZZLE_RETURN_OK)
3151
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3153
fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
3154
" records are NOT sorted (%s)\n"),
3155
table_name, drizzle_result_error(&res));
3156
drizzle_result_free(&res);
3160
fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
3161
" records are NOT sorted (%s)\n"),
3162
table_name, drizzle_con_error(&dcon));
3168
if (drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3069
3170
fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
3070
3171
" records are NOT sorted (%s)\n"),
3071
table_name, drizzleclient_error(drizzle));
3072
/* Don't exit, because it's better to print out unsorted records */
3172
table_name, drizzle_con_error(&dcon));
3079
3179
* row, and UNIQUE keys come before others. So we only need to check
3080
3180
* the first key, not all keys.
3082
if ((row= drizzleclient_fetch_row(res)) && atoi(row[1]) == 0)
3182
if ((row= drizzle_row_next(&res)) && atoi(row[1]) == 0)
3084
3184
/* Key is unique */
3087
3187
quoted_field= quote_name(row[4], buff, 0);
3088
3188
result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3089
} while ((row= drizzleclient_fetch_row(res)) && atoi(row[3]) > 1);
3189
} while ((row= drizzle_row_next(&res)) && atoi(row[3]) > 1);
3092
3192
/* Build the ORDER BY clause result */
3100
3200
fprintf(stderr, _("Error: Not enough memory to store ORDER BY clause\n"));
3201
drizzle_result_free(&res);
3103
drizzleclient_data_seek(res, 0);
3104
row= drizzleclient_fetch_row(res);
3204
drizzle_row_seek(&res, 0);
3205
row= drizzle_row_next(&res);
3105
3206
quoted_field= quote_name(row[4], buff, 0);
3106
3207
end= strcpy(result, quoted_field) + strlen(quoted_field);
3107
while ((row= drizzleclient_fetch_row(res)) && atoi(row[3]) > 1)
3208
while ((row= drizzle_row_next(&res)) && atoi(row[3]) > 1)
3109
3210
quoted_field= quote_name(row[4], buff, 0);
3110
3211
end+= sprintf(end,",%s",quoted_field);
3116
drizzleclient_free_result(res);
3215
drizzle_result_free(&res);
3145
3244
write_header(md_result_file, *argv);
3147
if (opt_slave_data && do_stop_slave_sql(drizzle))
3246
if (opt_slave_data && do_stop_slave_sql(&dcon))
3150
3249
if ((opt_lock_all_tables || opt_master_data) &&
3151
do_flush_tables_read_lock(drizzle))
3250
do_flush_tables_read_lock(&dcon))
3153
if (opt_single_transaction && start_transaction(drizzle))
3252
if (opt_single_transaction && start_transaction(&dcon))
3155
3254
if (opt_delete_master_logs)
3157
if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")) ||
3158
get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
3256
if (drizzleclient_query_with_error_report(&dcon, &result, "FLUSH LOGS", false))
3258
drizzle_result_free(&result);
3259
if (get_bin_log_name(&dcon, bin_log_name, sizeof(bin_log_name)))
3162
3263
if (opt_lock_all_tables || opt_master_data)
3164
if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
3265
if (drizzleclient_query_with_error_report(&dcon, &result, "FLUSH LOGS", false))
3267
drizzle_result_free(&result);
3166
3268
flush_logs= 0; /* not anymore; that would not be sensible */
3168
3270
/* Add 'STOP SLAVE to beginning of dump */
3169
3271
if (opt_slave_apply && add_stop_slave())
3171
if (opt_master_data && do_show_master_status(drizzle))
3173
if (opt_slave_data && do_show_slave_status(drizzle))
3175
if (opt_single_transaction && do_unlock_tables(drizzle)) /* unlock but no commit! */
3273
if (opt_master_data && do_show_master_status(&dcon))
3275
if (opt_slave_data && do_show_slave_status(&dcon))
3277
if (opt_single_transaction && do_unlock_tables(&dcon)) /* unlock but no commit! */
3178
3280
if (opt_alldbs)