~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Brian Aker
  • Date: 2009-02-08 12:39:10 UTC
  • mfrom: (840.1.21 devel)
  • Revision ID: brian@tangent.org-20090208123910-gaodow8xvkw9ed4l
Merging Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
static bool debug_info_flag= false, debug_check_flag= false;
97
97
static uint32_t opt_max_allowed_packet, opt_net_buffer_length, show_progress_size= 0;
98
98
static uint64_t total_rows= 0;
99
 
static DRIZZLE drizzle_connection, *drizzle= 0;
 
99
static DRIZZLE drizzleclient_connection, *drizzle= 0;
100
100
static string insert_pat;
101
101
static char  *opt_password= NULL, *current_user= NULL,
102
102
             *current_host= NULL, *path= NULL, *fields_terminated= NULL,
472
472
static void print_version(void)
473
473
{
474
474
  printf(_("%s  Ver %s Distrib %s, for %s (%s)\n"),my_progname,DUMP_VERSION,
475
 
         drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
475
         drizzleclient_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
476
476
} /* print_version */
477
477
 
478
478
 
525
525
    {
526
526
      fprintf(sql_file,
527
527
              "-- DRIZZLE dump %s  Distrib %s, for %s (%s)\n--\n",
528
 
              DUMP_VERSION, drizzle_get_client_info(),
 
528
              DUMP_VERSION, drizzleclient_get_client_info(),
529
529
              SYSTEM_TYPE, MACHINE_TYPE);
530
530
      fprintf(sql_file, "-- Host: %s    Database: %s\n",
531
531
              current_host ? current_host : "localhost", db_name ? db_name :
533
533
      fputs("-- ------------------------------------------------------\n",
534
534
            sql_file);
535
535
      fprintf(sql_file, "-- Server version\t%s\n",
536
 
              drizzle_get_server_info(&drizzle_connection));
 
536
              drizzleclient_get_server_info(&drizzleclient_connection));
537
537
    }
538
538
    if (opt_set_charset)
539
539
      fprintf(sql_file,
774
774
static int get_options(int *argc, char ***argv)
775
775
{
776
776
  int ho_error;
777
 
  const DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
 
777
  const DRIZZLE_PARAMETERS *drizzle_params= drizzleclient_get_parameters();
778
778
 
779
779
  opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
780
780
  opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
854
854
    return EX_USAGE;
855
855
  }
856
856
  if (tty_password)
857
 
    opt_password=get_tty_password(NULL);
 
857
    opt_password=drizzleclient_get_tty_password(NULL);
858
858
  return(0);
859
859
} /* get_options */
860
860
 
866
866
{
867
867
 
868
868
  maybe_die(EX_DRIZZLEERR, _("Got error: %d: %s %s"),
869
 
          drizzle_errno(drizzle_arg), drizzle_error(drizzle_arg), when);
 
869
          drizzleclient_errno(drizzle_arg), drizzleclient_error(drizzle_arg), when);
870
870
  return;
871
871
}
872
872
 
940
940
  some.
941
941
 
942
942
  SYNOPSIS
943
 
    drizzle_query_with_error_report()
 
943
    drizzleclient_query_with_error_report()
944
944
    drizzle_con       connection to use
945
945
    res             if non zero, result will be put there with
946
 
                    drizzle_store_result()
 
946
                    drizzleclient_store_result()
947
947
    query           query to send to server
948
948
 
949
949
  RETURN VALUES
951
951
    1               error
952
952
*/
953
953
 
954
 
static int drizzle_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
 
954
static int drizzleclient_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
955
955
                                         const char *query)
956
956
{
957
 
  if (drizzle_query(drizzle_con, query) ||
958
 
      (res && !((*res)= drizzle_store_result(drizzle_con))))
 
957
  if (drizzleclient_query(drizzle_con, query) ||
 
958
      (res && !((*res)= drizzleclient_store_result(drizzle_con))))
959
959
  {
960
960
    maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
961
 
            query, drizzle_error(drizzle_con), drizzle_errno(drizzle_con));
 
961
            query, drizzleclient_error(drizzle_con), drizzleclient_errno(drizzle_con));
962
962
    return 1;
963
963
  }
964
964
  return 0;
1006
1006
  if (ignore_errors)
1007
1007
    return;
1008
1008
  if (drizzle)
1009
 
    drizzle_close(drizzle);
 
1009
    drizzleclient_close(drizzle);
1010
1010
  free_resources();
1011
1011
  exit(error);
1012
1012
}
1019
1019
static int connect_to_db(char *host, char *user,char *passwd)
1020
1020
{
1021
1021
  verbose_msg(_("-- Connecting to %s...\n"), host ? host : "localhost");
1022
 
  drizzle_create(&drizzle_connection);
 
1022
  drizzleclient_create(&drizzleclient_connection);
1023
1023
  if (opt_compress)
1024
 
    drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NULL);
1025
 
  if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
 
1024
    drizzleclient_options(&drizzleclient_connection,DRIZZLE_OPT_COMPRESS,NULL);
 
1025
  if (!(drizzle= drizzleclient_connect(&drizzleclient_connection,host,user,passwd,
1026
1026
                                  NULL,opt_drizzle_port, NULL,
1027
1027
                                  0)))
1028
1028
  {
1029
 
    DB_error(&drizzle_connection, "when trying to connect");
 
1029
    DB_error(&drizzleclient_connection, "when trying to connect");
1030
1030
    return(1);
1031
1031
  }
1032
1032
 
1040
1040
static void dbDisconnect(char *host)
1041
1041
{
1042
1042
  verbose_msg(_("-- Disconnecting from %s...\n"), host ? host : "localhost");
1043
 
  drizzle_close(drizzle);
 
1043
  drizzleclient_close(drizzle);
1044
1044
} /* dbDisconnect */
1045
1045
 
1046
1046
 
1051
1051
  if (!(tmp=(char*) malloc(length*2+1)))
1052
1052
    die(EX_DRIZZLEERR, _("Couldn't allocate memory"));
1053
1053
 
1054
 
  drizzle_escape_string(tmp, pos, length);
 
1054
  drizzleclient_escape_string(tmp, pos, length);
1055
1055
  fputc('\'', file);
1056
1056
  fputs(tmp, file);
1057
1057
  fputc('\'', file);
1312
1312
{
1313
1313
  uint i;
1314
1314
  DRIZZLE_FIELD *field;
1315
 
  uint32_t *lengths= drizzle_fetch_lengths(tableRes);
 
1315
  uint32_t *lengths= drizzleclient_fetch_lengths(tableRes);
1316
1316
 
1317
1317
  fprintf(xml_file, "\t\t<%s", row_name);
1318
1318
  check_io(xml_file);
1319
 
  drizzle_field_seek(tableRes, 0);
1320
 
  for (i= 0; (field= drizzle_fetch_field(tableRes)); i++)
 
1319
  drizzleclient_field_seek(tableRes, 0);
 
1320
  for (i= 0; (field= drizzleclient_fetch_field(tableRes)); i++)
1321
1321
  {
1322
1322
    if ((*row)[i])
1323
1323
    {
1426
1426
 
1427
1427
      snprintf(buff, sizeof(buff), "show create table %s", result_table);
1428
1428
 
1429
 
      if (drizzle_query_with_error_report(drizzle, &result, buff))
 
1429
      if (drizzleclient_query_with_error_report(drizzle, &result, buff))
1430
1430
        return false;
1431
1431
 
1432
1432
      if (path)
1451
1451
        check_io(sql_file);
1452
1452
      }
1453
1453
 
1454
 
      field= drizzle_fetch_field_direct(result, 0);
 
1454
      field= drizzleclient_fetch_field_direct(result, 0);
1455
1455
 
1456
 
      row= drizzle_fetch_row(result);
 
1456
      row= drizzleclient_fetch_row(result);
1457
1457
 
1458
1458
      fprintf(sql_file, "%s;\n", row[1]);
1459
1459
 
1460
1460
      check_io(sql_file);
1461
 
      drizzle_free_result(result);
 
1461
      drizzleclient_free_result(result);
1462
1462
    }
1463
1463
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1464
1464
             result_table);
1465
 
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
 
1465
    if (drizzleclient_query_with_error_report(drizzle, &result, query_buff))
1466
1466
    {
1467
1467
      if (path)
1468
1468
        my_fclose(sql_file, MYF(MY_WME));
1496
1496
      }
1497
1497
    }
1498
1498
 
1499
 
    while ((row= drizzle_fetch_row(result)))
 
1499
    while ((row= drizzleclient_fetch_row(result)))
1500
1500
    {
1501
1501
      if (complete_insert)
1502
1502
      {
1508
1508
        insert_pat.append(quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1509
1509
      }
1510
1510
    }
1511
 
    *num_fields= drizzle_num_rows(result);
1512
 
    drizzle_free_result(result);
 
1511
    *num_fields= drizzleclient_num_rows(result);
 
1512
    drizzleclient_free_result(result);
1513
1513
  }
1514
1514
  else
1515
1515
  {
1516
1516
    verbose_msg(_("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n"),
1517
 
                my_progname, drizzle_error(drizzle));
 
1517
                my_progname, drizzleclient_error(drizzle));
1518
1518
 
1519
1519
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1520
1520
             result_table);
1521
 
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
 
1521
    if (drizzleclient_query_with_error_report(drizzle, &result, query_buff))
1522
1522
      return false;
1523
1523
 
1524
1524
    /* Make an sql-file, if path was given iow. option -T was given */
1562
1562
      }
1563
1563
    }
1564
1564
 
1565
 
    while ((row= drizzle_fetch_row(result)))
 
1565
    while ((row= drizzleclient_fetch_row(result)))
1566
1566
    {
1567
 
      uint32_t *lengths= drizzle_fetch_lengths(result);
 
1567
      uint32_t *lengths= drizzleclient_fetch_lengths(result);
1568
1568
      if (init)
1569
1569
      {
1570
1570
        if (!opt_xml && !opt_no_create_info)
1606
1606
        check_io(sql_file);
1607
1607
      }
1608
1608
    }
1609
 
    *num_fields= drizzle_num_rows(result);
1610
 
    drizzle_free_result(result);
 
1609
    *num_fields= drizzleclient_num_rows(result);
 
1610
    drizzleclient_free_result(result);
1611
1611
    if (!opt_no_create_info)
1612
1612
    {
1613
1613
      /* Make an sql-file, if path was given iow. option -T was given */
1614
1614
      char buff[20+FN_REFLEN];
1615
1615
      uint keynr,primary_key;
1616
1616
      snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1617
 
      if (drizzle_query_with_error_report(drizzle, &result, buff))
 
1617
      if (drizzleclient_query_with_error_report(drizzle, &result, buff))
1618
1618
      {
1619
 
        if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
 
1619
        if (drizzleclient_errno(drizzle) == ER_WRONG_OBJECT)
1620
1620
        {
1621
1621
          /* it is VIEW */
1622
1622
          fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1623
1623
          goto continue_xml;
1624
1624
        }
1625
1625
        fprintf(stderr, _("%s: Can't get keys for table %s (%s)\n"),
1626
 
                my_progname, result_table, drizzle_error(drizzle));
 
1626
                my_progname, result_table, drizzleclient_error(drizzle));
1627
1627
        if (path)
1628
1628
          my_fclose(sql_file, MYF(MY_WME));
1629
1629
        return false;
1632
1632
      /* Find first which key is primary key */
1633
1633
      keynr=0;
1634
1634
      primary_key=INT_MAX;
1635
 
      while ((row= drizzle_fetch_row(result)))
 
1635
      while ((row= drizzleclient_fetch_row(result)))
1636
1636
      {
1637
1637
        if (atoi(row[3]) == 1)
1638
1638
        {
1648
1648
          }
1649
1649
        }
1650
1650
      }
1651
 
      drizzle_data_seek(result,0);
 
1651
      drizzleclient_data_seek(result,0);
1652
1652
      keynr=0;
1653
 
      while ((row= drizzle_fetch_row(result)))
 
1653
      while ((row= drizzleclient_fetch_row(result)))
1654
1654
      {
1655
1655
        if (opt_xml)
1656
1656
        {
1678
1678
          fprintf(sql_file, " (%s)",row[7]);      /* Sub key */
1679
1679
        check_io(sql_file);
1680
1680
      }
1681
 
      drizzle_free_result(result);
 
1681
      drizzleclient_free_result(result);
1682
1682
      if (!opt_xml)
1683
1683
      {
1684
1684
        if (keynr)
1695
1695
        snprintf(buff, sizeof(buff), "show table status like %s",
1696
1696
                 quote_for_like(table, show_name_buff));
1697
1697
 
1698
 
        if (drizzle_query_with_error_report(drizzle, &result, buff))
 
1698
        if (drizzleclient_query_with_error_report(drizzle, &result, buff))
1699
1699
        {
1700
 
          if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
 
1700
          if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
1701
1701
          {                                     /* If old DRIZZLE version */
1702
1702
            verbose_msg(_("-- Warning: Couldn't get status information for " \
1703
 
                        "table %s (%s)\n"), result_table,drizzle_error(drizzle));
 
1703
                        "table %s (%s)\n"), result_table,drizzleclient_error(drizzle));
1704
1704
          }
1705
1705
        }
1706
 
        else if (!(row= drizzle_fetch_row(result)))
 
1706
        else if (!(row= drizzleclient_fetch_row(result)))
1707
1707
        {
1708
1708
          fprintf(stderr,
1709
1709
                  _("Error: Couldn't read status information for table %s (%s)\n"),
1710
 
                  result_table,drizzle_error(drizzle));
 
1710
                  result_table,drizzleclient_error(drizzle));
1711
1711
        }
1712
1712
        else
1713
1713
        {
1724
1724
            check_io(sql_file);
1725
1725
          }
1726
1726
        }
1727
 
        drizzle_free_result(result);              /* Is always safe to free */
 
1727
        drizzleclient_free_result(result);              /* Is always safe to free */
1728
1728
      }
1729
1729
continue_xml:
1730
1730
      if (!opt_xml)
1931
1931
      query_string.append( order_by);
1932
1932
    }
1933
1933
 
1934
 
    if (drizzle_real_query(drizzle, query_string.c_str(), query_string.length()))
 
1934
    if (drizzleclient_real_query(drizzle, query_string.c_str(), query_string.length()))
1935
1935
    {
1936
1936
      DB_error(drizzle, _("when executing 'SELECT INTO OUTFILE'"));
1937
1937
      return;
1976
1976
      fputs("\n", md_result_file);
1977
1977
      check_io(md_result_file);
1978
1978
    }
1979
 
    if (drizzle_query_with_error_report(drizzle, 0, query_string.c_str()))
 
1979
    if (drizzleclient_query_with_error_report(drizzle, 0, query_string.c_str()))
1980
1980
    {
1981
1981
      DB_error(drizzle, _("when retrieving data from server"));
1982
1982
      goto err;
1983
1983
    }
1984
1984
    if (quick)
1985
 
      res=drizzle_use_result(drizzle);
 
1985
      res=drizzleclient_use_result(drizzle);
1986
1986
    else
1987
 
      res=drizzle_store_result(drizzle);
 
1987
      res=drizzleclient_store_result(drizzle);
1988
1988
    if (!res)
1989
1989
    {
1990
1990
      DB_error(drizzle, _("when retrieving data from server"));
1992
1992
    }
1993
1993
 
1994
1994
    verbose_msg(_("-- Retrieving rows...\n"));
1995
 
    if (drizzle_num_fields(res) != num_fields)
 
1995
    if (drizzleclient_num_fields(res) != num_fields)
1996
1996
    {
1997
1997
      fprintf(stderr,_("%s: Error in field count for table: %s !  Aborting.\n"),
1998
1998
              my_progname, result_table);
2026
2026
      check_io(md_result_file);
2027
2027
    }
2028
2028
 
2029
 
    while ((row= drizzle_fetch_row(res)))
 
2029
    while ((row= drizzleclient_fetch_row(res)))
2030
2030
    {
2031
2031
      uint i;
2032
 
      uint32_t *lengths= drizzle_fetch_lengths(res);
 
2032
      uint32_t *lengths= drizzleclient_fetch_lengths(res);
2033
2033
      rownr++;
2034
2034
      if ((rownr % show_progress_size) == 0)
2035
2035
      {
2040
2040
        fputs(insert_pat.c_str(),md_result_file);
2041
2041
        check_io(md_result_file);
2042
2042
      }
2043
 
      drizzle_field_seek(res,0);
 
2043
      drizzleclient_field_seek(res,0);
2044
2044
 
2045
2045
      if (opt_xml)
2046
2046
      {
2048
2048
        check_io(md_result_file);
2049
2049
      }
2050
2050
 
2051
 
      for (i= 0; i < drizzle_num_fields(res); i++)
 
2051
      for (i= 0; i < drizzleclient_num_fields(res); i++)
2052
2052
      {
2053
2053
        int is_blob;
2054
2054
        uint32_t length= lengths[i];
2055
2055
 
2056
 
        if (!(field= drizzle_fetch_field(res)))
 
2056
        if (!(field= drizzleclient_fetch_field(res)))
2057
2057
          die(EX_CONSCHECK,
2058
2058
                      _("Not enough fields from table %s! Aborting.\n"),
2059
2059
                      result_table);
2095
2095
                if (opt_hex_blob && is_blob)
2096
2096
                {
2097
2097
                  extended_row.append("0x");
2098
 
                  octet2hex(tmp_str, row[i], length);
 
2098
                  drizzleclient_drizzleclient_octet2hex(tmp_str, row[i], length);
2099
2099
                  extended_row.append(tmp_str);
2100
2100
                }
2101
2101
                else
2102
2102
                {
2103
2103
                  extended_row.append("'");
2104
 
                  drizzle_escape_string(tmp_str,
 
2104
                  drizzleclient_escape_string(tmp_str,
2105
2105
                                        row[i],length);
2106
2106
                  extended_row.append(tmp_str);
2107
2107
                  extended_row.append("'");
2238
2238
      fputs(";\n", md_result_file);             /* If not empty table */
2239
2239
    fflush(md_result_file);
2240
2240
    check_io(md_result_file);
2241
 
    if (drizzle_errno(drizzle))
 
2241
    if (drizzleclient_errno(drizzle))
2242
2242
    {
2243
2243
      snprintf(buf, sizeof(buf),
2244
2244
               _("%s: Error %d: %s when dumping table %s at row: %d\n"),
2245
2245
               my_progname,
2246
 
               drizzle_errno(drizzle),
2247
 
               drizzle_error(drizzle),
 
2246
               drizzleclient_errno(drizzle),
 
2247
               drizzleclient_error(drizzle),
2248
2248
               result_table,
2249
2249
               rownr);
2250
2250
      fputs(buf,stderr);
2269
2269
      fprintf(md_result_file, "commit;\n");
2270
2270
      check_io(md_result_file);
2271
2271
    }
2272
 
    drizzle_free_result(res);
 
2272
    drizzleclient_free_result(res);
2273
2273
  }
2274
2274
  return;
2275
2275
 
2286
2286
 
2287
2287
  if (!res)
2288
2288
  {
2289
 
    if (!(res= drizzle_list_tables(drizzle,NULL)))
 
2289
    if (!(res= drizzleclient_list_tables(drizzle,NULL)))
2290
2290
      return(NULL);
2291
2291
  }
2292
 
  if ((row= drizzle_fetch_row(res)))
 
2292
  if ((row= drizzleclient_fetch_row(res)))
2293
2293
    return((char*) row[0]);
2294
2294
 
2295
2295
  if (reset)
2296
 
    drizzle_data_seek(res,0);      /* We want to read again */
 
2296
    drizzleclient_data_seek(res,0);      /* We want to read again */
2297
2297
  else
2298
2298
  {
2299
 
    drizzle_free_result(res);
 
2299
    drizzleclient_free_result(res);
2300
2300
    res= NULL;
2301
2301
  }
2302
2302
  return(NULL);
2309
2309
  DRIZZLE_RES *tableres;
2310
2310
  int result=0;
2311
2311
 
2312
 
  if (drizzle_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
 
2312
  if (drizzleclient_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
2313
2313
    return 1;
2314
 
  while ((row= drizzle_fetch_row(tableres)))
 
2314
  while ((row= drizzleclient_fetch_row(tableres)))
2315
2315
  {
2316
2316
    if (dump_all_tables_in_db(row[0]))
2317
2317
      result=1;
2362
2362
             "SHOW CREATE DATABASE IF NOT EXISTS %s",
2363
2363
             qdatabase);
2364
2364
 
2365
 
    if (drizzle_query(drizzle, qbuf) || !(dbinfo = drizzle_store_result(drizzle)))
 
2365
    if (drizzleclient_query(drizzle, qbuf) || !(dbinfo = drizzleclient_store_result(drizzle)))
2366
2366
    {
2367
2367
      /* Old server version, dump generic CREATE DATABASE */
2368
2368
      if (opt_drop_database)
2379
2379
        fprintf(md_result_file,
2380
2380
                "\nDROP DATABASE IF EXISTS %s;\n",
2381
2381
                qdatabase);
2382
 
      row = drizzle_fetch_row(dbinfo);
 
2382
      row = drizzleclient_fetch_row(dbinfo);
2383
2383
      if (row[1])
2384
2384
      {
2385
2385
        fprintf(md_result_file,"\n%s;\n",row[1]);
2386
2386
      }
2387
 
      drizzle_free_result(dbinfo);
 
2387
      drizzleclient_free_result(dbinfo);
2388
2388
    }
2389
2389
  }
2390
2390
  return(0);
2393
2393
 
2394
2394
static int init_dumping(char *database, int init_func(char*))
2395
2395
{
2396
 
  if (drizzle_get_server_version(drizzle) >= 50003 &&
 
2396
  if (drizzleclient_get_server_version(drizzle) >= 50003 &&
2397
2397
      !my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
2398
2398
    return 1;
2399
2399
 
2400
 
  if (drizzle_select_db(drizzle, database))
 
2400
  if (drizzleclient_select_db(drizzle, database))
2401
2401
  {
2402
2402
    DB_error(drizzle, _("when selecting the database"));
2403
2403
    return 1;                   /* If --force */
2466
2466
        query.append( " READ LOCAL,");
2467
2467
      }
2468
2468
    }
2469
 
    if (numrows && drizzle_real_query(drizzle, query.c_str(), query.length()-1))
 
2469
    if (numrows && drizzleclient_real_query(drizzle, query.c_str(), query.length()-1))
2470
2470
      DB_error(drizzle, _("when using LOCK TABLES"));
2471
2471
            /* We shall continue here, if --force was given */
2472
2472
    query.clear();
2473
2473
  }
2474
2474
  if (flush_logs)
2475
2475
  {
2476
 
    if (drizzle_refresh(drizzle, REFRESH_LOG))
 
2476
    if (drizzleclient_refresh(drizzle, REFRESH_LOG))
2477
2477
      DB_error(drizzle, _("when doing refresh"));
2478
2478
           /* We shall continue here, if --force was given */
2479
2479
  }
2493
2493
    check_io(md_result_file);
2494
2494
  }
2495
2495
  if (lock_tables)
2496
 
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
 
2496
    drizzleclient_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2497
2497
 
2498
2498
  return(0);
2499
2499
} /* dump_all_tables_in_db */
2524
2524
  snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2525
2525
           quote_for_like(old_table_name, show_name_buff));
2526
2526
 
2527
 
  if (drizzle_query_with_error_report(drizzle, 0, query))
 
2527
  if (drizzleclient_query_with_error_report(drizzle, 0, query))
2528
2528
    return NULL;
2529
2529
 
2530
 
  if ((table_res= drizzle_store_result(drizzle)))
 
2530
  if ((table_res= drizzleclient_store_result(drizzle)))
2531
2531
  {
2532
 
    uint64_t num_rows= drizzle_num_rows(table_res);
 
2532
    uint64_t num_rows= drizzleclient_num_rows(table_res);
2533
2533
    if (num_rows > 0)
2534
2534
    {
2535
2535
      uint32_t *lengths;
2537
2537
        Return first row
2538
2538
        TODO: Return all matching rows
2539
2539
      */
2540
 
      row= drizzle_fetch_row(table_res);
2541
 
      lengths= drizzle_fetch_lengths(table_res);
 
2540
      row= drizzleclient_fetch_row(table_res);
 
2541
      lengths= drizzleclient_fetch_lengths(table_res);
2542
2542
      name= strmake_root(root, row[0], lengths[0]);
2543
2543
    }
2544
 
    drizzle_free_result(table_res);
 
2544
    drizzleclient_free_result(table_res);
2545
2545
  }
2546
2546
  return(name);
2547
2547
}
2589
2589
 
2590
2590
  if (lock_tables)
2591
2591
  {
2592
 
    if (drizzle_real_query(drizzle, lock_tables_query.c_str(),
 
2592
    if (drizzleclient_real_query(drizzle, lock_tables_query.c_str(),
2593
2593
                         lock_tables_query.length()-1))
2594
2594
    {
2595
2595
      if (!ignore_errors)
2602
2602
  }
2603
2603
  if (flush_logs)
2604
2604
  {
2605
 
    if (drizzle_refresh(drizzle, REFRESH_LOG))
 
2605
    if (drizzleclient_refresh(drizzle, REFRESH_LOG))
2606
2606
    {
2607
2607
      if (!ignore_errors)
2608
2608
        free_root(&root, MYF(0));
2626
2626
    check_io(md_result_file);
2627
2627
  }
2628
2628
  if (lock_tables)
2629
 
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
 
2629
    drizzleclient_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2630
2630
  return(0);
2631
2631
} /* dump_selected_tables */
2632
2632
 
2637
2637
  DRIZZLE_RES *master;
2638
2638
  const char *comment_prefix=
2639
2639
    (opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2640
 
  if (drizzle_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
 
2640
  if (drizzleclient_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
2641
2641
  {
2642
2642
    return 1;
2643
2643
  }
2644
2644
  else
2645
2645
  {
2646
 
    row= drizzle_fetch_row(master);
 
2646
    row= drizzleclient_fetch_row(master);
2647
2647
    if (row && row[0] && row[1])
2648
2648
    {
2649
2649
      /* SHOW MASTER STATUS reports file and position */
2661
2661
      /* SHOW MASTER STATUS reports nothing and --force is not enabled */
2662
2662
      my_printf_error(0, _("Error: Binlogging on server not active"),
2663
2663
                      MYF(0));
2664
 
      drizzle_free_result(master);
 
2664
      drizzleclient_free_result(master);
2665
2665
      maybe_exit(EX_DRIZZLEERR);
2666
2666
      return 1;
2667
2667
    }
2668
 
    drizzle_free_result(master);
 
2668
    drizzleclient_free_result(master);
2669
2669
  }
2670
2670
  return 0;
2671
2671
}
2674
2674
{
2675
2675
  DRIZZLE_RES *slave;
2676
2676
  /* We need to check if the slave sql is running in the first place */
2677
 
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
 
2677
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2678
2678
    return(1);
2679
2679
  else
2680
2680
  {
2681
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
 
2681
    DRIZZLE_ROW row= drizzleclient_fetch_row(slave);
2682
2682
    if (row && row[11])
2683
2683
    {
2684
2684
      /* if SLAVE SQL is not running, we don't stop it */
2685
2685
      if (!strcmp(row[11],"No"))
2686
2686
      {
2687
 
        drizzle_free_result(slave);
 
2687
        drizzleclient_free_result(slave);
2688
2688
        /* Silently assume that they don't have the slave running */
2689
2689
        return(0);
2690
2690
      }
2691
2691
    }
2692
2692
  }
2693
 
  drizzle_free_result(slave);
 
2693
  drizzleclient_free_result(slave);
2694
2694
 
2695
2695
  /* now, stop slave if running */
2696
 
  if (drizzle_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
 
2696
  if (drizzleclient_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
2697
2697
    return(1);
2698
2698
 
2699
2699
  return(0);
2722
2722
  DRIZZLE_RES *slave;
2723
2723
  const char *comment_prefix=
2724
2724
    (opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2725
 
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
 
2725
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2726
2726
  {
2727
2727
    if (!ignore_errors)
2728
2728
    {
2733
2733
  }
2734
2734
  else
2735
2735
  {
2736
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
 
2736
    DRIZZLE_ROW row= drizzleclient_fetch_row(slave);
2737
2737
    if (row && row[9] && row[21])
2738
2738
    {
2739
2739
      /* SHOW MASTER STATUS reports file and position */
2756
2756
 
2757
2757
      check_io(md_result_file);
2758
2758
    }
2759
 
    drizzle_free_result(slave);
 
2759
    drizzleclient_free_result(slave);
2760
2760
  }
2761
2761
  return 0;
2762
2762
}
2765
2765
{
2766
2766
  DRIZZLE_RES *slave;
2767
2767
  /* We need to check if the slave sql is stopped in the first place */
2768
 
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
 
2768
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2769
2769
    return(1);
2770
2770
  else
2771
2771
  {
2772
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
 
2772
    DRIZZLE_ROW row= drizzleclient_fetch_row(slave);
2773
2773
    if (row && row[11])
2774
2774
    {
2775
2775
      /* if SLAVE SQL is not running, we don't start it */
2776
2776
      if (!strcmp(row[11],"Yes"))
2777
2777
      {
2778
 
        drizzle_free_result(slave);
 
2778
        drizzleclient_free_result(slave);
2779
2779
        /* Silently assume that they don't have the slave running */
2780
2780
        return(0);
2781
2781
      }
2782
2782
    }
2783
2783
  }
2784
 
  drizzle_free_result(slave);
 
2784
  drizzleclient_free_result(slave);
2785
2785
 
2786
2786
  /* now, start slave if stopped */
2787
 
  if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
 
2787
  if (drizzleclient_query_with_error_report(drizzle_con, 0, "START SLAVE"))
2788
2788
  {
2789
2789
    my_printf_error(0, _("Error: Unable to start slave"), MYF(0));
2790
2790
    return 1;
2805
2805
    update starts between the two FLUSHes, we have that bad stall.
2806
2806
  */
2807
2807
  return
2808
 
    ( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
2809
 
      drizzle_query_with_error_report(drizzle_con, 0,
 
2808
    ( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
 
2809
      drizzleclient_query_with_error_report(drizzle_con, 0,
2810
2810
                                    "FLUSH TABLES WITH READ LOCK") );
2811
2811
}
2812
2812
 
2813
2813
 
2814
2814
static int do_unlock_tables(DRIZZLE *drizzle_con)
2815
2815
{
2816
 
  return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
 
2816
  return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
2817
2817
}
2818
2818
 
2819
2819
static int get_bin_log_name(DRIZZLE *drizzle_con,
2822
2822
  DRIZZLE_RES *res;
2823
2823
  DRIZZLE_ROW row;
2824
2824
 
2825
 
  if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
2826
 
      !(res= drizzle_store_result(drizzle)))
 
2825
  if (drizzleclient_query(drizzle_con, "SHOW MASTER STATUS") ||
 
2826
      !(res= drizzleclient_store_result(drizzle)))
2827
2827
    return 1;
2828
2828
 
2829
 
  if (!(row= drizzle_fetch_row(res)))
 
2829
  if (!(row= drizzleclient_fetch_row(res)))
2830
2830
  {
2831
 
    drizzle_free_result(res);
 
2831
    drizzleclient_free_result(res);
2832
2832
    return 1;
2833
2833
  }
2834
2834
  /*
2837
2837
  */
2838
2838
  strncpy(buff_log_name, row[0], buff_len - 1);
2839
2839
 
2840
 
  drizzle_free_result(res);
 
2840
  drizzleclient_free_result(res);
2841
2841
  return 0;
2842
2842
}
2843
2843
 
2847
2847
  string str= "PURGE BINARY LOGS TO '";
2848
2848
  str.append(log_name);
2849
2849
  str.append("'");
2850
 
  err = drizzle_query_with_error_report(drizzle_con, 0, str.c_str());
 
2850
  err = drizzleclient_query_with_error_report(drizzle_con, 0, str.c_str());
2851
2851
  return err;
2852
2852
}
2853
2853
 
2854
2854
 
2855
2855
static int start_transaction(DRIZZLE *drizzle_con)
2856
2856
{
2857
 
  return (drizzle_query_with_error_report(drizzle_con, 0,
 
2857
  return (drizzleclient_query_with_error_report(drizzle_con, 0,
2858
2858
                                        "SET SESSION TRANSACTION ISOLATION "
2859
2859
                                        "LEVEL REPEATABLE READ") ||
2860
 
          drizzle_query_with_error_report(drizzle_con, 0,
 
2860
          drizzleclient_query_with_error_report(drizzle_con, 0,
2861
2861
                                        "START TRANSACTION "
2862
2862
                                        "WITH CONSISTENT SNAPSHOT"));
2863
2863
}
2910
2910
                        int string_value)
2911
2911
{
2912
2912
  DRIZZLE_FIELD   *field;
2913
 
  drizzle_field_seek(result, 0);
 
2913
  drizzleclient_field_seek(result, 0);
2914
2914
 
2915
 
  for ( ; (field= drizzle_fetch_field(result)) ; row++)
 
2915
  for ( ; (field= drizzleclient_fetch_field(result)) ; row++)
2916
2916
  {
2917
2917
    if (!strcmp(field->name,name))
2918
2918
    {
2940
2940
static const char* fetch_named_row(DRIZZLE_RES *result, DRIZZLE_ROW row, const char *name)
2941
2941
{
2942
2942
  DRIZZLE_FIELD   *field;
2943
 
  drizzle_field_seek(result, 0);
2944
 
  for ( ; (field= drizzle_fetch_field(result)) ; row++)
 
2943
  drizzleclient_field_seek(result, 0);
 
2944
  for ( ; (field= drizzleclient_fetch_field(result)) ; row++)
2945
2945
  {
2946
2946
    if (!strcmp(field->name,name))
2947
2947
    {
2948
2948
      if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */
2949
2949
      {
2950
 
        drizzle_field_seek(result, 0);
 
2950
        drizzleclient_field_seek(result, 0);
2951
2951
        return row[0];
2952
2952
      }
2953
2953
    }
2954
2954
  }
2955
 
  drizzle_field_seek(result, 0);
 
2955
  drizzleclient_field_seek(result, 0);
2956
2956
  return NULL;
2957
2957
}
2958
2958
 
2993
2993
  assert(2*sizeof(table_name) < sizeof(show_name_buff));
2994
2994
  snprintf(buff, sizeof(buff), "show table status like %s",
2995
2995
           quote_for_like(table_name, show_name_buff));
2996
 
  if (drizzle_query_with_error_report(drizzle, &res, buff))
 
2996
  if (drizzleclient_query_with_error_report(drizzle, &res, buff))
2997
2997
  {
2998
 
    if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
 
2998
    if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
2999
2999
    {                                   /* If old DRIZZLE version */
3000
3000
      verbose_msg(_("-- Warning: Couldn't get status information for "
3001
 
                  "table %s (%s)\n"), table_name, drizzle_error(drizzle));
 
3001
                  "table %s (%s)\n"), table_name, drizzleclient_error(drizzle));
3002
3002
      return(result);                       /* assume table is ok */
3003
3003
    }
3004
3004
  }
3005
 
  if (!(row= drizzle_fetch_row(res)))
 
3005
  if (!(row= drizzleclient_fetch_row(res)))
3006
3006
  {
3007
3007
    fprintf(stderr,
3008
3008
            _("Error: Couldn't read status information for table %s (%s)\n"),
3009
 
            table_name, drizzle_error(drizzle));
3010
 
    drizzle_free_result(res);
 
3009
            table_name, drizzleclient_error(drizzle));
 
3010
    drizzleclient_free_result(res);
3011
3011
    return(result);                         /* assume table is ok */
3012
3012
  }
3013
3013
  else
3034
3034
        result= IGNORE_INSERT_DELAYED;
3035
3035
    }
3036
3036
  }
3037
 
  drizzle_free_result(res);
 
3037
  drizzleclient_free_result(res);
3038
3038
  return(result);
3039
3039
}
3040
3040
 
3070
3070
 
3071
3071
  snprintf(show_keys_buff, sizeof(show_keys_buff),
3072
3072
           "SHOW KEYS FROM %s", table_name);
3073
 
  if (drizzle_query(drizzle, show_keys_buff) ||
3074
 
      !(res= drizzle_store_result(drizzle)))
 
3073
  if (drizzleclient_query(drizzle, show_keys_buff) ||
 
3074
      !(res= drizzleclient_store_result(drizzle)))
3075
3075
  {
3076
3076
    fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
3077
3077
            " records are NOT sorted (%s)\n"),
3078
 
            table_name, drizzle_error(drizzle));
 
3078
            table_name, drizzleclient_error(drizzle));
3079
3079
    /* Don't exit, because it's better to print out unsorted records */
3080
3080
    goto cleanup;
3081
3081
  }
3086
3086
   * row, and UNIQUE keys come before others.  So we only need to check
3087
3087
   * the first key, not all keys.
3088
3088
   */
3089
 
  if ((row= drizzle_fetch_row(res)) && atoi(row[1]) == 0)
 
3089
  if ((row= drizzleclient_fetch_row(res)) && atoi(row[1]) == 0)
3090
3090
  {
3091
3091
    /* Key is unique */
3092
3092
    do
3093
3093
    {
3094
3094
      quoted_field= quote_name(row[4], buff, 0);
3095
3095
      result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3096
 
    } while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1);
 
3096
    } while ((row= drizzleclient_fetch_row(res)) && atoi(row[3]) > 1);
3097
3097
  }
3098
3098
 
3099
3099
  /* Build the ORDER BY clause result */
3107
3107
      fprintf(stderr, _("Error: Not enough memory to store ORDER BY clause\n"));
3108
3108
      goto cleanup;
3109
3109
    }
3110
 
    drizzle_data_seek(res, 0);
3111
 
    row= drizzle_fetch_row(res);
 
3110
    drizzleclient_data_seek(res, 0);
 
3111
    row= drizzleclient_fetch_row(res);
3112
3112
    quoted_field= quote_name(row[4], buff, 0);
3113
3113
    end= strcpy(result, quoted_field) + strlen(quoted_field);
3114
 
    while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1)
 
3114
    while ((row= drizzleclient_fetch_row(res)) && atoi(row[3]) > 1)
3115
3115
    {
3116
3116
      quoted_field= quote_name(row[4], buff, 0);
3117
3117
      end+= sprintf(end,",%s",quoted_field);
3120
3120
 
3121
3121
cleanup:
3122
3122
  if (res)
3123
 
    drizzle_free_result(res);
 
3123
    drizzleclient_free_result(res);
3124
3124
 
3125
3125
  return result;
3126
3126
}
3161
3161
      goto err;
3162
3162
  if (opt_delete_master_logs)
3163
3163
  {
3164
 
    if (drizzle_refresh(drizzle, REFRESH_LOG) ||
 
3164
    if (drizzleclient_refresh(drizzle, REFRESH_LOG) ||
3165
3165
        get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
3166
3166
      goto err;
3167
3167
    flush_logs= 0;
3168
3168
  }
3169
3169
  if (opt_lock_all_tables || opt_master_data)
3170
3170
  {
3171
 
    if (flush_logs && drizzle_refresh(drizzle, REFRESH_LOG))
 
3171
    if (flush_logs && drizzleclient_refresh(drizzle, REFRESH_LOG))
3172
3172
      goto err;
3173
3173
    flush_logs= 0; /* not anymore; that would not be sensible */
3174
3174
  }