~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Brian Aker
  • Date: 2009-03-30 18:13:06 UTC
  • mfrom: (968.1.1 lib-merge)
  • Revision ID: brian@tangent.org-20090330181306-hzodbge1b0v57puh
Merge of Eric's libdrizzle work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
 
62
62
/* Size of buffer for dump's select query */
63
63
#define QUERY_LENGTH 1536
 
64
#define DRIZZLE_MAX_LINE_LENGTH 1024*1024L-1025
64
65
 
65
66
/* ignore table flags */
66
67
#define IGNORE_NONE 0x00 /* no ignore */
94
95
                opt_include_master_host_port= false,
95
96
                opt_alltspcs= false;
96
97
static bool debug_info_flag= false, debug_check_flag= false;
97
 
static uint32_t opt_max_allowed_packet, opt_net_buffer_length, show_progress_size= 0;
 
98
static uint32_t show_progress_size= 0;
98
99
static uint64_t total_rows= 0;
99
 
static DRIZZLE drizzleclient_connection, *drizzle= 0;
 
100
static drizzle_st drizzle;
 
101
static drizzle_con_st dcon;
100
102
static string insert_pat;
101
103
static char  *opt_password= NULL, *current_user= NULL,
102
104
             *current_host= NULL, *path= NULL, *fields_terminated= NULL,
313
315
   "Option automatically turns --lock-tables off.",
314
316
   (char**) &opt_master_data, (char**) &opt_master_data, 0,
315
317
   GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
316
 
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
317
 
    (char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
318
 
    GET_UINT32, REQUIRED_ARG, 24*1024*1024, 4096,
319
 
   (int64_t) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
320
 
  {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
321
 
    (char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0,
322
 
    GET_UINT32, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
323
 
   MALLOC_OVERHEAD-1024, 1024, 0},
324
318
  {"no-autocommit", OPT_AUTOCOMMIT,
325
319
   "Wrap tables with autocommit/commit statements.",
326
320
   (char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
415
409
static void die(int error, const char* reason, ...);
416
410
static void maybe_die(int error, const char* reason, ...);
417
411
static void write_header(FILE *sql_file, char *db_name);
418
 
static void print_value(FILE *file, DRIZZLE_RES  *result, DRIZZLE_ROW row,
419
 
                        const char *prefix,const char *name,
 
412
static void print_value(FILE *file, drizzle_result_st *result,
 
413
                        drizzle_row_t row, const char *prefix, const char *name,
420
414
                        int string_value);
421
 
static const char* fetch_named_row(DRIZZLE_RES *result, DRIZZLE_ROW row, const char* name);
 
415
static const char* fetch_named_row(drizzle_result_st *result, drizzle_row_t row,
 
416
                                   const char* name);
422
417
static int dump_selected_tables(char *db, char **table_names, int tables);
423
418
static int dump_all_tables_in_db(char *db);
424
419
static int init_dumping_tables(char *);
469
464
static void print_version(void)
470
465
{
471
466
  printf(_("%s  Ver %s Distrib %s, for %s (%s)\n"),my_progname,DUMP_VERSION,
472
 
         drizzleclient_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
467
         drizzle_version(),SYSTEM_TYPE,MACHINE_TYPE);
473
468
} /* print_version */
474
469
 
475
470
 
522
517
    {
523
518
      fprintf(sql_file,
524
519
              "-- DRIZZLE dump %s  Distrib %s, for %s (%s)\n--\n",
525
 
              DUMP_VERSION, drizzleclient_get_client_info(),
526
 
              SYSTEM_TYPE, MACHINE_TYPE);
 
520
              DUMP_VERSION, drizzle_version(), SYSTEM_TYPE, MACHINE_TYPE);
527
521
      fprintf(sql_file, "-- Host: %s    Database: %s\n",
528
522
              current_host ? current_host : "localhost", db_name ? db_name :
529
523
              "");
530
524
      fputs("-- ------------------------------------------------------\n",
531
525
            sql_file);
532
526
      fprintf(sql_file, "-- Server version\t%s\n",
533
 
              drizzleclient_get_server_info(&drizzleclient_connection));
 
527
              drizzle_con_server_version(&dcon));
534
528
    }
535
529
    if (opt_set_charset)
536
530
      fprintf(sql_file,
770
764
static int get_options(int *argc, char ***argv)
771
765
{
772
766
  int ho_error;
773
 
  const DRIZZLE_PARAMETERS *drizzle_params= drizzleclient_get_parameters();
774
 
 
775
 
  opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
776
 
  opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
777
767
 
778
768
  md_result_file= stdout;
779
769
  load_defaults("drizzle",load_default_groups,argc,argv);
787
777
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
788
778
    return(ho_error);
789
779
 
790
 
  *drizzle_params->p_max_allowed_packet= opt_max_allowed_packet;
791
 
  *drizzle_params->p_net_buffer_length= opt_net_buffer_length;
792
780
  if (debug_info_flag)
793
781
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
794
782
  if (debug_check_flag)
849
837
    return EX_USAGE;
850
838
  }
851
839
  if (tty_password)
852
 
    opt_password=drizzleclient_get_tty_password(NULL);
 
840
    opt_password=client_get_tty_password(NULL);
853
841
  return(0);
854
842
} /* get_options */
855
843
 
857
845
/*
858
846
** DB_error -- prints DRIZZLE error message and exits the program.
859
847
*/
860
 
static void DB_error(DRIZZLE *drizzle_arg, const char *when)
 
848
static void DB_error(drizzle_result_st *res, drizzle_return_t ret,
 
849
                     const char *when)
861
850
{
 
851
  if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
852
  {
 
853
    maybe_die(EX_DRIZZLEERR, _("Got error: %s %s"),
 
854
              drizzle_result_error_code(res), when);
 
855
    drizzle_result_free(res);
 
856
  }
 
857
  else
 
858
    maybe_die(EX_DRIZZLEERR, _("Got error: %s %s"), ret, when);
862
859
 
863
 
  maybe_die(EX_DRIZZLEERR, _("Got error: %d: %s %s"),
864
 
          drizzleclient_errno(drizzle_arg), drizzleclient_error(drizzle_arg), when);
865
860
  return;
866
861
}
867
862
 
946
941
    1               error
947
942
*/
948
943
 
949
 
static int drizzleclient_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
950
 
                                         const char *query)
 
944
static int drizzleclient_query_with_error_report(drizzle_con_st *con,
 
945
                                                 drizzle_result_st *result,
 
946
                                                 const char *query_str,
 
947
                                                 bool no_buffer)
951
948
{
952
 
  if (drizzleclient_query(drizzle_con, query) ||
953
 
      (res && !((*res)= drizzleclient_store_result(drizzle_con))))
954
 
  {
 
949
  drizzle_return_t ret;
 
950
 
 
951
  if (drizzle_query_str(con, result, query_str, &ret) == NULL ||
 
952
      ret != DRIZZLE_RETURN_OK)
 
953
  {
 
954
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
955
    {
 
956
      maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
 
957
                query_str, drizzle_result_error(result),
 
958
                drizzle_result_error_code(result));
 
959
      drizzle_result_free(result);
 
960
    }
 
961
    else
 
962
    {
 
963
      maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
 
964
                query_str, drizzle_con_error(con), ret);
 
965
    }
 
966
    return 1;
 
967
  }
 
968
 
 
969
  if (no_buffer)
 
970
    ret= drizzle_column_buffer(result);
 
971
  else
 
972
    ret= drizzle_result_buffer(result);
 
973
  if (ret != DRIZZLE_RETURN_OK)
 
974
  {
 
975
    drizzle_result_free(result);
955
976
    maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
956
 
            query, drizzleclient_error(drizzle_con), drizzleclient_errno(drizzle_con));
 
977
              query_str, drizzle_con_error(con), ret);
957
978
    return 1;
958
979
  }
 
980
 
959
981
  return 0;
960
982
}
961
983
 
1000
1022
    first_error= error;
1001
1023
  if (ignore_errors)
1002
1024
    return;
1003
 
  if (drizzle)
1004
 
    drizzleclient_close(drizzle);
 
1025
  drizzle_con_free(&dcon);
 
1026
  drizzle_free(&drizzle);
1005
1027
  free_resources();
1006
1028
  exit(error);
1007
1029
}
1013
1035
 
1014
1036
static int connect_to_db(char *host, char *user,char *passwd)
1015
1037
{
 
1038
  drizzle_return_t ret;
 
1039
 
1016
1040
  verbose_msg(_("-- Connecting to %s...\n"), host ? host : "localhost");
1017
 
  drizzleclient_create(&drizzleclient_connection);
1018
 
  if (opt_compress)
1019
 
    drizzleclient_options(&drizzleclient_connection,DRIZZLE_OPT_COMPRESS,NULL);
1020
 
  if (!(drizzle= drizzleclient_connect(&drizzleclient_connection,host,user,passwd,
1021
 
                                  NULL,opt_drizzle_port, NULL,
1022
 
                                  0)))
 
1041
  drizzle_create(&drizzle);
 
1042
  drizzle_con_create(&drizzle, &dcon);
 
1043
  drizzle_con_set_tcp(&dcon, host, opt_drizzle_port);
 
1044
  drizzle_con_set_auth(&dcon, user, passwd);
 
1045
  ret= drizzle_con_connect(&dcon);
 
1046
  if (ret != DRIZZLE_RETURN_OK)
1023
1047
  {
1024
 
    DB_error(&drizzleclient_connection, "when trying to connect");
 
1048
    DB_error(NULL, ret, "when trying to connect");
1025
1049
    return(1);
1026
1050
  }
1027
1051
 
1035
1059
static void dbDisconnect(char *host)
1036
1060
{
1037
1061
  verbose_msg(_("-- Disconnecting from %s...\n"), host ? host : "localhost");
1038
 
  drizzleclient_close(drizzle);
 
1062
  drizzle_con_free(&dcon);
 
1063
  drizzle_free(&drizzle);
1039
1064
} /* dbDisconnect */
1040
1065
 
1041
1066
 
1046
1071
  if (!(tmp=(char*) malloc(length*2+1)))
1047
1072
    die(EX_DRIZZLEERR, _("Couldn't allocate memory"));
1048
1073
 
1049
 
  drizzleclient_escape_string(tmp, pos, length);
 
1074
  drizzle_escape_string(tmp, pos, length);
1050
1075
  fputc('\'', file);
1051
1076
  fputs(tmp, file);
1052
1077
  fputc('\'', file);
1303
1328
*/
1304
1329
 
1305
1330
static void print_xml_row(FILE *xml_file, const char *row_name,
1306
 
                          DRIZZLE_RES *tableRes, DRIZZLE_ROW *row)
 
1331
                          drizzle_result_st *tableRes, drizzle_row_t *row)
1307
1332
{
1308
1333
  uint32_t i;
1309
 
  DRIZZLE_FIELD *field;
1310
 
  uint32_t *lengths= drizzleclient_fetch_lengths(tableRes);
 
1334
  drizzle_column_st *column;
 
1335
  size_t *lengths= drizzle_row_field_sizes(tableRes);
1311
1336
 
1312
1337
  fprintf(xml_file, "\t\t<%s", row_name);
1313
1338
  check_io(xml_file);
1314
 
  drizzleclient_field_seek(tableRes, 0);
1315
 
  for (i= 0; (field= drizzleclient_fetch_field(tableRes)); i++)
 
1339
  drizzle_column_seek(tableRes, 0);
 
1340
  for (i= 0; (column= drizzle_column_next(tableRes)); i++)
1316
1341
  {
1317
1342
    if ((*row)[i])
1318
1343
    {
1319
1344
      fputc(' ', xml_file);
1320
 
      print_quoted_xml(xml_file, field->name, field->name_length);
 
1345
      print_quoted_xml(xml_file, drizzle_column_name(column),
 
1346
                       strlen(drizzle_column_name(column)));
1321
1347
      fputs("=\"", xml_file);
1322
1348
      print_quoted_xml(xml_file, (*row)[i], lengths[i]);
1323
1349
      fputc('"', xml_file);
1373
1399
  bool    init=0, delayed, write_data, complete_insert;
1374
1400
  char       *result_table, *opt_quoted_table;
1375
1401
  const char *insert_option;
1376
 
  char       name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3];
1377
 
  char       table_buff2[NAME_LEN*2+3], query_buff[QUERY_LENGTH];
 
1402
  char       name_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE+3];
 
1403
  char       table_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE*2+3];
 
1404
  char       table_buff2[DRIZZLE_MAX_TABLE_SIZE*2+3];
 
1405
  char       query_buff[QUERY_LENGTH];
1378
1406
  FILE       *sql_file= md_result_file;
1379
 
  DRIZZLE_RES  *result;
1380
 
  DRIZZLE_ROW  row;
 
1407
  drizzle_result_st result;
 
1408
  drizzle_row_t  row;
1381
1409
 
1382
1410
  *ignore_flag= check_if_ignore_table(table, table_type);
1383
1411
 
1417
1445
    {
1418
1446
      /* Make an sql-file, if path was given iow. option -T was given */
1419
1447
      char buff[20+FN_REFLEN];
1420
 
      const DRIZZLE_FIELD *field;
 
1448
      const drizzle_column_st *column;
1421
1449
 
1422
1450
      snprintf(buff, sizeof(buff), "show create table %s", result_table);
1423
1451
 
1424
 
      if (drizzleclient_query_with_error_report(drizzle, &result, buff))
 
1452
      if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1425
1453
        return false;
1426
1454
 
1427
1455
      if (path)
1428
1456
      {
1429
1457
        if (!(sql_file= open_sql_file_for_table(table)))
 
1458
        {
 
1459
          drizzle_result_free(&result);
1430
1460
          return false;
 
1461
        }
1431
1462
 
1432
1463
        write_header(sql_file, db);
1433
1464
      }
1446
1477
        check_io(sql_file);
1447
1478
      }
1448
1479
 
1449
 
      field= drizzleclient_fetch_field_direct(result, 0);
 
1480
      column= drizzle_column_index(&result, 0);
1450
1481
 
1451
 
      row= drizzleclient_fetch_row(result);
 
1482
      row= drizzle_row_next(&result);
1452
1483
 
1453
1484
      fprintf(sql_file, "%s;\n", row[1]);
1454
1485
 
1455
1486
      check_io(sql_file);
1456
 
      drizzleclient_free_result(result);
 
1487
      drizzle_result_free(&result);
1457
1488
    }
 
1489
 
1458
1490
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1459
1491
             result_table);
1460
 
    if (drizzleclient_query_with_error_report(drizzle, &result, query_buff))
 
1492
 
 
1493
    if (drizzleclient_query_with_error_report(&dcon, &result, query_buff, false))
1461
1494
    {
1462
1495
      if (path)
1463
1496
        fclose(sql_file);
1491
1524
      }
1492
1525
    }
1493
1526
 
1494
 
    while ((row= drizzleclient_fetch_row(result)))
 
1527
    while ((row= drizzle_row_next(&result)))
1495
1528
    {
1496
1529
      if (complete_insert)
1497
1530
      {
1503
1536
        insert_pat.append(quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1504
1537
      }
1505
1538
    }
1506
 
    *num_fields= drizzleclient_num_rows(result);
1507
 
    drizzleclient_free_result(result);
 
1539
    *num_fields= drizzle_result_row_count(&result);
 
1540
    drizzle_result_free(&result);
1508
1541
  }
1509
1542
  else
1510
1543
  {
1511
1544
    verbose_msg(_("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n"),
1512
 
                my_progname, drizzleclient_error(drizzle));
 
1545
                my_progname, drizzle_con_error(&dcon));
1513
1546
 
1514
1547
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1515
1548
             result_table);
1516
 
    if (drizzleclient_query_with_error_report(drizzle, &result, query_buff))
 
1549
    if (drizzleclient_query_with_error_report(&dcon, &result, query_buff, false))
1517
1550
      return false;
1518
1551
 
1519
1552
    /* Make an sql-file, if path was given iow. option -T was given */
1522
1555
      if (path)
1523
1556
      {
1524
1557
        if (!(sql_file= open_sql_file_for_table(table)))
 
1558
        {
 
1559
          drizzle_result_free(&result);
1525
1560
          return false;
 
1561
        }
1526
1562
        write_header(sql_file, db);
1527
1563
      }
1528
1564
      if (!opt_xml && opt_comments)
1557
1593
      }
1558
1594
    }
1559
1595
 
1560
 
    while ((row= drizzleclient_fetch_row(result)))
 
1596
    while ((row= drizzle_row_next(&result)))
1561
1597
    {
1562
 
      uint32_t *lengths= drizzleclient_fetch_lengths(result);
 
1598
      size_t *lengths= drizzle_row_field_sizes(&result);
1563
1599
      if (init)
1564
1600
      {
1565
1601
        if (!opt_xml && !opt_no_create_info)
1577
1613
      {
1578
1614
        if (opt_xml)
1579
1615
        {
1580
 
          print_xml_row(sql_file, "field", result, &row);
 
1616
          print_xml_row(sql_file, "field", &result, &row);
1581
1617
          continue;
1582
1618
        }
1583
1619
 
1601
1637
        check_io(sql_file);
1602
1638
      }
1603
1639
    }
1604
 
    *num_fields= drizzleclient_num_rows(result);
1605
 
    drizzleclient_free_result(result);
 
1640
    *num_fields= drizzle_result_row_count(&result);
 
1641
    drizzle_result_free(&result);
 
1642
 
1606
1643
    if (!opt_no_create_info)
1607
1644
    {
1608
1645
      /* Make an sql-file, if path was given iow. option -T was given */
1609
1646
      char buff[20+FN_REFLEN];
1610
1647
      uint32_t keynr,primary_key;
1611
1648
      snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1612
 
      if (drizzleclient_query_with_error_report(drizzle, &result, buff))
 
1649
      if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1613
1650
      {
1614
 
        if (drizzleclient_errno(drizzle) == ER_WRONG_OBJECT)
1615
 
        {
1616
 
          /* it is VIEW */
1617
 
          fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1618
 
          goto continue_xml;
1619
 
        }
1620
 
        fprintf(stderr, _("%s: Can't get keys for table %s (%s)\n"),
1621
 
                my_progname, result_table, drizzleclient_error(drizzle));
 
1651
        fprintf(stderr, _("%s: Can't get keys for table %s\n"),
 
1652
                my_progname, result_table);
1622
1653
        if (path)
1623
1654
          fclose(sql_file);
1624
1655
        return false;
1627
1658
      /* Find first which key is primary key */
1628
1659
      keynr=0;
1629
1660
      primary_key=INT_MAX;
1630
 
      while ((row= drizzleclient_fetch_row(result)))
 
1661
      while ((row= drizzle_row_next(&result)))
1631
1662
      {
1632
1663
        if (atoi(row[3]) == 1)
1633
1664
        {
1643
1674
          }
1644
1675
        }
1645
1676
      }
1646
 
      drizzleclient_data_seek(result,0);
 
1677
      drizzle_row_seek(&result,0);
1647
1678
      keynr=0;
1648
 
      while ((row= drizzleclient_fetch_row(result)))
 
1679
      while ((row= drizzle_row_next(&result)))
1649
1680
      {
1650
1681
        if (opt_xml)
1651
1682
        {
1652
 
          print_xml_row(sql_file, "key", result, &row);
 
1683
          print_xml_row(sql_file, "key", &result, &row);
1653
1684
          continue;
1654
1685
        }
1655
1686
 
1673
1704
          fprintf(sql_file, " (%s)",row[7]);      /* Sub key */
1674
1705
        check_io(sql_file);
1675
1706
      }
1676
 
      drizzleclient_free_result(result);
 
1707
      drizzle_result_free(&result);
1677
1708
      if (!opt_xml)
1678
1709
      {
1679
1710
        if (keynr)
1684
1715
      /* Get DRIZZLE specific create options */
1685
1716
      if (create_options)
1686
1717
      {
1687
 
        char show_name_buff[NAME_LEN*2+2+24];
 
1718
        char show_name_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE*2+2+24];
1688
1719
 
1689
1720
        /* Check memory for quote_for_like() */
1690
1721
        snprintf(buff, sizeof(buff), "show table status like %s",
1691
1722
                 quote_for_like(table, show_name_buff));
1692
1723
 
1693
 
        if (drizzleclient_query_with_error_report(drizzle, &result, buff))
 
1724
        if (!drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1694
1725
        {
1695
 
          if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
1696
 
          {                                     /* If old DRIZZLE version */
1697
 
            verbose_msg(_("-- Warning: Couldn't get status information for " \
1698
 
                        "table %s (%s)\n"), result_table,drizzleclient_error(drizzle));
 
1726
          if (!(row= drizzle_row_next(&result)))
 
1727
          {
 
1728
            fprintf(stderr,
 
1729
                    _("Error: Couldn't read status information for table %s\n"),
 
1730
                    result_table);
1699
1731
          }
1700
 
        }
1701
 
        else if (!(row= drizzleclient_fetch_row(result)))
1702
 
        {
1703
 
          fprintf(stderr,
1704
 
                  _("Error: Couldn't read status information for table %s (%s)\n"),
1705
 
                  result_table,drizzleclient_error(drizzle));
1706
 
        }
1707
 
        else
1708
 
        {
1709
 
          if (opt_xml)
1710
 
            print_xml_row(sql_file, "options", result, &row);
1711
1732
          else
1712
1733
          {
1713
 
            fputs("/*!",sql_file);
1714
 
            print_value(sql_file,result,row,"engine=","Engine",0);
1715
 
            print_value(sql_file,result,row,"","Create_options",0);
1716
 
            print_value(sql_file,result,row,"comment=","Comment",1);
 
1734
            if (opt_xml)
 
1735
              print_xml_row(sql_file, "options", &result, &row);
 
1736
            else
 
1737
            {
 
1738
              fputs("/*!",sql_file);
 
1739
              print_value(sql_file,&result,row,"engine=","Engine",0);
 
1740
              print_value(sql_file,&result,row,"","Create_options",0);
 
1741
              print_value(sql_file,&result,row,"comment=","Comment",1);
1717
1742
 
1718
 
            fputs(" */",sql_file);
1719
 
            check_io(sql_file);
 
1743
              fputs(" */",sql_file);
 
1744
              check_io(sql_file);
 
1745
            }
1720
1746
          }
 
1747
          drizzle_result_free(&result);
1721
1748
        }
1722
 
        drizzleclient_free_result(result);              /* Is always safe to free */
1723
1749
      }
1724
 
continue_xml:
1725
1750
      if (!opt_xml)
1726
1751
        fputs(";\n", sql_file);
1727
1752
      else
1825
1850
static void dump_table(char *table, char *db)
1826
1851
{
1827
1852
  char ignore_flag;
1828
 
  char buf[200], table_buff[NAME_LEN+3];
 
1853
  char table_buff[DRIZZLE_MAX_TABLE_SIZE+3];
1829
1854
  string query_string;
1830
 
  char table_type[NAME_LEN];
1831
 
  char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table;
 
1855
  char table_type[DRIZZLE_MAX_TABLE_SIZE];
 
1856
  char *result_table, table_buff2[DRIZZLE_MAX_TABLE_SIZE*2+3], *opt_quoted_table;
1832
1857
  int error= 0;
1833
1858
  uint32_t rownr, row_break, total_length, init_length;
1834
1859
  uint64_t num_fields= 0;
1835
 
  DRIZZLE_RES     *res;
1836
 
  DRIZZLE_FIELD   *field;
1837
 
  DRIZZLE_ROW     row;
 
1860
  drizzle_return_t ret;
 
1861
  drizzle_result_st result;
 
1862
  drizzle_column_st *column;
 
1863
  drizzle_row_t row;
1838
1864
 
1839
1865
 
1840
1866
  /*
1926
1952
      query_string.append( order_by);
1927
1953
    }
1928
1954
 
1929
 
    if (drizzleclient_real_query(drizzle, query_string.c_str(), query_string.length()))
 
1955
    if (drizzle_query(&dcon, &result, query_string.c_str(),
 
1956
                      query_string.length(), &ret) == NULL ||
 
1957
        ret != DRIZZLE_RETURN_OK)
1930
1958
    {
1931
 
      DB_error(drizzle, _("when executing 'SELECT INTO OUTFILE'"));
 
1959
      DB_error(&result, ret, _("when executing 'SELECT INTO OUTFILE'"));
 
1960
 
1932
1961
      return;
1933
1962
    }
 
1963
    drizzle_result_free(&result);
1934
1964
  }
1935
1965
  else
1936
1966
  {
1971
2001
      fputs("\n", md_result_file);
1972
2002
      check_io(md_result_file);
1973
2003
    }
1974
 
    if (drizzleclient_query_with_error_report(drizzle, 0, query_string.c_str()))
1975
 
    {
1976
 
      DB_error(drizzle, _("when retrieving data from server"));
1977
 
      goto err;
1978
 
    }
1979
 
    if (quick)
1980
 
      res=drizzleclient_use_result(drizzle);
1981
 
    else
1982
 
      res=drizzleclient_store_result(drizzle);
1983
 
    if (!res)
1984
 
    {
1985
 
      DB_error(drizzle, _("when retrieving data from server"));
 
2004
    if (drizzleclient_query_with_error_report(&dcon, &result,
 
2005
                                              query_string.c_str(), quick))
 
2006
    {
1986
2007
      goto err;
1987
2008
    }
1988
2009
 
1989
2010
    verbose_msg(_("-- Retrieving rows...\n"));
1990
 
    if (drizzleclient_num_fields(res) != num_fields)
 
2011
    if (drizzle_result_column_count(&result) != num_fields)
1991
2012
    {
1992
2013
      fprintf(stderr,_("%s: Error in field count for table: %s !  Aborting.\n"),
1993
2014
              my_progname, result_table);
1994
2015
      error= EX_CONSCHECK;
 
2016
      drizzle_result_free(&result);
1995
2017
      goto err;
1996
2018
    }
1997
2019
 
2008
2030
      check_io(md_result_file);
2009
2031
    }
2010
2032
 
2011
 
    total_length= opt_net_buffer_length;                /* Force row break */
 
2033
    total_length= DRIZZLE_MAX_LINE_LENGTH;                /* Force row break */
2012
2034
    row_break=0;
2013
2035
    rownr=0;
2014
2036
    init_length=(uint32_t) insert_pat.length()+4;
2021
2043
      check_io(md_result_file);
2022
2044
    }
2023
2045
 
2024
 
    while ((row= drizzleclient_fetch_row(res)))
 
2046
    row= NULL;
 
2047
 
 
2048
    while (1)
2025
2049
    {
2026
2050
      uint32_t i;
2027
 
      uint32_t *lengths= drizzleclient_fetch_lengths(res);
 
2051
      size_t *lengths;
 
2052
 
 
2053
      if (quick)
 
2054
      {
 
2055
        if (row)
 
2056
          drizzle_row_free(&result, row);
 
2057
 
 
2058
        row= drizzle_row_buffer(&result, &ret);
 
2059
        if (ret != DRIZZLE_RETURN_OK)
 
2060
        {
 
2061
          fprintf(stderr,
 
2062
                _("%s: Error reading rows for table: %s (%d:%s) ! Aborting.\n"),
 
2063
                  my_progname, result_table, ret, drizzle_con_error(&dcon));
 
2064
          drizzle_result_free(&result);
 
2065
          goto err;
 
2066
        }
 
2067
      }
 
2068
      else
 
2069
        row= drizzle_row_next(&result);
 
2070
 
 
2071
      if (row == NULL)
 
2072
        break;
 
2073
 
 
2074
      lengths= drizzle_row_field_sizes(&result);
 
2075
 
2028
2076
      rownr++;
2029
2077
      if ((rownr % show_progress_size) == 0)
2030
2078
      {
2035
2083
        fputs(insert_pat.c_str(),md_result_file);
2036
2084
        check_io(md_result_file);
2037
2085
      }
2038
 
      drizzleclient_field_seek(res,0);
 
2086
      drizzle_column_seek(&result,0);
2039
2087
 
2040
2088
      if (opt_xml)
2041
2089
      {
2043
2091
        check_io(md_result_file);
2044
2092
      }
2045
2093
 
2046
 
      for (i= 0; i < drizzleclient_num_fields(res); i++)
 
2094
      for (i= 0; i < drizzle_result_column_count(&result); i++)
2047
2095
      {
2048
2096
        int is_blob;
2049
2097
        uint32_t length= lengths[i];
2050
2098
 
2051
 
        if (!(field= drizzleclient_fetch_field(res)))
 
2099
        if (!(column= drizzle_column_next(&result)))
2052
2100
          die(EX_CONSCHECK,
2053
2101
                      _("Not enough fields from table %s! Aborting.\n"),
2054
2102
                      result_table);
2058
2106
           we have not a BLOB but a TEXT column.
2059
2107
           we'll dump in hex only BLOB columns.
2060
2108
        */
2061
 
        is_blob= (opt_hex_blob && field->charsetnr == 63 &&
2062
 
                  (field->type == DRIZZLE_TYPE_VARCHAR ||
2063
 
                   field->type == DRIZZLE_TYPE_BLOB)) ? 1 : 0;
 
2109
        is_blob= (opt_hex_blob && drizzle_column_charset(column) == 63 &&
 
2110
                  (drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_VARCHAR ||
 
2111
                   drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_BLOB)) ? 1 : 0;
2064
2112
        if (extended_insert && !opt_xml)
2065
2113
        {
2066
2114
          if (i == 0)
2075
2123
          {
2076
2124
            if (length)
2077
2125
            {
2078
 
              if (!(field->type & NUM_FLAG))
 
2126
              if (!(drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_NUM))
2079
2127
              {
2080
2128
                /*
2081
2129
                  "length * 2 + 2" is OK for both HEX and non-HEX modes:
2090
2138
                if (opt_hex_blob && is_blob)
2091
2139
                {
2092
2140
                  extended_row.append("0x");
2093
 
                  drizzleclient_drizzleclient_octet2hex(tmp_str, row[i], length);
 
2141
                  drizzle_hex_string(tmp_str, row[i], length);
2094
2142
                  extended_row.append(tmp_str);
2095
2143
                }
2096
2144
                else
2097
2145
                {
2098
2146
                  extended_row.append("'");
2099
 
                  drizzleclient_escape_string(tmp_str,
2100
 
                                        row[i],length);
 
2147
                  drizzle_escape_string(tmp_str, row[i],length);
2101
2148
                  extended_row.append(tmp_str);
2102
2149
                  extended_row.append("'");
2103
2150
                }
2131
2178
          }
2132
2179
          if (row[i])
2133
2180
          {
2134
 
            if (!(field->type & NUM_FLAG))
 
2181
            if (!(drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_NUM))
2135
2182
            {
2136
2183
              if (opt_xml)
2137
2184
              {
2139
2186
                {
2140
2187
                  /* Define xsi:type="xs:hexBinary" for hex encoded data */
2141
2188
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2142
 
                                field->name, "xsi:type=", "xs:hexBinary", NULL);
 
2189
                                drizzle_column_name(column), "xsi:type=", "xs:hexBinary", NULL);
2143
2190
                  print_blob_as_hex(md_result_file, row[i], length);
2144
2191
                }
2145
2192
                else
2146
2193
                {
2147
2194
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2148
 
                                field->name, NULL);
 
2195
                                drizzle_column_name(column), NULL);
2149
2196
                  print_quoted_xml(md_result_file, row[i], length);
2150
2197
                }
2151
2198
                fputs("</field>\n", md_result_file);
2165
2212
              if (opt_xml)
2166
2213
              {
2167
2214
                print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2168
 
                        field->name, NULL);
 
2215
                        drizzle_column_name(column), NULL);
2169
2216
                fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
2170
2217
                      md_result_file);
2171
2218
                fputs("</field>\n", md_result_file);
2184
2231
              fputs("NULL", md_result_file);
2185
2232
            else
2186
2233
              print_xml_null_tag(md_result_file, "\t\t", "field name=",
2187
 
                                 field->name, "\n");
 
2234
                                 drizzle_column_name(column), "\n");
2188
2235
          }
2189
2236
          check_io(md_result_file);
2190
2237
        }
2201
2248
        uint32_t row_length;
2202
2249
        extended_row.append(")");
2203
2250
        row_length= 2 + extended_row.length();
2204
 
        if (total_length + row_length < opt_net_buffer_length)
 
2251
        if (total_length + row_length < DRIZZLE_MAX_LINE_LENGTH)
2205
2252
        {
2206
2253
          total_length+= row_length;
2207
2254
          fputc(',',md_result_file);            /* Always row break */
2233
2280
      fputs(";\n", md_result_file);             /* If not empty table */
2234
2281
    fflush(md_result_file);
2235
2282
    check_io(md_result_file);
2236
 
    if (drizzleclient_errno(drizzle))
2237
 
    {
2238
 
      snprintf(buf, sizeof(buf),
2239
 
               _("%s: Error %d: %s when dumping table %s at row: %d\n"),
2240
 
               my_progname,
2241
 
               drizzleclient_errno(drizzle),
2242
 
               drizzleclient_error(drizzle),
2243
 
               result_table,
2244
 
               rownr);
2245
 
      fputs(buf,stderr);
2246
 
      error= EX_CONSCHECK;
2247
 
      goto err;
2248
 
    }
2249
2283
 
2250
2284
    /* Moved enable keys to before unlock per bug 15977 */
2251
2285
    if (opt_disable_keys)
2264
2298
      fprintf(md_result_file, "commit;\n");
2265
2299
      check_io(md_result_file);
2266
2300
    }
2267
 
    drizzleclient_free_result(res);
 
2301
    drizzle_result_free(&result);
2268
2302
  }
2269
2303
  return;
2270
2304
 
2276
2310
 
2277
2311
static char *getTableName(int reset)
2278
2312
{
2279
 
  static DRIZZLE_RES *res= NULL;
2280
 
  DRIZZLE_ROW    row;
 
2313
  static drizzle_result_st result;
 
2314
  static bool have_result= false;
 
2315
  drizzle_row_t row;
2281
2316
 
2282
 
  if (!res)
 
2317
  if (!have_result)
2283
2318
  {
2284
 
    if (!(res= drizzleclient_list_tables(drizzle,NULL)))
2285
 
      return(NULL);
 
2319
    if (drizzleclient_query_with_error_report(&dcon, &result, "SHOW TABLES", false))
 
2320
      return NULL;
 
2321
    have_result= true;
2286
2322
  }
2287
 
  if ((row= drizzleclient_fetch_row(res)))
2288
 
    return((char*) row[0]);
 
2323
 
 
2324
  if ((row= drizzle_row_next(&result)))
 
2325
    return row[0];
2289
2326
 
2290
2327
  if (reset)
2291
 
    drizzleclient_data_seek(res,0);      /* We want to read again */
 
2328
    drizzle_row_seek(&result, 0);
2292
2329
  else
2293
2330
  {
2294
 
    drizzleclient_free_result(res);
2295
 
    res= NULL;
 
2331
    drizzle_result_free(&result);
 
2332
    have_result= false;
2296
2333
  }
2297
 
  return(NULL);
 
2334
  return NULL;
2298
2335
} /* getTableName */
2299
2336
 
2300
2337
 
2301
2338
static int dump_all_databases()
2302
2339
{
2303
 
  DRIZZLE_ROW row;
2304
 
  DRIZZLE_RES *tableres;
 
2340
  drizzle_row_t row;
 
2341
  drizzle_result_st tableres;
2305
2342
  int result=0;
2306
2343
 
2307
 
  if (drizzleclient_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
 
2344
  if (drizzleclient_query_with_error_report(&dcon, &tableres, "SHOW DATABASES", false))
2308
2345
    return 1;
2309
 
  while ((row= drizzleclient_fetch_row(tableres)))
 
2346
  while ((row= drizzle_row_next(&tableres)))
2310
2347
  {
2311
2348
    if (dump_all_tables_in_db(row[0]))
2312
2349
      result=1;
2313
2350
  }
 
2351
  drizzle_result_free(&tableres);
2314
2352
  return result;
2315
2353
}
2316
2354
/* dump_all_databases */
2345
2383
 
2346
2384
int init_dumping_tables(char *qdatabase)
2347
2385
{
2348
 
 
2349
 
 
2350
2386
  if (!opt_create_db)
2351
2387
  {
2352
2388
    char qbuf[256];
2353
 
    DRIZZLE_ROW row;
2354
 
    DRIZZLE_RES *dbinfo;
 
2389
    drizzle_row_t row;
 
2390
    drizzle_result_st result;
 
2391
    drizzle_return_t ret;
2355
2392
 
2356
2393
    snprintf(qbuf, sizeof(qbuf),
2357
2394
             "SHOW CREATE DATABASE IF NOT EXISTS %s",
2358
2395
             qdatabase);
2359
2396
 
2360
 
    if (drizzleclient_query(drizzle, qbuf) || !(dbinfo = drizzleclient_store_result(drizzle)))
 
2397
    if (drizzle_query_str(&dcon, &result, qbuf, &ret) == NULL ||
 
2398
        ret != DRIZZLE_RETURN_OK)
2361
2399
    {
 
2400
      if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
2401
        drizzle_result_free(&result);
 
2402
 
2362
2403
      /* Old server version, dump generic CREATE DATABASE */
2363
2404
      if (opt_drop_database)
2364
2405
        fprintf(md_result_file,
2370
2411
    }
2371
2412
    else
2372
2413
    {
2373
 
      if (opt_drop_database)
2374
 
        fprintf(md_result_file,
2375
 
                "\nDROP DATABASE IF EXISTS %s;\n",
2376
 
                qdatabase);
2377
 
      row = drizzleclient_fetch_row(dbinfo);
2378
 
      if (row[1])
 
2414
      if (drizzle_result_buffer(&result) == DRIZZLE_RETURN_OK)
2379
2415
      {
2380
 
        fprintf(md_result_file,"\n%s;\n",row[1]);
 
2416
        if (opt_drop_database)
 
2417
          fprintf(md_result_file,
 
2418
                  "\nDROP DATABASE IF EXISTS %s;\n",
 
2419
                  qdatabase);
 
2420
        row = drizzle_row_next(&result);
 
2421
        if (row != NULL && row[1])
 
2422
        {
 
2423
          fprintf(md_result_file,"\n%s;\n",row[1]);
 
2424
        }
2381
2425
      }
2382
 
      drizzleclient_free_result(dbinfo);
 
2426
      drizzle_result_free(&result);
2383
2427
    }
2384
2428
  }
2385
2429
  return(0);
2388
2432
 
2389
2433
static int init_dumping(char *database, int init_func(char*))
2390
2434
{
2391
 
  if (drizzleclient_get_server_version(drizzle) >= 50003 &&
2392
 
      !my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
 
2435
  drizzle_result_st result;
 
2436
  drizzle_return_t ret;
 
2437
 
 
2438
  if (!my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
2393
2439
    return 1;
2394
2440
 
2395
 
  if (drizzleclient_select_db(drizzle, database))
 
2441
  if (drizzle_select_db(&dcon, &result, database, &ret) == NULL ||
 
2442
        ret != DRIZZLE_RETURN_OK)
2396
2443
  {
2397
 
    DB_error(drizzle, _("when selecting the database"));
 
2444
    DB_error(&result, ret, _("when executing 'SELECT INTO OUTFILE'"));
2398
2445
    return 1;                   /* If --force */
2399
2446
  }
 
2447
  drizzle_result_free(&result);
 
2448
 
2400
2449
  if (!path && !opt_xml)
2401
2450
  {
2402
2451
    if (opt_databases || opt_alldbs)
2404
2453
      /*
2405
2454
        length of table name * 2 (if name contains quotes), 2 quotes and 0
2406
2455
      */
2407
 
      char quoted_database_buf[NAME_LEN*2+3];
 
2456
      char quoted_database_buf[DRIZZLE_MAX_DB_SIZE*2+3];
2408
2457
      char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
2409
2458
      if (opt_comments)
2410
2459
      {
2437
2486
{
2438
2487
  char *table;
2439
2488
  uint32_t numrows;
2440
 
  char table_buff[NAME_LEN*2+3];
2441
 
  char hash_key[2*NAME_LEN+2];  /* "db.tablename" */
 
2489
  char table_buff[DRIZZLE_MAX_TABLE_SIZE*2+3];
 
2490
  char hash_key[DRIZZLE_MAX_DB_SIZE+DRIZZLE_MAX_TABLE_SIZE+2];  /* "db.tablename" */
2442
2491
  char *afterdot;
 
2492
  drizzle_result_st result;
 
2493
  drizzle_return_t ret;
2443
2494
 
2444
2495
  afterdot= strcpy(hash_key, database) + strlen(database);
2445
2496
  *afterdot++= '.';
2461
2512
        query.append( " READ LOCAL,");
2462
2513
      }
2463
2514
    }
2464
 
    if (numrows && drizzleclient_real_query(drizzle, query.c_str(), query.length()-1))
2465
 
      DB_error(drizzle, _("when using LOCK TABLES"));
2466
 
            /* We shall continue here, if --force was given */
 
2515
    if (numrows)
 
2516
    {
 
2517
      if (drizzle_query(&dcon, &result, query.c_str(),
 
2518
                        query.length()-1, &ret) == NULL ||
 
2519
          ret != DRIZZLE_RETURN_OK)
 
2520
      {
 
2521
        DB_error(&result, ret, _("when using LOCK TABLES"));
 
2522
        /* We shall continue here, if --force was given */
 
2523
      }
 
2524
      else
 
2525
        drizzle_result_free(&result);
 
2526
    }
2467
2527
    query.clear();
2468
2528
  }
2469
2529
  if (flush_logs)
2470
2530
  {
2471
 
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
2472
 
      DB_error(drizzle, _("when doing refresh"));
2473
 
           /* We shall continue here, if --force was given */
 
2531
    if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
 
2532
        ret != DRIZZLE_RETURN_OK)
 
2533
    {
 
2534
      DB_error(&result, ret, _("when doing refresh"));
 
2535
      /* We shall continue here, if --force was given */
 
2536
    }
 
2537
    else
 
2538
      drizzle_result_free(&result);
2474
2539
  }
2475
2540
  while ((table= getTableName(0)))
2476
2541
  {
2488
2553
    check_io(md_result_file);
2489
2554
  }
2490
2555
  if (lock_tables)
2491
 
    drizzleclient_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
 
2556
  {
 
2557
    if (!drizzleclient_query_with_error_report(&dcon, &result, "UNLOCK TABLES", false))
 
2558
      drizzle_result_free(&result);
 
2559
  }
2492
2560
 
2493
2561
  return(0);
2494
2562
} /* dump_all_tables_in_db */
2508
2576
static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root)
2509
2577
{
2510
2578
  char *name= 0;
2511
 
  DRIZZLE_RES  *table_res;
2512
 
  DRIZZLE_ROW  row;
2513
 
  char query[50 + 2*NAME_LEN];
 
2579
  drizzle_result_st result;
 
2580
  drizzle_row_t  row;
 
2581
  char query[50 + 2*DRIZZLE_MAX_TABLE_SIZE];
2514
2582
  char show_name_buff[FN_REFLEN];
 
2583
  uint64_t num_rows;
2515
2584
 
2516
2585
 
2517
2586
  /* Check memory for quote_for_like() */
2519
2588
  snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2520
2589
           quote_for_like(old_table_name, show_name_buff));
2521
2590
 
2522
 
  if (drizzleclient_query_with_error_report(drizzle, 0, query))
 
2591
  if (drizzleclient_query_with_error_report(&dcon, &result, query, false))
2523
2592
    return NULL;
2524
2593
 
2525
 
  if ((table_res= drizzleclient_store_result(drizzle)))
 
2594
  num_rows= drizzle_result_row_count(&result);
 
2595
  if (num_rows > 0)
2526
2596
  {
2527
 
    uint64_t num_rows= drizzleclient_num_rows(table_res);
2528
 
    if (num_rows > 0)
2529
 
    {
2530
 
      uint32_t *lengths;
2531
 
      /*
2532
 
        Return first row
2533
 
        TODO: Return all matching rows
2534
 
      */
2535
 
      row= drizzleclient_fetch_row(table_res);
2536
 
      lengths= drizzleclient_fetch_lengths(table_res);
2537
 
      name= strmake_root(root, row[0], lengths[0]);
2538
 
    }
2539
 
    drizzleclient_free_result(table_res);
 
2597
    size_t *lengths;
 
2598
    /*
 
2599
      Return first row
 
2600
      TODO: Return all matching rows
 
2601
    */
 
2602
    row= drizzle_row_next(&result);
 
2603
    lengths= drizzle_row_field_sizes(&result);
 
2604
    name= strmake_root(root, row[0], lengths[0]);
2540
2605
  }
 
2606
  drizzle_result_free(&result);
 
2607
 
2541
2608
  return(name);
2542
2609
}
2543
2610
 
2544
2611
 
2545
2612
static int dump_selected_tables(char *db, char **table_names, int tables)
2546
2613
{
2547
 
  char table_buff[NAME_LEN*2+3];
 
2614
  char table_buff[DRIZZLE_MAX_TABLE_SIZE*2+3];
2548
2615
  string lock_tables_query("LOCK TABLES ");
2549
2616
  MEM_ROOT root;
2550
2617
  char **dump_tables, **pos, **end;
 
2618
  drizzle_result_st result;
 
2619
  drizzle_return_t ret;
2551
2620
 
2552
2621
 
2553
2622
  if (init_dumping(db, init_dumping_tables))
2584
2653
 
2585
2654
  if (lock_tables)
2586
2655
  {
2587
 
    if (drizzleclient_real_query(drizzle, lock_tables_query.c_str(),
2588
 
                         lock_tables_query.length()-1))
 
2656
    if (drizzle_query(&dcon, &result, lock_tables_query.c_str(),
 
2657
                      lock_tables_query.length()-1, &ret) == NULL ||
 
2658
        ret != DRIZZLE_RETURN_OK)
2589
2659
    {
2590
2660
      if (!ignore_errors)
2591
2661
      {
2592
2662
        free_root(&root, MYF(0));
2593
2663
      }
2594
 
      DB_error(drizzle, _("when doing LOCK TABLES"));
2595
 
       /* We shall countinue here, if --force was given */
 
2664
      DB_error(&result, ret, _("when doing LOCK TABLES"));
 
2665
      /* We shall countinue here, if --force was given */
2596
2666
    }
 
2667
    else
 
2668
      drizzle_result_free(&result);
2597
2669
  }
2598
2670
  if (flush_logs)
2599
2671
  {
2600
 
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
 
2672
    if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
 
2673
        ret != DRIZZLE_RETURN_OK)
2601
2674
    {
2602
2675
      if (!ignore_errors)
2603
2676
        free_root(&root, MYF(0));
2604
 
      DB_error(drizzle, _("when doing refresh"));
 
2677
      DB_error(&result, ret, _("when doing refresh"));
 
2678
      /* We shall countinue here, if --force was given */
2605
2679
    }
2606
 
     /* We shall countinue here, if --force was given */
 
2680
    else
 
2681
      drizzle_result_free(&result);
2607
2682
  }
2608
2683
  if (opt_xml)
2609
2684
    print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
2621
2696
    check_io(md_result_file);
2622
2697
  }
2623
2698
  if (lock_tables)
2624
 
    drizzleclient_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
 
2699
  {
 
2700
    if (!(drizzleclient_query_with_error_report(&dcon, &result, "UNLOCK TABLES", false)))
 
2701
      drizzle_result_free(&result);
 
2702
  }
2625
2703
  return(0);
2626
2704
} /* dump_selected_tables */
2627
2705
 
2628
2706
 
2629
 
static int do_show_master_status(DRIZZLE *drizzle_con)
 
2707
static int do_show_master_status(drizzle_con_st *drizzle_con)
2630
2708
{
2631
 
  DRIZZLE_ROW row;
2632
 
  DRIZZLE_RES *master;
 
2709
  drizzle_row_t row;
 
2710
  drizzle_result_st master;
2633
2711
  const char *comment_prefix=
2634
2712
    (opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2635
 
  if (drizzleclient_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
 
2713
  if (drizzleclient_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS", false))
2636
2714
  {
2637
2715
    return 1;
2638
2716
  }
2639
2717
  else
2640
2718
  {
2641
 
    row= drizzleclient_fetch_row(master);
 
2719
    row= drizzle_row_next(&master);
2642
2720
    if (row && row[0] && row[1])
2643
2721
    {
2644
2722
      /* SHOW MASTER STATUS reports file and position */
2656
2734
      /* SHOW MASTER STATUS reports nothing and --force is not enabled */
2657
2735
      my_printf_error(0, _("Error: Binlogging on server not active"),
2658
2736
                      MYF(0));
2659
 
      drizzleclient_free_result(master);
 
2737
      drizzle_result_free(&master);
2660
2738
      maybe_exit(EX_DRIZZLEERR);
2661
2739
      return 1;
2662
2740
    }
2663
 
    drizzleclient_free_result(master);
 
2741
    drizzle_result_free(&master);
2664
2742
  }
2665
2743
  return 0;
2666
2744
}
2667
2745
 
2668
 
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
 
2746
static int do_stop_slave_sql(drizzle_con_st *drizzle_con)
2669
2747
{
2670
 
  DRIZZLE_RES *slave;
 
2748
  drizzle_result_st slave;
2671
2749
  /* We need to check if the slave sql is running in the first place */
2672
 
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
 
2750
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2673
2751
    return(1);
2674
2752
  else
2675
2753
  {
2676
 
    DRIZZLE_ROW row= drizzleclient_fetch_row(slave);
 
2754
    drizzle_row_t row= drizzle_row_next(&slave);
2677
2755
    if (row && row[11])
2678
2756
    {
2679
2757
      /* if SLAVE SQL is not running, we don't stop it */
2680
2758
      if (!strcmp(row[11],"No"))
2681
2759
      {
2682
 
        drizzleclient_free_result(slave);
 
2760
        drizzle_result_free(&slave);
2683
2761
        /* Silently assume that they don't have the slave running */
2684
2762
        return(0);
2685
2763
      }
2686
2764
    }
2687
2765
  }
2688
 
  drizzleclient_free_result(slave);
 
2766
  drizzle_result_free(&slave);
2689
2767
 
2690
2768
  /* now, stop slave if running */
2691
 
  if (drizzleclient_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
 
2769
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "STOP SLAVE SQL_THREAD", false))
2692
2770
    return(1);
 
2771
  drizzle_result_free(&slave);
2693
2772
 
2694
2773
  return(0);
2695
2774
}
2712
2791
  return(0);
2713
2792
}
2714
2793
 
2715
 
static int do_show_slave_status(DRIZZLE *drizzle_con)
 
2794
static int do_show_slave_status(drizzle_con_st *drizzle_con)
2716
2795
{
2717
 
  DRIZZLE_RES *slave;
 
2796
  drizzle_result_st slave;
2718
2797
  const char *comment_prefix=
2719
2798
    (opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2720
 
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
 
2799
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2721
2800
  {
2722
2801
    if (!ignore_errors)
2723
2802
    {
2728
2807
  }
2729
2808
  else
2730
2809
  {
2731
 
    DRIZZLE_ROW row= drizzleclient_fetch_row(slave);
 
2810
    drizzle_row_t row= drizzle_row_next(&slave);
2732
2811
    if (row && row[9] && row[21])
2733
2812
    {
2734
2813
      /* SHOW MASTER STATUS reports file and position */
2751
2830
 
2752
2831
      check_io(md_result_file);
2753
2832
    }
2754
 
    drizzleclient_free_result(slave);
 
2833
    drizzle_result_free(&slave);
2755
2834
  }
2756
2835
  return 0;
2757
2836
}
2758
2837
 
2759
 
static int do_start_slave_sql(DRIZZLE *drizzle_con)
 
2838
static int do_start_slave_sql(drizzle_con_st *drizzle_con)
2760
2839
{
2761
 
  DRIZZLE_RES *slave;
 
2840
  drizzle_result_st slave;
2762
2841
  /* We need to check if the slave sql is stopped in the first place */
2763
 
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
 
2842
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2764
2843
    return(1);
2765
2844
  else
2766
2845
  {
2767
 
    DRIZZLE_ROW row= drizzleclient_fetch_row(slave);
 
2846
    drizzle_row_t row= drizzle_row_next(&slave);
2768
2847
    if (row && row[11])
2769
2848
    {
2770
2849
      /* if SLAVE SQL is not running, we don't start it */
2771
2850
      if (!strcmp(row[11],"Yes"))
2772
2851
      {
2773
 
        drizzleclient_free_result(slave);
 
2852
        drizzle_result_free(&slave);
2774
2853
        /* Silently assume that they don't have the slave running */
2775
2854
        return(0);
2776
2855
      }
2777
2856
    }
 
2857
    drizzle_result_free(&slave);
2778
2858
  }
2779
 
  drizzleclient_free_result(slave);
2780
2859
 
2781
2860
  /* now, start slave if stopped */
2782
 
  if (drizzleclient_query_with_error_report(drizzle_con, 0, "START SLAVE"))
 
2861
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "START SLAVE", false))
2783
2862
  {
2784
2863
    my_printf_error(0, _("Error: Unable to start slave"), MYF(0));
2785
2864
    return 1;
2786
2865
  }
 
2866
  drizzle_result_free(&slave);
2787
2867
  return(0);
2788
2868
}
2789
2869
 
2790
2870
 
2791
2871
 
2792
 
static int do_flush_tables_read_lock(DRIZZLE *drizzle_con)
 
2872
static int do_flush_tables_read_lock(drizzle_con_st *drizzle_con)
2793
2873
{
2794
2874
  /*
2795
2875
    We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
2800
2880
    update starts between the two FLUSHes, we have that bad stall.
2801
2881
  */
2802
2882
  return
2803
 
    ( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
 
2883
    ( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES", false) ||
2804
2884
      drizzleclient_query_with_error_report(drizzle_con, 0,
2805
 
                                    "FLUSH TABLES WITH READ LOCK") );
 
2885
                                    "FLUSH TABLES WITH READ LOCK", false) );
2806
2886
}
2807
2887
 
2808
2888
 
2809
 
static int do_unlock_tables(DRIZZLE *drizzle_con)
 
2889
static int do_unlock_tables(drizzle_con_st *drizzle_con)
2810
2890
{
2811
 
  return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
 
2891
  return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES", false);
2812
2892
}
2813
2893
 
2814
 
static int get_bin_log_name(DRIZZLE *drizzle_con,
 
2894
static int get_bin_log_name(drizzle_con_st *drizzle_con,
2815
2895
                            char* buff_log_name, uint32_t buff_len)
2816
2896
{
2817
 
  DRIZZLE_RES *res;
2818
 
  DRIZZLE_ROW row;
 
2897
  drizzle_result_st res;
 
2898
  drizzle_row_t row;
2819
2899
 
2820
 
  if (drizzleclient_query(drizzle_con, "SHOW MASTER STATUS") ||
2821
 
      !(res= drizzleclient_store_result(drizzle)))
 
2900
  if (drizzleclient_query_with_error_report(drizzle_con, &res, "SHOW MASTER STATUS", false))
2822
2901
    return 1;
2823
2902
 
2824
 
  if (!(row= drizzleclient_fetch_row(res)))
 
2903
  if (!(row= drizzle_row_next(&res)))
2825
2904
  {
2826
 
    drizzleclient_free_result(res);
 
2905
    drizzle_result_free(&res);
2827
2906
    return 1;
2828
2907
  }
2829
2908
  /*
2832
2911
  */
2833
2912
  strncpy(buff_log_name, row[0], buff_len - 1);
2834
2913
 
2835
 
  drizzleclient_free_result(res);
 
2914
  drizzle_result_free(&res);
2836
2915
  return 0;
2837
2916
}
2838
2917
 
2839
 
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
 
2918
static int purge_bin_logs_to(drizzle_con_st *drizzle_con, char* log_name)
2840
2919
{
2841
2920
  int err;
2842
2921
  string str= "PURGE BINARY LOGS TO '";
2843
2922
  str.append(log_name);
2844
2923
  str.append("'");
2845
 
  err = drizzleclient_query_with_error_report(drizzle_con, 0, str.c_str());
2846
 
  return err;
 
2924
  drizzle_result_st res;
 
2925
  err= drizzleclient_query_with_error_report(drizzle_con, &res, str.c_str(),
 
2926
                                             false);
 
2927
  if (err)
 
2928
    return err;
 
2929
  drizzle_result_free(&res);
 
2930
  return 0;
2847
2931
}
2848
2932
 
2849
2933
 
2850
 
static int start_transaction(DRIZZLE *drizzle_con)
 
2934
static int start_transaction(drizzle_con_st *drizzle_con)
2851
2935
{
2852
2936
  return (drizzleclient_query_with_error_report(drizzle_con, 0,
2853
2937
                                        "SET SESSION TRANSACTION ISOLATION "
2854
 
                                        "LEVEL REPEATABLE READ") ||
 
2938
                                        "LEVEL REPEATABLE READ", false) ||
2855
2939
          drizzleclient_query_with_error_report(drizzle_con, 0,
2856
2940
                                        "START TRANSACTION "
2857
 
                                        "WITH CONSISTENT SNAPSHOT"));
 
2941
                                        "WITH CONSISTENT SNAPSHOT", false));
2858
2942
}
2859
2943
 
2860
2944
 
2900
2984
 
2901
2985
 
2902
2986
/* Print a value with a prefix on file */
2903
 
static void print_value(FILE *file, DRIZZLE_RES  *result, DRIZZLE_ROW row,
 
2987
static void print_value(FILE *file, drizzle_result_st  *result, drizzle_row_t row,
2904
2988
                        const char *prefix, const char *name,
2905
2989
                        int string_value)
2906
2990
{
2907
 
  DRIZZLE_FIELD   *field;
2908
 
  drizzleclient_field_seek(result, 0);
 
2991
  drizzle_column_st *column;
 
2992
  drizzle_column_seek(result, 0);
2909
2993
 
2910
 
  for ( ; (field= drizzleclient_fetch_field(result)) ; row++)
 
2994
  for ( ; (column= drizzle_column_next(result)) ; row++)
2911
2995
  {
2912
 
    if (!strcmp(field->name,name))
 
2996
    if (!strcmp(drizzle_column_name(column),name))
2913
2997
    {
2914
2998
      if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */
2915
2999
      {
2932
3016
 * Returns const char* of the data in that row or NULL if not found
2933
3017
 */
2934
3018
 
2935
 
static const char* fetch_named_row(DRIZZLE_RES *result, DRIZZLE_ROW row, const char *name)
 
3019
static const char* fetch_named_row(drizzle_result_st *result, drizzle_row_t row, const char *name)
2936
3020
{
2937
 
  DRIZZLE_FIELD   *field;
2938
 
  drizzleclient_field_seek(result, 0);
2939
 
  for ( ; (field= drizzleclient_fetch_field(result)) ; row++)
 
3021
  drizzle_column_st *column;
 
3022
  drizzle_column_seek(result, 0);
 
3023
 
 
3024
  for ( ; (column= drizzle_column_next(result)) ; row++)
2940
3025
  {
2941
 
    if (!strcmp(field->name,name))
 
3026
    if (!strcmp(drizzle_column_name(column),name))
2942
3027
    {
2943
3028
      if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */
2944
3029
      {
2945
 
        drizzleclient_field_seek(result, 0);
 
3030
        drizzle_column_seek(result, 0);
2946
3031
        return row[0];
2947
3032
      }
2948
3033
    }
2949
3034
  }
2950
 
  drizzleclient_field_seek(result, 0);
 
3035
  drizzle_column_seek(result, 0);
2951
3036
  return NULL;
2952
3037
}
2953
3038
 
2981
3066
  char result= IGNORE_NONE;
2982
3067
  char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
2983
3068
  const char *number_of_rows= NULL;
2984
 
  DRIZZLE_RES *res= NULL;
2985
 
  DRIZZLE_ROW row;
 
3069
  drizzle_result_st res;
 
3070
  drizzle_row_t row;
2986
3071
 
2987
3072
  /* Check memory for quote_for_like() */
2988
3073
  assert(2*sizeof(table_name) < sizeof(show_name_buff));
2989
3074
  snprintf(buff, sizeof(buff), "show table status like %s",
2990
3075
           quote_for_like(table_name, show_name_buff));
2991
 
  if (drizzleclient_query_with_error_report(drizzle, &res, buff))
 
3076
  if (drizzleclient_query_with_error_report(&dcon, &res, buff, false))
2992
3077
  {
2993
 
    if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
2994
 
    {                                   /* If old DRIZZLE version */
2995
 
      verbose_msg(_("-- Warning: Couldn't get status information for "
2996
 
                  "table %s (%s)\n"), table_name, drizzleclient_error(drizzle));
2997
 
      return(result);                       /* assume table is ok */
2998
 
    }
 
3078
    return result;
2999
3079
  }
3000
 
  if (!(row= drizzleclient_fetch_row(res)))
 
3080
  if (!(row= drizzle_row_next(&res)))
3001
3081
  {
3002
3082
    fprintf(stderr,
3003
 
            _("Error: Couldn't read status information for table %s (%s)\n"),
3004
 
            table_name, drizzleclient_error(drizzle));
3005
 
    drizzleclient_free_result(res);
 
3083
            _("Error: Couldn't read status information for table %s\n"),
 
3084
            table_name);
 
3085
    drizzle_result_free(&res);
3006
3086
    return(result);                         /* assume table is ok */
3007
3087
  }
3008
3088
  else
3009
3089
  {
3010
 
    if ((number_of_rows= fetch_named_row(res, row, "Rows")) != NULL)
 
3090
    if ((number_of_rows= fetch_named_row(&res, row, "Rows")) != NULL)
3011
3091
    {
3012
3092
      total_rows= strtoul(number_of_rows, NULL, 10);
3013
3093
    }
3019
3099
    the table type is _NOT_ one of these types
3020
3100
    */
3021
3101
  {
3022
 
    strncpy(table_type, row[1], NAME_LEN-1);
 
3102
    strncpy(table_type, row[1], DRIZZLE_MAX_TABLE_SIZE-1);
3023
3103
    if (opt_delayed)
3024
3104
    {
3025
3105
      if (strcmp(table_type,"MyISAM") &&
3029
3109
        result= IGNORE_INSERT_DELAYED;
3030
3110
    }
3031
3111
  }
3032
 
  drizzleclient_free_result(res);
 
3112
  drizzle_result_free(&res);
3033
3113
  return(result);
3034
3114
}
3035
3115
 
3054
3134
 
3055
3135
static char *primary_key_fields(const char *table_name)
3056
3136
{
3057
 
  DRIZZLE_RES  *res= NULL;
3058
 
  DRIZZLE_ROW  row;
 
3137
  drizzle_result_st res;
 
3138
  drizzle_return_t ret;
 
3139
  drizzle_row_t  row;
3059
3140
  /* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3060
 
  char show_keys_buff[15 + NAME_LEN * 2 + 3];
 
3141
  char show_keys_buff[15 + DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
3061
3142
  uint32_t result_length= 0;
3062
3143
  char *result= 0;
3063
 
  char buff[NAME_LEN * 2 + 3];
 
3144
  char buff[DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
3064
3145
  char *quoted_field;
3065
3146
 
3066
3147
  snprintf(show_keys_buff, sizeof(show_keys_buff),
3067
3148
           "SHOW KEYS FROM %s", table_name);
3068
 
  if (drizzleclient_query(drizzle, show_keys_buff) ||
3069
 
      !(res= drizzleclient_store_result(drizzle)))
 
3149
  if (drizzle_query_str(&dcon, &res, show_keys_buff, &ret) == NULL ||
 
3150
      ret != DRIZZLE_RETURN_OK)
 
3151
  {
 
3152
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
3153
    {
 
3154
      fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
 
3155
              " records are NOT sorted (%s)\n"),
 
3156
              table_name, drizzle_result_error(&res));
 
3157
      drizzle_result_free(&res);
 
3158
    }
 
3159
    else
 
3160
    {
 
3161
      fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
 
3162
              " records are NOT sorted (%s)\n"),
 
3163
              table_name, drizzle_con_error(&dcon));
 
3164
    }
 
3165
 
 
3166
    return result;
 
3167
  }
 
3168
 
 
3169
  if (drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3070
3170
  {
3071
3171
    fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
3072
3172
            " records are NOT sorted (%s)\n"),
3073
 
            table_name, drizzleclient_error(drizzle));
3074
 
    /* Don't exit, because it's better to print out unsorted records */
3075
 
    goto cleanup;
 
3173
            table_name, drizzle_con_error(&dcon));
 
3174
    return result;
3076
3175
  }
3077
3176
 
3078
3177
  /*
3081
3180
   * row, and UNIQUE keys come before others.  So we only need to check
3082
3181
   * the first key, not all keys.
3083
3182
   */
3084
 
  if ((row= drizzleclient_fetch_row(res)) && atoi(row[1]) == 0)
 
3183
  if ((row= drizzle_row_next(&res)) && atoi(row[1]) == 0)
3085
3184
  {
3086
3185
    /* Key is unique */
3087
3186
    do
3088
3187
    {
3089
3188
      quoted_field= quote_name(row[4], buff, 0);
3090
3189
      result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3091
 
    } while ((row= drizzleclient_fetch_row(res)) && atoi(row[3]) > 1);
 
3190
    } while ((row= drizzle_row_next(&res)) && atoi(row[3]) > 1);
3092
3191
  }
3093
3192
 
3094
3193
  /* Build the ORDER BY clause result */
3100
3199
    if (!result)
3101
3200
    {
3102
3201
      fprintf(stderr, _("Error: Not enough memory to store ORDER BY clause\n"));
3103
 
      goto cleanup;
 
3202
      drizzle_result_free(&res);
 
3203
      return result;
3104
3204
    }
3105
 
    drizzleclient_data_seek(res, 0);
3106
 
    row= drizzleclient_fetch_row(res);
 
3205
    drizzle_row_seek(&res, 0);
 
3206
    row= drizzle_row_next(&res);
3107
3207
    quoted_field= quote_name(row[4], buff, 0);
3108
3208
    end= strcpy(result, quoted_field) + strlen(quoted_field);
3109
 
    while ((row= drizzleclient_fetch_row(res)) && atoi(row[3]) > 1)
 
3209
    while ((row= drizzle_row_next(&res)) && atoi(row[3]) > 1)
3110
3210
    {
3111
3211
      quoted_field= quote_name(row[4], buff, 0);
3112
3212
      end+= sprintf(end,",%s",quoted_field);
3113
3213
    }
3114
3214
  }
3115
3215
 
3116
 
cleanup:
3117
 
  if (res)
3118
 
    drizzleclient_free_result(res);
3119
 
 
 
3216
  drizzle_result_free(&res);
3120
3217
  return result;
3121
3218
}
3122
3219
 
3126
3223
  char bin_log_name[FN_REFLEN];
3127
3224
  int exit_code;
3128
3225
  MY_INIT("drizzledump");
 
3226
  drizzle_result_st result;
3129
3227
 
3130
3228
  compatible_mode_normal_str[0]= 0;
3131
3229
  default_charset= (char *)drizzle_universal_client_charset;
3146
3244
  if (!path)
3147
3245
    write_header(md_result_file, *argv);
3148
3246
 
3149
 
  if (opt_slave_data && do_stop_slave_sql(drizzle))
 
3247
  if (opt_slave_data && do_stop_slave_sql(&dcon))
3150
3248
    goto err;
3151
3249
 
3152
3250
  if ((opt_lock_all_tables || opt_master_data) &&
3153
 
      do_flush_tables_read_lock(drizzle))
 
3251
      do_flush_tables_read_lock(&dcon))
3154
3252
    goto err;
3155
 
  if (opt_single_transaction && start_transaction(drizzle))
 
3253
  if (opt_single_transaction && start_transaction(&dcon))
3156
3254
      goto err;
3157
3255
  if (opt_delete_master_logs)
3158
3256
  {
3159
 
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")) ||
3160
 
        get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
 
3257
    if (drizzleclient_query_with_error_report(&dcon, &result, "FLUSH LOGS", false))
 
3258
      goto err;
 
3259
    drizzle_result_free(&result);
 
3260
    if (get_bin_log_name(&dcon, bin_log_name, sizeof(bin_log_name)))
3161
3261
      goto err;
3162
3262
    flush_logs= 0;
3163
3263
  }
3164
3264
  if (opt_lock_all_tables || opt_master_data)
3165
3265
  {
3166
 
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
 
3266
    if (drizzleclient_query_with_error_report(&dcon, &result, "FLUSH LOGS", false))
3167
3267
      goto err;
 
3268
    drizzle_result_free(&result);
3168
3269
    flush_logs= 0; /* not anymore; that would not be sensible */
3169
3270
  }
3170
3271
  /* Add 'STOP SLAVE to beginning of dump */
3171
3272
  if (opt_slave_apply && add_stop_slave())
3172
3273
    goto err;
3173
 
  if (opt_master_data && do_show_master_status(drizzle))
3174
 
    goto err;
3175
 
  if (opt_slave_data && do_show_slave_status(drizzle))
3176
 
    goto err;
3177
 
  if (opt_single_transaction && do_unlock_tables(drizzle)) /* unlock but no commit! */
 
3274
  if (opt_master_data && do_show_master_status(&dcon))
 
3275
    goto err;
 
3276
  if (opt_slave_data && do_show_slave_status(&dcon))
 
3277
    goto err;
 
3278
  if (opt_single_transaction && do_unlock_tables(&dcon)) /* unlock but no commit! */
3178
3279
    goto err;
3179
3280
 
3180
3281
  if (opt_alldbs)
3192
3293
  }
3193
3294
 
3194
3295
  /* if --dump-slave , start the slave sql thread */
3195
 
  if (opt_slave_data && do_start_slave_sql(drizzle))
 
3296
  if (opt_slave_data && do_start_slave_sql(&dcon))
3196
3297
    goto err;
3197
3298
 
3198
3299
  /* add 'START SLAVE' to end of dump */
3207
3308
    goto err;
3208
3309
  }
3209
3310
  /* everything successful, purge the old logs files */
3210
 
  if (opt_delete_master_logs && purge_bin_logs_to(drizzle, bin_log_name))
 
3311
  if (opt_delete_master_logs && purge_bin_logs_to(&dcon, bin_log_name))
3211
3312
    goto err;
3212
3313
 
3213
3314
  /*