~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Eric Day
  • Date: 2009-03-25 08:02:36 UTC
  • mto: (968.1.1 lib-merge)
  • mto: This revision was merged to the branch mainline in revision 969.
  • Revision ID: eday@oddments.org-20090325080236-vgw82pmoh5rnb8lz
All utilities done except slap.

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 8192
 
64
#define DRIZZLE_MAX_LINE_LENGTH 1024*1024L-1025
65
65
 
66
66
/* ignore table flags */
67
67
#define IGNORE_NONE 0x00 /* no ignore */
845
845
/*
846
846
** DB_error -- prints DRIZZLE error message and exits the program.
847
847
*/
848
 
static void DB_error(drizzle_con_st *con, const char *when)
 
848
static void DB_error(drizzle_result_st *res, drizzle_return_t ret,
 
849
                     const char *when)
849
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);
850
859
 
851
 
  maybe_die(EX_DRIZZLEERR, _("Got error: %s %s"), drizzle_con_error(con), when);
852
860
  return;
853
861
}
854
862
 
935
943
 
936
944
static int drizzleclient_query_with_error_report(drizzle_con_st *con,
937
945
                                                 drizzle_result_st *result,
938
 
                                                 const char *query)
 
946
                                                 const char *query, bool quick)
939
947
{
940
948
  drizzle_return_t ret;
941
949
 
942
950
  if (drizzle_query_str(con, result, query, &ret) == NULL ||
943
 
      ret != DRIZZLE_RETURN_OK ||
944
 
      drizzle_result_buffer(result) != DRIZZLE_RETURN_OK)
945
 
  {
 
951
      ret != DRIZZLE_RETURN_OK)
 
952
  {
 
953
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
954
    {
 
955
      maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
 
956
                query, drizzle_result_error(result),
 
957
                drizzle_result_error_code(result));
 
958
      drizzle_result_free(result);
 
959
    }
 
960
    else
 
961
    {
 
962
      maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
 
963
                query, drizzle_con_error(con), ret);
 
964
    }
 
965
    return 1;
 
966
  }
 
967
 
 
968
  if (quick)
 
969
    ret= drizzle_column_buffer(result);
 
970
  else
 
971
    ret= drizzle_result_buffer(result);
 
972
  if (ret != DRIZZLE_RETURN_OK)
 
973
  {
 
974
    drizzle_result_free(result);
946
975
    maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
947
 
            query, drizzle_con_error(con), ret);
 
976
              query, drizzle_con_error(con), ret);
948
977
    return 1;
949
978
  }
 
979
 
950
980
  return 0;
951
981
}
952
982
 
1004
1034
 
1005
1035
static int connect_to_db(char *host, char *user,char *passwd)
1006
1036
{
 
1037
  drizzle_return_t ret;
 
1038
 
1007
1039
  verbose_msg(_("-- Connecting to %s...\n"), host ? host : "localhost");
1008
1040
  drizzle_create(&drizzle);
1009
1041
  drizzle_con_create(&drizzle, &dcon);
1010
1042
  drizzle_con_set_tcp(&dcon, host, opt_drizzle_port);
1011
1043
  drizzle_con_set_auth(&dcon, user, passwd);
1012
 
  if (drizzle_con_connect(&dcon) != DRIZZLE_RETURN_OK)
 
1044
  ret= drizzle_con_connect(&dcon);
 
1045
  if (ret != DRIZZLE_RETURN_OK)
1013
1046
  {
1014
 
    DB_error(&dcon, "when trying to connect");
 
1047
    DB_error(NULL, ret, "when trying to connect");
1015
1048
    return(1);
1016
1049
  }
1017
1050
 
1415
1448
 
1416
1449
      snprintf(buff, sizeof(buff), "show create table %s", result_table);
1417
1450
 
1418
 
      if (drizzleclient_query_with_error_report(&dcon, &result, buff))
 
1451
      if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1419
1452
        return false;
1420
1453
 
1421
1454
      if (path)
1422
1455
      {
1423
1456
        if (!(sql_file= open_sql_file_for_table(table)))
 
1457
        {
 
1458
          drizzle_result_free(&result);
1424
1459
          return false;
 
1460
        }
1425
1461
 
1426
1462
        write_header(sql_file, db);
1427
1463
      }
1449
1485
      check_io(sql_file);
1450
1486
      drizzle_result_free(&result);
1451
1487
    }
 
1488
 
1452
1489
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1453
1490
             result_table);
1454
 
    if (drizzleclient_query_with_error_report(&dcon, &result, query_buff))
 
1491
 
 
1492
    if (drizzleclient_query_with_error_report(&dcon, &result, query_buff, false))
1455
1493
    {
1456
1494
      if (path)
1457
1495
        fclose(sql_file);
1497
1535
        insert_pat.append(quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1498
1536
      }
1499
1537
    }
1500
 
    *num_fields= drizzle_result_column_count(&result);
 
1538
    *num_fields= drizzle_result_row_count(&result);
1501
1539
    drizzle_result_free(&result);
1502
1540
  }
1503
1541
  else
1507
1545
 
1508
1546
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1509
1547
             result_table);
1510
 
    if (drizzleclient_query_with_error_report(&dcon, &result, query_buff))
 
1548
    if (drizzleclient_query_with_error_report(&dcon, &result, query_buff, false))
1511
1549
      return false;
1512
1550
 
1513
1551
    /* Make an sql-file, if path was given iow. option -T was given */
1600
1638
    }
1601
1639
    *num_fields= drizzle_result_row_count(&result);
1602
1640
    drizzle_result_free(&result);
 
1641
 
1603
1642
    if (!opt_no_create_info)
1604
1643
    {
1605
1644
      /* Make an sql-file, if path was given iow. option -T was given */
1606
1645
      char buff[20+FN_REFLEN];
1607
1646
      uint32_t keynr,primary_key;
1608
1647
      snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1609
 
      if (drizzleclient_query_with_error_report(dcon, &result, buff))
 
1648
      if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1610
1649
      {
1611
 
        if (drizzleclient_errno(drizzle) == ER_WRONG_OBJECT)
1612
 
        {
1613
 
          /* it is VIEW */
1614
 
          fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1615
 
          goto continue_xml;
1616
 
        }
1617
 
        fprintf(stderr, _("%s: Can't get keys for table %s (%s)\n"),
1618
 
                my_progname, result_table, drizzleclient_error(drizzle));
 
1650
        fprintf(stderr, _("%s: Can't get keys for table %s\n"),
 
1651
                my_progname, result_table);
1619
1652
        if (path)
1620
1653
          fclose(sql_file);
1621
1654
        return false;
1624
1657
      /* Find first which key is primary key */
1625
1658
      keynr=0;
1626
1659
      primary_key=INT_MAX;
1627
 
      while ((row= drizzleclient_fetch_row(result)))
 
1660
      while ((row= drizzle_row_next(&result)))
1628
1661
      {
1629
1662
        if (atoi(row[3]) == 1)
1630
1663
        {
1640
1673
          }
1641
1674
        }
1642
1675
      }
1643
 
      drizzleclient_data_seek(result,0);
 
1676
      drizzle_row_seek(&result,0);
1644
1677
      keynr=0;
1645
 
      while ((row= drizzleclient_fetch_row(result)))
 
1678
      while ((row= drizzle_row_next(&result)))
1646
1679
      {
1647
1680
        if (opt_xml)
1648
1681
        {
1649
 
          print_xml_row(sql_file, "key", result, &row);
 
1682
          print_xml_row(sql_file, "key", &result, &row);
1650
1683
          continue;
1651
1684
        }
1652
1685
 
1670
1703
          fprintf(sql_file, " (%s)",row[7]);      /* Sub key */
1671
1704
        check_io(sql_file);
1672
1705
      }
1673
 
      drizzleclient_free_result(result);
 
1706
      drizzle_result_free(&result);
1674
1707
      if (!opt_xml)
1675
1708
      {
1676
1709
        if (keynr)
1681
1714
      /* Get DRIZZLE specific create options */
1682
1715
      if (create_options)
1683
1716
      {
1684
 
        char show_name_buff[NAME_LEN*2+2+24];
 
1717
        char show_name_buff[DRIZZLE_MAX_COLUMN_NAME_SIZE*2+2+24];
1685
1718
 
1686
1719
        /* Check memory for quote_for_like() */
1687
1720
        snprintf(buff, sizeof(buff), "show table status like %s",
1688
1721
                 quote_for_like(table, show_name_buff));
1689
1722
 
1690
 
        if (drizzleclient_query_with_error_report(dcon, &result, buff))
 
1723
        if (!drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1691
1724
        {
1692
 
          if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
1693
 
          {                                     /* If old DRIZZLE version */
1694
 
            verbose_msg(_("-- Warning: Couldn't get status information for " \
1695
 
                        "table %s (%s)\n"), result_table,drizzleclient_error(drizzle));
 
1725
          if (!(row= drizzle_row_next(&result)))
 
1726
          {
 
1727
            fprintf(stderr,
 
1728
                    _("Error: Couldn't read status information for table %s\n"),
 
1729
                    result_table);
1696
1730
          }
1697
 
        }
1698
 
        else if (!(row= drizzleclient_fetch_row(result)))
1699
 
        {
1700
 
          fprintf(stderr,
1701
 
                  _("Error: Couldn't read status information for table %s (%s)\n"),
1702
 
                  result_table,drizzleclient_error(drizzle));
1703
 
        }
1704
 
        else
1705
 
        {
1706
 
          if (opt_xml)
1707
 
            print_xml_row(sql_file, "options", result, &row);
1708
1731
          else
1709
1732
          {
1710
 
            fputs("/*!",sql_file);
1711
 
            print_value(sql_file,result,row,"engine=","Engine",0);
1712
 
            print_value(sql_file,result,row,"","Create_options",0);
1713
 
            print_value(sql_file,result,row,"comment=","Comment",1);
 
1733
            if (opt_xml)
 
1734
              print_xml_row(sql_file, "options", &result, &row);
 
1735
            else
 
1736
            {
 
1737
              fputs("/*!",sql_file);
 
1738
              print_value(sql_file,&result,row,"engine=","Engine",0);
 
1739
              print_value(sql_file,&result,row,"","Create_options",0);
 
1740
              print_value(sql_file,&result,row,"comment=","Comment",1);
1714
1741
 
1715
 
            fputs(" */",sql_file);
1716
 
            check_io(sql_file);
 
1742
              fputs(" */",sql_file);
 
1743
              check_io(sql_file);
 
1744
            }
1717
1745
          }
 
1746
          drizzle_result_free(&result);
1718
1747
        }
1719
 
        drizzleclient_free_result(result);              /* Is always safe to free */
1720
1748
      }
1721
 
continue_xml:
1722
1749
      if (!opt_xml)
1723
1750
        fputs(";\n", sql_file);
1724
1751
      else
1822
1849
static void dump_table(char *table, char *db)
1823
1850
{
1824
1851
  char ignore_flag;
1825
 
  char buf[200], table_buff[NAME_LEN+3];
 
1852
  char table_buff[DRIZZLE_MAX_TABLE_SIZE+3];
1826
1853
  string query_string;
1827
 
  char table_type[NAME_LEN];
1828
 
  char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table;
 
1854
  char table_type[DRIZZLE_MAX_TABLE_SIZE];
 
1855
  char *result_table, table_buff2[DRIZZLE_MAX_TABLE_SIZE*2+3], *opt_quoted_table;
1829
1856
  int error= 0;
1830
1857
  uint32_t rownr, row_break, total_length, init_length;
1831
1858
  uint64_t num_fields= 0;
1832
 
  drizzle_result_st     *res;
1833
 
  DRIZZLE_FIELD   *field;
1834
 
  drizzle_row_t     row;
 
1859
  drizzle_return_t ret;
 
1860
  drizzle_result_st result;
 
1861
  drizzle_column_st *column;
 
1862
  drizzle_row_t row;
1835
1863
 
1836
1864
 
1837
1865
  /*
1923
1951
      query_string.append( order_by);
1924
1952
    }
1925
1953
 
1926
 
    if (drizzleclient_real_query(drizzle, query_string.c_str(), query_string.length()))
 
1954
    if (drizzle_query(&dcon, &result, query_string.c_str(),
 
1955
                      query_string.length(), &ret) == NULL ||
 
1956
        ret != DRIZZLE_RETURN_OK)
1927
1957
    {
1928
 
      DB_error(drizzle, _("when executing 'SELECT INTO OUTFILE'"));
 
1958
      DB_error(&result, ret, _("when executing 'SELECT INTO OUTFILE'"));
 
1959
 
1929
1960
      return;
1930
1961
    }
 
1962
    drizzle_result_free(&result);
1931
1963
  }
1932
1964
  else
1933
1965
  {
1968
2000
      fputs("\n", md_result_file);
1969
2001
      check_io(md_result_file);
1970
2002
    }
1971
 
    if (drizzleclient_query_with_error_report(dcon, &result,
1972
 
                                              query_string.c_str()))
1973
 
    {
1974
 
      DB_error(drizzle, _("when retrieving data from server"));
1975
 
      goto err;
1976
 
    }
1977
 
    if (quick)
1978
 
      res=drizzleclient_use_result(drizzle);
1979
 
    else
1980
 
      res=drizzleclient_store_result(drizzle);
1981
 
    if (!res)
1982
 
    {
1983
 
      DB_error(drizzle, _("when retrieving data from server"));
 
2003
    if (drizzleclient_query_with_error_report(&dcon, &result,
 
2004
                                              query_string.c_str(), quick))
 
2005
    {
1984
2006
      goto err;
1985
2007
    }
1986
2008
 
1987
2009
    verbose_msg(_("-- Retrieving rows...\n"));
1988
 
    if (drizzleclient_num_fields(res) != num_fields)
 
2010
    if (drizzle_result_column_count(&result) != num_fields)
1989
2011
    {
1990
2012
      fprintf(stderr,_("%s: Error in field count for table: %s !  Aborting.\n"),
1991
2013
              my_progname, result_table);
1992
2014
      error= EX_CONSCHECK;
 
2015
      drizzle_result_free(&result);
1993
2016
      goto err;
1994
2017
    }
1995
2018
 
2019
2042
      check_io(md_result_file);
2020
2043
    }
2021
2044
 
2022
 
    while ((row= drizzleclient_fetch_row(res)))
 
2045
    row= NULL;
 
2046
 
 
2047
    while (1)
2023
2048
    {
2024
2049
      uint32_t i;
2025
 
      uint32_t *lengths= drizzleclient_fetch_lengths(res);
 
2050
      size_t *lengths;
 
2051
 
 
2052
      if (quick)
 
2053
      {
 
2054
        if (row)
 
2055
          drizzle_row_free(&result, row);
 
2056
 
 
2057
        row= drizzle_row_buffer(&result, &ret);
 
2058
        if (ret != DRIZZLE_RETURN_OK)
 
2059
        {
 
2060
          fprintf(stderr,
 
2061
                _("%s: Error reading rows for table: %s (%d:%s) ! Aborting.\n"),
 
2062
                  my_progname, result_table, ret, drizzle_con_error(&dcon));
 
2063
          drizzle_result_free(&result);
 
2064
          goto err;
 
2065
        }
 
2066
      }
 
2067
      else
 
2068
        row= drizzle_row_next(&result);
 
2069
 
 
2070
      if (row == NULL)
 
2071
        break;
 
2072
 
 
2073
      lengths= drizzle_row_field_sizes(&result);
 
2074
 
2026
2075
      rownr++;
2027
2076
      if ((rownr % show_progress_size) == 0)
2028
2077
      {
2033
2082
        fputs(insert_pat.c_str(),md_result_file);
2034
2083
        check_io(md_result_file);
2035
2084
      }
2036
 
      drizzleclient_field_seek(res,0);
 
2085
      drizzle_column_seek(&result,0);
2037
2086
 
2038
2087
      if (opt_xml)
2039
2088
      {
2041
2090
        check_io(md_result_file);
2042
2091
      }
2043
2092
 
2044
 
      for (i= 0; i < drizzleclient_num_fields(res); i++)
 
2093
      for (i= 0; i < drizzle_result_column_count(&result); i++)
2045
2094
      {
2046
2095
        int is_blob;
2047
2096
        uint32_t length= lengths[i];
2048
2097
 
2049
 
        if (!(field= drizzleclient_fetch_field(res)))
 
2098
        if (!(column= drizzle_column_next(&result)))
2050
2099
          die(EX_CONSCHECK,
2051
2100
                      _("Not enough fields from table %s! Aborting.\n"),
2052
2101
                      result_table);
2056
2105
           we have not a BLOB but a TEXT column.
2057
2106
           we'll dump in hex only BLOB columns.
2058
2107
        */
2059
 
        is_blob= (opt_hex_blob && field->charsetnr == 63 &&
2060
 
                  (field->type == DRIZZLE_TYPE_VARCHAR ||
2061
 
                   field->type == DRIZZLE_TYPE_BLOB)) ? 1 : 0;
 
2108
        is_blob= (opt_hex_blob && drizzle_column_charset(column) == 63 &&
 
2109
                  (drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_VARCHAR ||
 
2110
                   drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_BLOB)) ? 1 : 0;
2062
2111
        if (extended_insert && !opt_xml)
2063
2112
        {
2064
2113
          if (i == 0)
2073
2122
          {
2074
2123
            if (length)
2075
2124
            {
2076
 
              if (!(field->type & NUM_FLAG))
 
2125
              if (!(drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_NUM))
2077
2126
              {
2078
2127
                /*
2079
2128
                  "length * 2 + 2" is OK for both HEX and non-HEX modes:
2088
2137
                if (opt_hex_blob && is_blob)
2089
2138
                {
2090
2139
                  extended_row.append("0x");
2091
 
                  drizzleclient_drizzleclient_octet2hex(tmp_str, row[i], length);
 
2140
                  drizzle_hex_string(tmp_str, row[i], length);
2092
2141
                  extended_row.append(tmp_str);
2093
2142
                }
2094
2143
                else
2095
2144
                {
2096
2145
                  extended_row.append("'");
2097
 
                  drizzleclient_escape_string(tmp_str,
2098
 
                                        row[i],length);
 
2146
                  drizzle_escape_string(tmp_str, row[i],length);
2099
2147
                  extended_row.append(tmp_str);
2100
2148
                  extended_row.append("'");
2101
2149
                }
2129
2177
          }
2130
2178
          if (row[i])
2131
2179
          {
2132
 
            if (!(field->type & NUM_FLAG))
 
2180
            if (!(drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_NUM))
2133
2181
            {
2134
2182
              if (opt_xml)
2135
2183
              {
2137
2185
                {
2138
2186
                  /* Define xsi:type="xs:hexBinary" for hex encoded data */
2139
2187
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2140
 
                                field->name, "xsi:type=", "xs:hexBinary", NULL);
 
2188
                                drizzle_column_name(column), "xsi:type=", "xs:hexBinary", NULL);
2141
2189
                  print_blob_as_hex(md_result_file, row[i], length);
2142
2190
                }
2143
2191
                else
2144
2192
                {
2145
2193
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2146
 
                                field->name, NULL);
 
2194
                                drizzle_column_name(column), NULL);
2147
2195
                  print_quoted_xml(md_result_file, row[i], length);
2148
2196
                }
2149
2197
                fputs("</field>\n", md_result_file);
2163
2211
              if (opt_xml)
2164
2212
              {
2165
2213
                print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2166
 
                        field->name, NULL);
 
2214
                        drizzle_column_name(column), NULL);
2167
2215
                fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
2168
2216
                      md_result_file);
2169
2217
                fputs("</field>\n", md_result_file);
2182
2230
              fputs("NULL", md_result_file);
2183
2231
            else
2184
2232
              print_xml_null_tag(md_result_file, "\t\t", "field name=",
2185
 
                                 field->name, "\n");
 
2233
                                 drizzle_column_name(column), "\n");
2186
2234
          }
2187
2235
          check_io(md_result_file);
2188
2236
        }
2231
2279
      fputs(";\n", md_result_file);             /* If not empty table */
2232
2280
    fflush(md_result_file);
2233
2281
    check_io(md_result_file);
2234
 
    if (drizzleclient_errno(drizzle))
2235
 
    {
2236
 
      snprintf(buf, sizeof(buf),
2237
 
               _("%s: Error %d: %s when dumping table %s at row: %d\n"),
2238
 
               my_progname,
2239
 
               drizzleclient_errno(drizzle),
2240
 
               drizzleclient_error(drizzle),
2241
 
               result_table,
2242
 
               rownr);
2243
 
      fputs(buf,stderr);
2244
 
      error= EX_CONSCHECK;
2245
 
      goto err;
2246
 
    }
2247
2282
 
2248
2283
    /* Moved enable keys to before unlock per bug 15977 */
2249
2284
    if (opt_disable_keys)
2262
2297
      fprintf(md_result_file, "commit;\n");
2263
2298
      check_io(md_result_file);
2264
2299
    }
2265
 
    drizzleclient_free_result(res);
 
2300
    drizzle_result_free(&result);
2266
2301
  }
2267
2302
  return;
2268
2303
 
2274
2309
 
2275
2310
static char *getTableName(int reset)
2276
2311
{
2277
 
  static drizzle_result_st *res= NULL;
2278
 
  drizzle_row_t    row;
 
2312
  static drizzle_result_st result;
 
2313
  static bool have_result= false;
 
2314
  drizzle_row_t row;
2279
2315
 
2280
 
  if (!res)
 
2316
  if (!have_result)
2281
2317
  {
2282
 
    if (!(res= drizzleclient_list_tables(drizzle,NULL)))
2283
 
      return(NULL);
 
2318
    if (drizzleclient_query_with_error_report(&dcon, &result, "SHOW TABLES", false))
 
2319
      return NULL;
 
2320
    have_result= true;
2284
2321
  }
2285
 
  if ((row= drizzleclient_fetch_row(res)))
2286
 
    return((char*) row[0]);
 
2322
 
 
2323
  if ((row= drizzle_row_next(&result)))
 
2324
    return row[0];
2287
2325
 
2288
2326
  if (reset)
2289
 
    drizzleclient_data_seek(res,0);      /* We want to read again */
 
2327
    drizzle_row_seek(&result, 0);
2290
2328
  else
2291
2329
  {
2292
 
    drizzleclient_free_result(res);
2293
 
    res= NULL;
 
2330
    drizzle_result_free(&result);
 
2331
    have_result= false;
2294
2332
  }
2295
 
  return(NULL);
 
2333
  return NULL;
2296
2334
} /* getTableName */
2297
2335
 
2298
2336
 
2299
2337
static int dump_all_databases()
2300
2338
{
2301
2339
  drizzle_row_t row;
2302
 
  drizzle_result_st *tableres;
 
2340
  drizzle_result_st tableres;
2303
2341
  int result=0;
2304
2342
 
2305
 
  if (drizzleclient_query_with_error_report(dcon, &tableres, "SHOW DATABASES"))
 
2343
  if (drizzleclient_query_with_error_report(&dcon, &tableres, "SHOW DATABASES", false))
2306
2344
    return 1;
2307
 
  while ((row= drizzleclient_fetch_row(tableres)))
 
2345
  while ((row= drizzle_row_next(&tableres)))
2308
2346
  {
2309
2347
    if (dump_all_tables_in_db(row[0]))
2310
2348
      result=1;
2311
2349
  }
 
2350
  drizzle_result_free(&tableres);
2312
2351
  return result;
2313
2352
}
2314
2353
/* dump_all_databases */
2343
2382
 
2344
2383
int init_dumping_tables(char *qdatabase)
2345
2384
{
2346
 
 
2347
 
 
2348
2385
  if (!opt_create_db)
2349
2386
  {
2350
2387
    char qbuf[256];
2351
2388
    drizzle_row_t row;
2352
 
    drizzle_result_st *dbinfo;
 
2389
    drizzle_result_st result;
 
2390
    drizzle_return_t ret;
2353
2391
 
2354
2392
    snprintf(qbuf, sizeof(qbuf),
2355
2393
             "SHOW CREATE DATABASE IF NOT EXISTS %s",
2356
2394
             qdatabase);
2357
2395
 
2358
 
    if (drizzleclient_query(drizzle, qbuf) || !(dbinfo = drizzleclient_store_result(drizzle)))
 
2396
    if (drizzle_query_str(&dcon, &result, qbuf, &ret) == NULL ||
 
2397
        ret != DRIZZLE_RETURN_OK)
2359
2398
    {
 
2399
      if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
2400
        drizzle_result_free(&result);
 
2401
 
2360
2402
      /* Old server version, dump generic CREATE DATABASE */
2361
2403
      if (opt_drop_database)
2362
2404
        fprintf(md_result_file,
2368
2410
    }
2369
2411
    else
2370
2412
    {
2371
 
      if (opt_drop_database)
2372
 
        fprintf(md_result_file,
2373
 
                "\nDROP DATABASE IF EXISTS %s;\n",
2374
 
                qdatabase);
2375
 
      row = drizzleclient_fetch_row(dbinfo);
2376
 
      if (row[1])
 
2413
      if (drizzle_result_buffer(&result) == DRIZZLE_RETURN_OK)
2377
2414
      {
2378
 
        fprintf(md_result_file,"\n%s;\n",row[1]);
 
2415
        if (opt_drop_database)
 
2416
          fprintf(md_result_file,
 
2417
                  "\nDROP DATABASE IF EXISTS %s;\n",
 
2418
                  qdatabase);
 
2419
        row = drizzle_row_next(&result);
 
2420
        if (row != NULL && row[1])
 
2421
        {
 
2422
          fprintf(md_result_file,"\n%s;\n",row[1]);
 
2423
        }
2379
2424
      }
2380
 
      drizzleclient_free_result(dbinfo);
 
2425
      drizzle_result_free(&result);
2381
2426
    }
2382
2427
  }
2383
2428
  return(0);
2386
2431
 
2387
2432
static int init_dumping(char *database, int init_func(char*))
2388
2433
{
2389
 
  if (drizzleclient_get_server_version(drizzle) >= 50003 &&
2390
 
      !my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
 
2434
  drizzle_result_st result;
 
2435
  drizzle_return_t ret;
 
2436
 
 
2437
  if (!my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
2391
2438
    return 1;
2392
2439
 
2393
 
  if (drizzleclient_select_db(drizzle, database))
 
2440
  if (drizzle_select_db(&dcon, &result, database, &ret) == NULL ||
 
2441
        ret != DRIZZLE_RETURN_OK)
2394
2442
  {
2395
 
    DB_error(drizzle, _("when selecting the database"));
 
2443
    DB_error(&result, ret, _("when executing 'SELECT INTO OUTFILE'"));
2396
2444
    return 1;                   /* If --force */
2397
2445
  }
 
2446
  drizzle_result_free(&result);
 
2447
 
2398
2448
  if (!path && !opt_xml)
2399
2449
  {
2400
2450
    if (opt_databases || opt_alldbs)
2402
2452
      /*
2403
2453
        length of table name * 2 (if name contains quotes), 2 quotes and 0
2404
2454
      */
2405
 
      char quoted_database_buf[NAME_LEN*2+3];
 
2455
      char quoted_database_buf[DRIZZLE_MAX_DB_SIZE*2+3];
2406
2456
      char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
2407
2457
      if (opt_comments)
2408
2458
      {
2435
2485
{
2436
2486
  char *table;
2437
2487
  uint32_t numrows;
2438
 
  char table_buff[NAME_LEN*2+3];
2439
 
  char hash_key[2*NAME_LEN+2];  /* "db.tablename" */
 
2488
  char table_buff[DRIZZLE_MAX_TABLE_SIZE*2+3];
 
2489
  char hash_key[DRIZZLE_MAX_DB_SIZE+DRIZZLE_MAX_TABLE_SIZE+2];  /* "db.tablename" */
2440
2490
  char *afterdot;
 
2491
  drizzle_result_st result;
 
2492
  drizzle_return_t ret;
2441
2493
 
2442
2494
  afterdot= strcpy(hash_key, database) + strlen(database);
2443
2495
  *afterdot++= '.';
2459
2511
        query.append( " READ LOCAL,");
2460
2512
      }
2461
2513
    }
2462
 
    if (numrows && drizzleclient_real_query(drizzle, query.c_str(), query.length()-1))
2463
 
      DB_error(drizzle, _("when using LOCK TABLES"));
2464
 
            /* We shall continue here, if --force was given */
 
2514
    if (numrows)
 
2515
    {
 
2516
      if (drizzle_query(&dcon, &result, query.c_str(),
 
2517
                        query.length()-1, &ret) == NULL ||
 
2518
          ret != DRIZZLE_RETURN_OK)
 
2519
      {
 
2520
        DB_error(&result, ret, _("when using LOCK TABLES"));
 
2521
        /* We shall continue here, if --force was given */
 
2522
      }
 
2523
      else
 
2524
        drizzle_result_free(&result);
 
2525
    }
2465
2526
    query.clear();
2466
2527
  }
2467
2528
  if (flush_logs)
2468
2529
  {
2469
 
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
2470
 
      DB_error(drizzle, _("when doing refresh"));
2471
 
           /* We shall continue here, if --force was given */
 
2530
    if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
 
2531
        ret != DRIZZLE_RETURN_OK)
 
2532
    {
 
2533
      DB_error(&result, ret, _("when doing refresh"));
 
2534
      /* We shall continue here, if --force was given */
 
2535
    }
 
2536
    else
 
2537
      drizzle_result_free(&result);
2472
2538
  }
2473
2539
  while ((table= getTableName(0)))
2474
2540
  {
2486
2552
    check_io(md_result_file);
2487
2553
  }
2488
2554
  if (lock_tables)
2489
 
    drizzleclient_query_with_error_report(dcon, &result, "UNLOCK TABLES");
 
2555
  {
 
2556
    if (!drizzleclient_query_with_error_report(&dcon, &result, "UNLOCK TABLES", false))
 
2557
      drizzle_result_free(&result);
 
2558
  }
2490
2559
 
2491
2560
  return(0);
2492
2561
} /* dump_all_tables_in_db */
2506
2575
static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root)
2507
2576
{
2508
2577
  char *name= 0;
2509
 
  drizzle_result_st  *table_res;
 
2578
  drizzle_result_st result;
2510
2579
  drizzle_row_t  row;
2511
 
  char query[50 + 2*NAME_LEN];
 
2580
  char query[50 + 2*DRIZZLE_MAX_TABLE_SIZE];
2512
2581
  char show_name_buff[FN_REFLEN];
 
2582
  uint64_t num_rows;
2513
2583
 
2514
2584
 
2515
2585
  /* Check memory for quote_for_like() */
2517
2587
  snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2518
2588
           quote_for_like(old_table_name, show_name_buff));
2519
2589
 
2520
 
  if (drizzleclient_query_with_error_report(dcon, &result, query))
 
2590
  if (drizzleclient_query_with_error_report(&dcon, &result, query, false))
2521
2591
    return NULL;
2522
2592
 
2523
 
  if ((table_res= drizzleclient_store_result(drizzle)))
 
2593
  num_rows= drizzle_result_row_count(&result);
 
2594
  if (num_rows > 0)
2524
2595
  {
2525
 
    uint64_t num_rows= drizzleclient_num_rows(table_res);
2526
 
    if (num_rows > 0)
2527
 
    {
2528
 
      uint32_t *lengths;
2529
 
      /*
2530
 
        Return first row
2531
 
        TODO: Return all matching rows
2532
 
      */
2533
 
      row= drizzleclient_fetch_row(table_res);
2534
 
      lengths= drizzleclient_fetch_lengths(table_res);
2535
 
      name= strmake_root(root, row[0], lengths[0]);
2536
 
    }
2537
 
    drizzleclient_free_result(table_res);
 
2596
    size_t *lengths;
 
2597
    /*
 
2598
      Return first row
 
2599
      TODO: Return all matching rows
 
2600
    */
 
2601
    row= drizzle_row_next(&result);
 
2602
    lengths= drizzle_row_field_sizes(&result);
 
2603
    name= strmake_root(root, row[0], lengths[0]);
2538
2604
  }
 
2605
  drizzle_result_free(&result);
 
2606
 
2539
2607
  return(name);
2540
2608
}
2541
2609
 
2542
2610
 
2543
2611
static int dump_selected_tables(char *db, char **table_names, int tables)
2544
2612
{
2545
 
  char table_buff[NAME_LEN*2+3];
 
2613
  char table_buff[DRIZZLE_MAX_TABLE_SIZE*2+3];
2546
2614
  string lock_tables_query("LOCK TABLES ");
2547
2615
  MEM_ROOT root;
2548
2616
  char **dump_tables, **pos, **end;
 
2617
  drizzle_result_st result;
 
2618
  drizzle_return_t ret;
2549
2619
 
2550
2620
 
2551
2621
  if (init_dumping(db, init_dumping_tables))
2582
2652
 
2583
2653
  if (lock_tables)
2584
2654
  {
2585
 
    if (drizzleclient_real_query(drizzle, lock_tables_query.c_str(),
2586
 
                         lock_tables_query.length()-1))
 
2655
    if (drizzle_query(&dcon, &result, lock_tables_query.c_str(),
 
2656
                      lock_tables_query.length()-1, &ret) == NULL ||
 
2657
        ret != DRIZZLE_RETURN_OK)
2587
2658
    {
2588
2659
      if (!ignore_errors)
2589
2660
      {
2590
2661
        free_root(&root, MYF(0));
2591
2662
      }
2592
 
      DB_error(drizzle, _("when doing LOCK TABLES"));
2593
 
       /* We shall countinue here, if --force was given */
 
2663
      DB_error(&result, ret, _("when doing LOCK TABLES"));
 
2664
      /* We shall countinue here, if --force was given */
2594
2665
    }
 
2666
    else
 
2667
      drizzle_result_free(&result);
2595
2668
  }
2596
2669
  if (flush_logs)
2597
2670
  {
2598
 
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
 
2671
    if (drizzle_query_str(&dcon, &result, "FLUSH LOGS", &ret) == NULL ||
 
2672
        ret != DRIZZLE_RETURN_OK)
2599
2673
    {
2600
2674
      if (!ignore_errors)
2601
2675
        free_root(&root, MYF(0));
2602
 
      DB_error(drizzle, _("when doing refresh"));
 
2676
      DB_error(&result, ret, _("when doing refresh"));
 
2677
      /* We shall countinue here, if --force was given */
2603
2678
    }
2604
 
     /* We shall countinue here, if --force was given */
 
2679
    else
 
2680
      drizzle_result_free(&result);
2605
2681
  }
2606
2682
  if (opt_xml)
2607
2683
    print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
2619
2695
    check_io(md_result_file);
2620
2696
  }
2621
2697
  if (lock_tables)
2622
 
    drizzleclient_query_with_error_report(dcon, &result, "UNLOCK TABLES");
 
2698
  {
 
2699
    if (!(drizzleclient_query_with_error_report(&dcon, &result, "UNLOCK TABLES", false)))
 
2700
      drizzle_result_free(&result);
 
2701
  }
2623
2702
  return(0);
2624
2703
} /* dump_selected_tables */
2625
2704
 
2630
2709
  drizzle_result_st master;
2631
2710
  const char *comment_prefix=
2632
2711
    (opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2633
 
  if (drizzleclient_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
 
2712
  if (drizzleclient_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS", false))
2634
2713
  {
2635
2714
    return 1;
2636
2715
  }
2637
2716
  else
2638
2717
  {
2639
 
    row= drizzleclient_fetch_row(master);
 
2718
    row= drizzle_row_next(&master);
2640
2719
    if (row && row[0] && row[1])
2641
2720
    {
2642
2721
      /* SHOW MASTER STATUS reports file and position */
2654
2733
      /* SHOW MASTER STATUS reports nothing and --force is not enabled */
2655
2734
      my_printf_error(0, _("Error: Binlogging on server not active"),
2656
2735
                      MYF(0));
2657
 
      drizzleclient_free_result(master);
 
2736
      drizzle_result_free(&master);
2658
2737
      maybe_exit(EX_DRIZZLEERR);
2659
2738
      return 1;
2660
2739
    }
2661
 
    drizzleclient_free_result(master);
 
2740
    drizzle_result_free(&master);
2662
2741
  }
2663
2742
  return 0;
2664
2743
}
2665
2744
 
2666
 
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
 
2745
static int do_stop_slave_sql(drizzle_con_st *drizzle_con)
2667
2746
{
2668
 
  drizzle_result_st *slave;
 
2747
  drizzle_result_st slave;
2669
2748
  /* We need to check if the slave sql is running in the first place */
2670
 
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
 
2749
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2671
2750
    return(1);
2672
2751
  else
2673
2752
  {
2674
 
    drizzle_row_t row= drizzleclient_fetch_row(slave);
 
2753
    drizzle_row_t row= drizzle_row_next(&slave);
2675
2754
    if (row && row[11])
2676
2755
    {
2677
2756
      /* if SLAVE SQL is not running, we don't stop it */
2678
2757
      if (!strcmp(row[11],"No"))
2679
2758
      {
2680
 
        drizzleclient_free_result(slave);
 
2759
        drizzle_result_free(&slave);
2681
2760
        /* Silently assume that they don't have the slave running */
2682
2761
        return(0);
2683
2762
      }
2684
2763
    }
2685
2764
  }
2686
 
  drizzleclient_free_result(slave);
 
2765
  drizzle_result_free(&slave);
2687
2766
 
2688
2767
  /* now, stop slave if running */
2689
 
  if (drizzleclient_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
 
2768
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "STOP SLAVE SQL_THREAD", false))
2690
2769
    return(1);
 
2770
  drizzle_result_free(&slave);
2691
2771
 
2692
2772
  return(0);
2693
2773
}
2710
2790
  return(0);
2711
2791
}
2712
2792
 
2713
 
static int do_show_slave_status(DRIZZLE *drizzle_con)
 
2793
static int do_show_slave_status(drizzle_con_st *drizzle_con)
2714
2794
{
2715
 
  drizzle_result_st *slave;
 
2795
  drizzle_result_st slave;
2716
2796
  const char *comment_prefix=
2717
2797
    (opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2718
 
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
 
2798
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2719
2799
  {
2720
2800
    if (!ignore_errors)
2721
2801
    {
2726
2806
  }
2727
2807
  else
2728
2808
  {
2729
 
    drizzle_row_t row= drizzleclient_fetch_row(slave);
 
2809
    drizzle_row_t row= drizzle_row_next(&slave);
2730
2810
    if (row && row[9] && row[21])
2731
2811
    {
2732
2812
      /* SHOW MASTER STATUS reports file and position */
2749
2829
 
2750
2830
      check_io(md_result_file);
2751
2831
    }
2752
 
    drizzleclient_free_result(slave);
 
2832
    drizzle_result_free(&slave);
2753
2833
  }
2754
2834
  return 0;
2755
2835
}
2756
2836
 
2757
 
static int do_start_slave_sql(DRIZZLE *drizzle_con)
 
2837
static int do_start_slave_sql(drizzle_con_st *drizzle_con)
2758
2838
{
2759
 
  drizzle_result_st *slave;
 
2839
  drizzle_result_st slave;
2760
2840
  /* We need to check if the slave sql is stopped in the first place */
2761
 
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
 
2841
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS", false))
2762
2842
    return(1);
2763
2843
  else
2764
2844
  {
2765
 
    drizzle_row_t row= drizzleclient_fetch_row(slave);
 
2845
    drizzle_row_t row= drizzle_row_next(&slave);
2766
2846
    if (row && row[11])
2767
2847
    {
2768
2848
      /* if SLAVE SQL is not running, we don't start it */
2769
2849
      if (!strcmp(row[11],"Yes"))
2770
2850
      {
2771
 
        drizzleclient_free_result(slave);
 
2851
        drizzle_result_free(&slave);
2772
2852
        /* Silently assume that they don't have the slave running */
2773
2853
        return(0);
2774
2854
      }
2775
2855
    }
 
2856
    drizzle_result_free(&slave);
2776
2857
  }
2777
 
  drizzleclient_free_result(slave);
2778
2858
 
2779
2859
  /* now, start slave if stopped */
2780
 
  if (drizzleclient_query_with_error_report(drizzle_con, 0, "START SLAVE"))
 
2860
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "START SLAVE", false))
2781
2861
  {
2782
2862
    my_printf_error(0, _("Error: Unable to start slave"), MYF(0));
2783
2863
    return 1;
2784
2864
  }
 
2865
  drizzle_result_free(&slave);
2785
2866
  return(0);
2786
2867
}
2787
2868
 
2788
2869
 
2789
2870
 
2790
 
static int do_flush_tables_read_lock(DRIZZLE *drizzle_con)
 
2871
static int do_flush_tables_read_lock(drizzle_con_st *drizzle_con)
2791
2872
{
2792
2873
  /*
2793
2874
    We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
2798
2879
    update starts between the two FLUSHes, we have that bad stall.
2799
2880
  */
2800
2881
  return
2801
 
    ( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
 
2882
    ( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES", false) ||
2802
2883
      drizzleclient_query_with_error_report(drizzle_con, 0,
2803
 
                                    "FLUSH TABLES WITH READ LOCK") );
 
2884
                                    "FLUSH TABLES WITH READ LOCK", false) );
2804
2885
}
2805
2886
 
2806
2887
 
2807
 
static int do_unlock_tables(DRIZZLE *drizzle_con)
 
2888
static int do_unlock_tables(drizzle_con_st *drizzle_con)
2808
2889
{
2809
 
  return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
 
2890
  return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES", false);
2810
2891
}
2811
2892
 
2812
 
static int get_bin_log_name(DRIZZLE *drizzle_con,
 
2893
static int get_bin_log_name(drizzle_con_st *drizzle_con,
2813
2894
                            char* buff_log_name, uint32_t buff_len)
2814
2895
{
2815
 
  drizzle_result_st *res;
 
2896
  drizzle_result_st res;
2816
2897
  drizzle_row_t row;
2817
2898
 
2818
 
  if (drizzleclient_query(drizzle_con, "SHOW MASTER STATUS") ||
2819
 
      !(res= drizzleclient_store_result(drizzle)))
 
2899
  if (drizzleclient_query_with_error_report(drizzle_con, &res, "SHOW MASTER STATUS", false))
2820
2900
    return 1;
2821
2901
 
2822
 
  if (!(row= drizzleclient_fetch_row(res)))
 
2902
  if (!(row= drizzle_row_next(&res)))
2823
2903
  {
2824
 
    drizzleclient_free_result(res);
 
2904
    drizzle_result_free(&res);
2825
2905
    return 1;
2826
2906
  }
2827
2907
  /*
2830
2910
  */
2831
2911
  strncpy(buff_log_name, row[0], buff_len - 1);
2832
2912
 
2833
 
  drizzleclient_free_result(res);
 
2913
  drizzle_result_free(&res);
2834
2914
  return 0;
2835
2915
}
2836
2916
 
2837
 
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
 
2917
static int purge_bin_logs_to(drizzle_con_st *drizzle_con, char* log_name)
2838
2918
{
2839
2919
  int err;
2840
2920
  string str= "PURGE BINARY LOGS TO '";
2841
2921
  str.append(log_name);
2842
2922
  str.append("'");
2843
 
  err = drizzleclient_query_with_error_report(drizzle_con, 0, str.c_str());
2844
 
  return err;
 
2923
  drizzle_result_st res;
 
2924
  err= drizzleclient_query_with_error_report(drizzle_con, &res, str.c_str(),
 
2925
                                             false);
 
2926
  if (err)
 
2927
    return err;
 
2928
  drizzle_result_free(&res);
 
2929
  return 0;
2845
2930
}
2846
2931
 
2847
2932
 
2848
 
static int start_transaction(DRIZZLE *drizzle_con)
 
2933
static int start_transaction(drizzle_con_st *drizzle_con)
2849
2934
{
2850
2935
  return (drizzleclient_query_with_error_report(drizzle_con, 0,
2851
2936
                                        "SET SESSION TRANSACTION ISOLATION "
2852
 
                                        "LEVEL REPEATABLE READ") ||
 
2937
                                        "LEVEL REPEATABLE READ", false) ||
2853
2938
          drizzleclient_query_with_error_report(drizzle_con, 0,
2854
2939
                                        "START TRANSACTION "
2855
 
                                        "WITH CONSISTENT SNAPSHOT"));
 
2940
                                        "WITH CONSISTENT SNAPSHOT", false));
2856
2941
}
2857
2942
 
2858
2943
 
2902
2987
                        const char *prefix, const char *name,
2903
2988
                        int string_value)
2904
2989
{
2905
 
  DRIZZLE_FIELD   *field;
2906
 
  drizzleclient_field_seek(result, 0);
 
2990
  drizzle_column_st *column;
 
2991
  drizzle_column_seek(result, 0);
2907
2992
 
2908
 
  for ( ; (field= drizzleclient_fetch_field(result)) ; row++)
 
2993
  for ( ; (column= drizzle_column_next(result)) ; row++)
2909
2994
  {
2910
 
    if (!strcmp(field->name,name))
 
2995
    if (!strcmp(drizzle_column_name(column),name))
2911
2996
    {
2912
2997
      if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */
2913
2998
      {
2932
3017
 
2933
3018
static const char* fetch_named_row(drizzle_result_st *result, drizzle_row_t row, const char *name)
2934
3019
{
2935
 
  DRIZZLE_FIELD   *field;
2936
 
  drizzleclient_field_seek(result, 0);
2937
 
  for ( ; (field= drizzleclient_fetch_field(result)) ; row++)
 
3020
  drizzle_column_st *column;
 
3021
  drizzle_column_seek(result, 0);
 
3022
 
 
3023
  for ( ; (column= drizzle_column_next(result)) ; row++)
2938
3024
  {
2939
 
    if (!strcmp(field->name,name))
 
3025
    if (!strcmp(drizzle_column_name(column),name))
2940
3026
    {
2941
3027
      if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */
2942
3028
      {
2943
 
        drizzleclient_field_seek(result, 0);
 
3029
        drizzle_column_seek(result, 0);
2944
3030
        return row[0];
2945
3031
      }
2946
3032
    }
2947
3033
  }
2948
 
  drizzleclient_field_seek(result, 0);
 
3034
  drizzle_column_seek(result, 0);
2949
3035
  return NULL;
2950
3036
}
2951
3037
 
2979
3065
  char result= IGNORE_NONE;
2980
3066
  char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
2981
3067
  const char *number_of_rows= NULL;
2982
 
  drizzle_result_st *res= NULL;
 
3068
  drizzle_result_st res;
2983
3069
  drizzle_row_t row;
2984
3070
 
2985
3071
  /* Check memory for quote_for_like() */
2986
3072
  assert(2*sizeof(table_name) < sizeof(show_name_buff));
2987
3073
  snprintf(buff, sizeof(buff), "show table status like %s",
2988
3074
           quote_for_like(table_name, show_name_buff));
2989
 
  if (drizzleclient_query_with_error_report(drizzle, &res, buff))
 
3075
  if (drizzleclient_query_with_error_report(&dcon, &res, buff, false))
2990
3076
  {
2991
 
    if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
2992
 
    {                                   /* If old DRIZZLE version */
2993
 
      verbose_msg(_("-- Warning: Couldn't get status information for "
2994
 
                  "table %s (%s)\n"), table_name, drizzleclient_error(drizzle));
2995
 
      return(result);                       /* assume table is ok */
2996
 
    }
 
3077
    return result;
2997
3078
  }
2998
 
  if (!(row= drizzleclient_fetch_row(res)))
 
3079
  if (!(row= drizzle_row_next(&res)))
2999
3080
  {
3000
3081
    fprintf(stderr,
3001
 
            _("Error: Couldn't read status information for table %s (%s)\n"),
3002
 
            table_name, drizzleclient_error(drizzle));
3003
 
    drizzleclient_free_result(res);
 
3082
            _("Error: Couldn't read status information for table %s\n"),
 
3083
            table_name);
 
3084
    drizzle_result_free(&res);
3004
3085
    return(result);                         /* assume table is ok */
3005
3086
  }
3006
3087
  else
3007
3088
  {
3008
 
    if ((number_of_rows= fetch_named_row(res, row, "Rows")) != NULL)
 
3089
    if ((number_of_rows= fetch_named_row(&res, row, "Rows")) != NULL)
3009
3090
    {
3010
3091
      total_rows= strtoul(number_of_rows, NULL, 10);
3011
3092
    }
3017
3098
    the table type is _NOT_ one of these types
3018
3099
    */
3019
3100
  {
3020
 
    strncpy(table_type, row[1], NAME_LEN-1);
 
3101
    strncpy(table_type, row[1], DRIZZLE_MAX_TABLE_SIZE-1);
3021
3102
    if (opt_delayed)
3022
3103
    {
3023
3104
      if (strcmp(table_type,"MyISAM") &&
3027
3108
        result= IGNORE_INSERT_DELAYED;
3028
3109
    }
3029
3110
  }
3030
 
  drizzleclient_free_result(res);
 
3111
  drizzle_result_free(&res);
3031
3112
  return(result);
3032
3113
}
3033
3114
 
3052
3133
 
3053
3134
static char *primary_key_fields(const char *table_name)
3054
3135
{
3055
 
  drizzle_result_st  *res= NULL;
 
3136
  drizzle_result_st res;
 
3137
  drizzle_return_t ret;
3056
3138
  drizzle_row_t  row;
3057
3139
  /* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3058
 
  char show_keys_buff[15 + NAME_LEN * 2 + 3];
 
3140
  char show_keys_buff[15 + DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
3059
3141
  uint32_t result_length= 0;
3060
3142
  char *result= 0;
3061
 
  char buff[NAME_LEN * 2 + 3];
 
3143
  char buff[DRIZZLE_MAX_TABLE_SIZE * 2 + 3];
3062
3144
  char *quoted_field;
3063
3145
 
3064
3146
  snprintf(show_keys_buff, sizeof(show_keys_buff),
3065
3147
           "SHOW KEYS FROM %s", table_name);
3066
 
  if (drizzleclient_query(drizzle, show_keys_buff) ||
3067
 
      !(res= drizzleclient_store_result(drizzle)))
 
3148
  if (drizzle_query_str(&dcon, &res, show_keys_buff, &ret) == NULL ||
 
3149
      ret != DRIZZLE_RETURN_OK)
 
3150
  {
 
3151
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
3152
    {
 
3153
      fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
 
3154
              " records are NOT sorted (%s)\n"),
 
3155
              table_name, drizzle_result_error(&res));
 
3156
      drizzle_result_free(&res);
 
3157
    }
 
3158
    else
 
3159
    {
 
3160
      fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
 
3161
              " records are NOT sorted (%s)\n"),
 
3162
              table_name, drizzle_con_error(&dcon));
 
3163
    }
 
3164
 
 
3165
    return result;
 
3166
  }
 
3167
 
 
3168
  if (drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3068
3169
  {
3069
3170
    fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
3070
3171
            " records are NOT sorted (%s)\n"),
3071
 
            table_name, drizzleclient_error(drizzle));
3072
 
    /* Don't exit, because it's better to print out unsorted records */
3073
 
    goto cleanup;
 
3172
            table_name, drizzle_con_error(&dcon));
 
3173
    return result;
3074
3174
  }
3075
3175
 
3076
3176
  /*
3079
3179
   * row, and UNIQUE keys come before others.  So we only need to check
3080
3180
   * the first key, not all keys.
3081
3181
   */
3082
 
  if ((row= drizzleclient_fetch_row(res)) && atoi(row[1]) == 0)
 
3182
  if ((row= drizzle_row_next(&res)) && atoi(row[1]) == 0)
3083
3183
  {
3084
3184
    /* Key is unique */
3085
3185
    do
3086
3186
    {
3087
3187
      quoted_field= quote_name(row[4], buff, 0);
3088
3188
      result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3089
 
    } while ((row= drizzleclient_fetch_row(res)) && atoi(row[3]) > 1);
 
3189
    } while ((row= drizzle_row_next(&res)) && atoi(row[3]) > 1);
3090
3190
  }
3091
3191
 
3092
3192
  /* Build the ORDER BY clause result */
3098
3198
    if (!result)
3099
3199
    {
3100
3200
      fprintf(stderr, _("Error: Not enough memory to store ORDER BY clause\n"));
3101
 
      goto cleanup;
 
3201
      drizzle_result_free(&res);
 
3202
      return result;
3102
3203
    }
3103
 
    drizzleclient_data_seek(res, 0);
3104
 
    row= drizzleclient_fetch_row(res);
 
3204
    drizzle_row_seek(&res, 0);
 
3205
    row= drizzle_row_next(&res);
3105
3206
    quoted_field= quote_name(row[4], buff, 0);
3106
3207
    end= strcpy(result, quoted_field) + strlen(quoted_field);
3107
 
    while ((row= drizzleclient_fetch_row(res)) && atoi(row[3]) > 1)
 
3208
    while ((row= drizzle_row_next(&res)) && atoi(row[3]) > 1)
3108
3209
    {
3109
3210
      quoted_field= quote_name(row[4], buff, 0);
3110
3211
      end+= sprintf(end,",%s",quoted_field);
3111
3212
    }
3112
3213
  }
3113
3214
 
3114
 
cleanup:
3115
 
  if (res)
3116
 
    drizzleclient_free_result(res);
3117
 
 
 
3215
  drizzle_result_free(&res);
3118
3216
  return result;
3119
3217
}
3120
3218
 
3124
3222
  char bin_log_name[FN_REFLEN];
3125
3223
  int exit_code;
3126
3224
  MY_INIT("drizzledump");
 
3225
  drizzle_result_st result;
3127
3226
 
3128
3227
  compatible_mode_normal_str[0]= 0;
3129
3228
  default_charset= (char *)drizzle_universal_client_charset;
3144
3243
  if (!path)
3145
3244
    write_header(md_result_file, *argv);
3146
3245
 
3147
 
  if (opt_slave_data && do_stop_slave_sql(drizzle))
 
3246
  if (opt_slave_data && do_stop_slave_sql(&dcon))
3148
3247
    goto err;
3149
3248
 
3150
3249
  if ((opt_lock_all_tables || opt_master_data) &&
3151
 
      do_flush_tables_read_lock(drizzle))
 
3250
      do_flush_tables_read_lock(&dcon))
3152
3251
    goto err;
3153
 
  if (opt_single_transaction && start_transaction(drizzle))
 
3252
  if (opt_single_transaction && start_transaction(&dcon))
3154
3253
      goto err;
3155
3254
  if (opt_delete_master_logs)
3156
3255
  {
3157
 
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")) ||
3158
 
        get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
 
3256
    if (drizzleclient_query_with_error_report(&dcon, &result, "FLUSH LOGS", false))
 
3257
      goto err;
 
3258
    drizzle_result_free(&result);
 
3259
    if (get_bin_log_name(&dcon, bin_log_name, sizeof(bin_log_name)))
3159
3260
      goto err;
3160
3261
    flush_logs= 0;
3161
3262
  }
3162
3263
  if (opt_lock_all_tables || opt_master_data)
3163
3264
  {
3164
 
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
 
3265
    if (drizzleclient_query_with_error_report(&dcon, &result, "FLUSH LOGS", false))
3165
3266
      goto err;
 
3267
    drizzle_result_free(&result);
3166
3268
    flush_logs= 0; /* not anymore; that would not be sensible */
3167
3269
  }
3168
3270
  /* Add 'STOP SLAVE to beginning of dump */
3169
3271
  if (opt_slave_apply && add_stop_slave())
3170
3272
    goto err;
3171
 
  if (opt_master_data && do_show_master_status(drizzle))
3172
 
    goto err;
3173
 
  if (opt_slave_data && do_show_slave_status(drizzle))
3174
 
    goto err;
3175
 
  if (opt_single_transaction && do_unlock_tables(drizzle)) /* unlock but no commit! */
 
3273
  if (opt_master_data && do_show_master_status(&dcon))
 
3274
    goto err;
 
3275
  if (opt_slave_data && do_show_slave_status(&dcon))
 
3276
    goto err;
 
3277
  if (opt_single_transaction && do_unlock_tables(&dcon)) /* unlock but no commit! */
3176
3278
    goto err;
3177
3279
 
3178
3280
  if (opt_alldbs)
3190
3292
  }
3191
3293
 
3192
3294
  /* if --dump-slave , start the slave sql thread */
3193
 
  if (opt_slave_data && do_start_slave_sql(drizzle))
 
3295
  if (opt_slave_data && do_start_slave_sql(&dcon))
3194
3296
    goto err;
3195
3297
 
3196
3298
  /* add 'START SLAVE' to end of dump */
3205
3307
    goto err;
3206
3308
  }
3207
3309
  /* everything successful, purge the old logs files */
3208
 
  if (opt_delete_master_logs && purge_bin_logs_to(drizzle, bin_log_name))
 
3310
  if (opt_delete_master_logs && purge_bin_logs_to(&dcon, bin_log_name))
3209
3311
    goto err;
3210
3312
 
3211
3313
  /*