~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Monty Taylor
  • Date: 2008-08-09 22:23:19 UTC
  • mto: (287.3.7 codestyle)
  • mto: This revision was merged to the branch mainline in revision 295.
  • Revision ID: monty@inaugust.com-20080809222319-8bkqup3b6r10bh1s
Replaced DYN string in drizzledump.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
#define DUMP_VERSION "10.13"
40
40
 
 
41
#include <string>
41
42
#include "client_priv.h"
42
43
 
43
44
#include <mysys/my_sys.h>
48
49
 
49
50
#include <drizzled/error.h>
50
51
 
 
52
using namespace std;
51
53
/* Exit codes */
52
54
 
53
55
#define EX_USAGE 1
73
75
#define IGNORE_DATA 0x01 /* don't dump data for this table */
74
76
#define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */
75
77
 
76
 
static void add_load_option(DYNAMIC_STRING *str, const char *option,
77
 
                             const char *option_value);
 
78
static void add_load_option(string &str, const char *option,
 
79
                            const char *option_value);
78
80
static ulong find_set(TYPELIB *lib, const char *x, uint length,
79
81
                      char **err_pos, uint *err_len);
80
82
 
81
 
static void field_escape(DYNAMIC_STRING* in, const char *from);
 
83
static void field_escape(string &in, const char *from);
82
84
static bool  verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
83
85
                quick= 1, extended_insert= 1,
84
86
                lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
97
99
                opt_include_master_host_port= 0,
98
100
                opt_events= 0,
99
101
                opt_alltspcs=0, opt_notspcs= 0;
100
 
static bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
 
102
static bool debug_info_flag= 0, debug_check_flag= 0;
101
103
static ulong opt_max_allowed_packet, opt_net_buffer_length;
102
104
static DRIZZLE drizzle_connection,*drizzle=0;
103
 
static DYNAMIC_STRING insert_pat;
 
105
static string insert_pat;
104
106
static char  *opt_password=0,*current_user=0,
105
107
             *current_host=0,*path=0,*fields_terminated=0,
106
108
             *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
121
123
static uint opt_slave_data;
122
124
static uint my_end_arg;
123
125
static int   first_error=0;
124
 
static DYNAMIC_STRING extended_row;
 
126
static string extended_row;
125
127
FILE *md_result_file= 0;
126
128
FILE *stderror_file=0;
127
129
 
128
130
static uint opt_protocol= DRIZZLE_PROTOCOL_TCP;
129
131
 
130
132
/*
131
 
Dynamic_string wrapper functions. In this file use these
132
 
wrappers, they will terminate the process if there is
133
 
an allocation failure.
134
 
*/
135
 
static void init_dynamic_string_checked(DYNAMIC_STRING *str, const char *init_str,
136
 
                            uint init_alloc, uint alloc_increment);
137
 
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src);
138
 
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str);
139
 
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
140
 
                          uint length);
141
 
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size);
142
 
/*
143
133
  Constant for detection of default value of default_charset.
144
134
  If default_charset is equal to drizzle_universal_client_charset, then
145
135
  it is the default value which assigned at the very beginning of main().
1057
1047
  my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
1058
1048
  if (hash_inited(&ignore_table))
1059
1049
    hash_free(&ignore_table);
1060
 
  if (extended_insert)
1061
 
    dynstr_free(&extended_row);
1062
 
  if (insert_pat_inited)
1063
 
    dynstr_free(&insert_pat);
1064
1050
  if (defaults_argv)
1065
1051
    free_defaults(defaults_argv);
1066
1052
  my_end(my_end_arg);
1490
1476
  if ((write_data= !(*ignore_flag & IGNORE_DATA)))
1491
1477
  {
1492
1478
    complete_insert= opt_complete_insert;
1493
 
    if (!insert_pat_inited)
1494
 
    {
1495
 
      insert_pat_inited= 1;
1496
 
      init_dynamic_string_checked(&insert_pat, "", 1024, 1024);
1497
 
    }
1498
 
    else
1499
 
      dynstr_set_checked(&insert_pat, "");
 
1479
    insert_pat= "";
1500
1480
  }
1501
1481
 
1502
1482
  insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " :
1690
1670
    if (write_data)
1691
1671
    {
1692
1672
      if (opt_replace_into)
1693
 
        dynstr_append_checked(&insert_pat, "REPLACE ");
 
1673
        insert_pat.append("REPLACE ");
1694
1674
      else
1695
 
        dynstr_append_checked(&insert_pat, "INSERT ");
1696
 
      dynstr_append_checked(&insert_pat, insert_option);
1697
 
      dynstr_append_checked(&insert_pat, "INTO ");
1698
 
      dynstr_append_checked(&insert_pat, opt_quoted_table);
 
1675
        insert_pat.append("INSERT ");
 
1676
      insert_pat.append(insert_option);
 
1677
      insert_pat.append("INTO ");
 
1678
      insert_pat.append(opt_quoted_table);
1699
1679
      if (complete_insert)
1700
1680
      {
1701
 
        dynstr_append_checked(&insert_pat, " (");
 
1681
        insert_pat.append(" (");
1702
1682
      }
1703
1683
      else
1704
1684
      {
1705
 
        dynstr_append_checked(&insert_pat, " VALUES ");
 
1685
        insert_pat.append(" VALUES ");
1706
1686
        if (!extended_insert)
1707
 
          dynstr_append_checked(&insert_pat, "(");
 
1687
          insert_pat.append("(");
1708
1688
      }
1709
1689
    }
1710
1690
 
1714
1694
      {
1715
1695
        if (init)
1716
1696
        {
1717
 
          dynstr_append_checked(&insert_pat, ", ");
 
1697
          insert_pat.append(", ");
1718
1698
        }
1719
1699
        init=1;
1720
 
        dynstr_append_checked(&insert_pat,
1721
 
                      quote_name(row[SHOW_FIELDNAME], name_buff, 0));
 
1700
        insert_pat.append(quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1722
1701
      }
1723
1702
    }
1724
1703
    num_fields= drizzle_num_rows(result);
1759
1738
    if (write_data)
1760
1739
    {
1761
1740
      if (opt_replace_into)
1762
 
        dynstr_append_checked(&insert_pat, "REPLACE ");
 
1741
        insert_pat.append("REPLACE ");
1763
1742
      else
1764
 
        dynstr_append_checked(&insert_pat, "INSERT ");
1765
 
      dynstr_append_checked(&insert_pat, insert_option);
1766
 
      dynstr_append_checked(&insert_pat, "INTO ");
1767
 
      dynstr_append_checked(&insert_pat, result_table);
 
1743
        insert_pat.append("INSERT ");
 
1744
      insert_pat.append(insert_option);
 
1745
      insert_pat.append("INTO ");
 
1746
      insert_pat.append(result_table);
1768
1747
      if (complete_insert)
1769
 
        dynstr_append_checked(&insert_pat, " (");
 
1748
        insert_pat.append(" (");
1770
1749
      else
1771
1750
      {
1772
 
        dynstr_append_checked(&insert_pat, " VALUES ");
 
1751
        insert_pat.append(" VALUES ");
1773
1752
        if (!extended_insert)
1774
 
          dynstr_append_checked(&insert_pat, "(");
 
1753
          insert_pat.append("(");
1775
1754
      }
1776
1755
    }
1777
1756
 
1786
1765
          check_io(sql_file);
1787
1766
        }
1788
1767
        if (complete_insert)
1789
 
          dynstr_append_checked(&insert_pat, ", ");
 
1768
          insert_pat.append(", ");
1790
1769
      }
1791
1770
      init=1;
1792
1771
      if (complete_insert)
1793
 
        dynstr_append_checked(&insert_pat,
1794
 
                      quote_name(row[SHOW_FIELDNAME], name_buff, 0));
 
1772
        insert_pat.append(quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1795
1773
      if (!opt_no_create_info)
1796
1774
      {
1797
1775
        if (opt_xml)
1950
1928
  }
1951
1929
  if (complete_insert)
1952
1930
  {
1953
 
    dynstr_append_checked(&insert_pat, ") VALUES ");
 
1931
    insert_pat.append(") VALUES ");
1954
1932
    if (!extended_insert)
1955
 
      dynstr_append_checked(&insert_pat, "(");
 
1933
      insert_pat.append("(");
1956
1934
  }
1957
1935
  if (sql_file != md_result_file)
1958
1936
  {
1963
1941
  return((uint) num_fields);
1964
1942
} /* get_table_structure */
1965
1943
 
1966
 
static void add_load_option(DYNAMIC_STRING *str, const char *option,
1967
 
                             const char *option_value)
 
1944
static void add_load_option(string &str, const char *option,
 
1945
                            const char *option_value)
1968
1946
{
1969
1947
  if (!option_value)
1970
1948
  {
1972
1950
    return;
1973
1951
  }
1974
1952
 
1975
 
  dynstr_append_checked(str, option);
 
1953
  str.append(option);
1976
1954
  
1977
1955
  if (strncmp(option_value, "0x", sizeof("0x")-1) == 0)
1978
1956
  {
1979
1957
    /* It's a hex constant, don't escape */
1980
 
    dynstr_append_checked(str, option_value);
 
1958
    str.append(option_value);
1981
1959
  }
1982
1960
  else
1983
1961
  {
1994
1972
  syntax errors from the SQL parser.
1995
1973
*/
1996
1974
 
1997
 
static void field_escape(DYNAMIC_STRING* in, const char *from)
 
1975
static void field_escape(string &in, const char *from)
1998
1976
{
1999
1977
  uint end_backslashes= 0; 
2000
1978
 
2001
 
  dynstr_append_checked(in, "'");
 
1979
  in.append("'");
2002
1980
 
2003
1981
  while (*from)
2004
1982
  {
2005
 
    dynstr_append_mem_checked(in, from, 1);
 
1983
    in.append(from, 1);
2006
1984
 
2007
1985
    if (*from == '\\')
2008
1986
      end_backslashes^=1;    /* find odd number of backslashes */
2011
1989
      if (*from == '\'' && !end_backslashes)
2012
1990
      {
2013
1991
        /* We want a duplicate of "'" for DRIZZLE */
2014
 
        dynstr_append_checked(in, "\'");
 
1992
        in.append("\'");
2015
1993
      }
2016
1994
      end_backslashes=0;
2017
1995
    }
2019
1997
  }
2020
1998
  /* Add missing backslashes if user has specified odd number of backs.*/
2021
1999
  if (end_backslashes)
2022
 
    dynstr_append_checked(in, "\\");
2023
 
  
2024
 
  dynstr_append_checked(in, "'");
 
2000
    in.append("\\");
 
2001
 
 
2002
  in.append("'");
2025
2003
}
2026
2004
 
2027
2005
 
2046
2024
{
2047
2025
  char ignore_flag;
2048
2026
  char buf[200], table_buff[NAME_LEN+3];
2049
 
  DYNAMIC_STRING query_string;
 
2027
  string query_string;
2050
2028
  char table_type[NAME_LEN];
2051
2029
  char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table;
2052
2030
  int error= 0;
2112
2090
 
2113
2091
  verbose_msg("-- Sending SELECT query...\n");
2114
2092
 
2115
 
  init_dynamic_string_checked(&query_string, "", 1024, 1024);
 
2093
  query_string.clear();
 
2094
  query_string.reserve(1024);
2116
2095
 
2117
2096
  if (path)
2118
2097
  {
2134
2113
 
2135
2114
    /* now build the query string */
2136
2115
 
2137
 
    dynstr_append_checked(&query_string, "SELECT * INTO OUTFILE '");
2138
 
    dynstr_append_checked(&query_string, filename);
2139
 
    dynstr_append_checked(&query_string, "'");
 
2116
    query_string.append( "SELECT * INTO OUTFILE '");
 
2117
    query_string.append( filename);
 
2118
    query_string.append( "'");
2140
2119
 
2141
2120
    if (fields_terminated || enclosed || opt_enclosed || escaped)
2142
 
      dynstr_append_checked(&query_string, " FIELDS");
 
2121
      query_string.append( " FIELDS");
2143
2122
    
2144
 
    add_load_option(&query_string, " TERMINATED BY ", fields_terminated);
2145
 
    add_load_option(&query_string, " ENCLOSED BY ", enclosed);
2146
 
    add_load_option(&query_string, " OPTIONALLY ENCLOSED BY ", opt_enclosed);
2147
 
    add_load_option(&query_string, " ESCAPED BY ", escaped);
2148
 
    add_load_option(&query_string, " LINES TERMINATED BY ", lines_terminated);
 
2123
    add_load_option(query_string, " TERMINATED BY ", fields_terminated);
 
2124
    add_load_option(query_string, " ENCLOSED BY ", enclosed);
 
2125
    add_load_option(query_string, " OPTIONALLY ENCLOSED BY ", opt_enclosed);
 
2126
    add_load_option(query_string, " ESCAPED BY ", escaped);
 
2127
    add_load_option(query_string, " LINES TERMINATED BY ", lines_terminated);
2149
2128
 
2150
 
    dynstr_append_checked(&query_string, " FROM ");
2151
 
    dynstr_append_checked(&query_string, result_table);
 
2129
    query_string.append( " FROM ");
 
2130
    query_string.append( result_table);
2152
2131
 
2153
2132
    if (where)
2154
2133
    {
2155
 
      dynstr_append_checked(&query_string, " WHERE ");
2156
 
      dynstr_append_checked(&query_string, where);
 
2134
      query_string.append( " WHERE ");
 
2135
      query_string.append( where);
2157
2136
    }
2158
2137
 
2159
2138
    if (order_by)
2160
2139
    {
2161
 
      dynstr_append_checked(&query_string, " ORDER BY ");
2162
 
      dynstr_append_checked(&query_string, order_by);
 
2140
      query_string.append( " ORDER BY ");
 
2141
      query_string.append( order_by);
2163
2142
    }
2164
2143
 
2165
 
    if (drizzle_real_query(drizzle, query_string.str, query_string.length))
 
2144
    if (drizzle_real_query(drizzle, query_string.c_str(), query_string.length()))
2166
2145
    {
2167
2146
      DB_error(drizzle, "when executing 'SELECT INTO OUTFILE'");
2168
 
      dynstr_free(&query_string);
2169
2147
      return;
2170
2148
    }
2171
2149
  }
2178
2156
      check_io(md_result_file);
2179
2157
    }
2180
2158
    
2181
 
    dynstr_append_checked(&query_string, "SELECT * FROM ");
2182
 
    dynstr_append_checked(&query_string, result_table);
 
2159
    query_string.append( "SELECT * FROM ");
 
2160
    query_string.append( result_table);
2183
2161
 
2184
2162
    if (where)
2185
2163
    {
2189
2167
        check_io(md_result_file);
2190
2168
      }
2191
2169
      
2192
 
      dynstr_append_checked(&query_string, " WHERE ");
2193
 
      dynstr_append_checked(&query_string, where);
 
2170
      query_string.append( " WHERE ");
 
2171
      query_string.append( where);
2194
2172
    }
2195
2173
    if (order_by)
2196
2174
    {
2199
2177
        fprintf(md_result_file, "-- ORDER BY:  %s\n", order_by);
2200
2178
        check_io(md_result_file);
2201
2179
      }
2202
 
      dynstr_append_checked(&query_string, " ORDER BY ");
2203
 
      dynstr_append_checked(&query_string, order_by);
 
2180
      query_string.append( " ORDER BY ");
 
2181
      query_string.append( order_by);
2204
2182
    }
2205
2183
 
2206
2184
    if (!opt_xml && !opt_compact)
2208
2186
      fputs("\n", md_result_file);
2209
2187
      check_io(md_result_file);
2210
2188
    }
2211
 
    if (drizzle_query_with_error_report(drizzle, 0, query_string.str))
 
2189
    if (drizzle_query_with_error_report(drizzle, 0, query_string.c_str()))
2212
2190
    {
2213
2191
      DB_error(drizzle, "when retrieving data from server");
2214
2192
      goto err;
2248
2226
    total_length= opt_net_buffer_length;                /* Force row break */
2249
2227
    row_break=0;
2250
2228
    rownr=0;
2251
 
    init_length=(uint) insert_pat.length+4;
 
2229
    init_length=(uint) insert_pat.length()+4;
2252
2230
    if (opt_xml)
2253
2231
      print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
2254
2232
              NullS);
2265
2243
      rownr++;
2266
2244
      if (!extended_insert && !opt_xml)
2267
2245
      {
2268
 
        fputs(insert_pat.str,md_result_file);
 
2246
        fputs(insert_pat.c_str(),md_result_file);
2269
2247
        check_io(md_result_file);
2270
2248
      }
2271
2249
      drizzle_field_seek(res,0);
2297
2275
        if (extended_insert && !opt_xml)
2298
2276
        {
2299
2277
          if (i == 0)
2300
 
            dynstr_set_checked(&extended_row,"(");
 
2278
            extended_row= "(";
2301
2279
          else
2302
 
            dynstr_append_checked(&extended_row,",");
 
2280
            extended_row.append(",");
2303
2281
 
2304
2282
          if (row[i])
2305
2283
          {
2315
2293
                  plus 2 bytes for leading and trailing '\'' characters.
2316
2294
                  Also we need to reserve 1 byte for terminating '\0'.
2317
2295
                */
2318
 
                dynstr_realloc_checked(&extended_row,length * 2 + 2 + 1);
 
2296
                char * tmp_str= (char *)malloc(length * 2 + 2 + 1);
 
2297
                memset(tmp_str, '\0', length * 2 + 2 + 1);
2319
2298
                if (opt_hex_blob && is_blob)
2320
2299
                {
2321
 
                  dynstr_append_checked(&extended_row, "0x");
2322
 
                  extended_row.length+= drizzle_hex_string(extended_row.str +
2323
 
                                                         extended_row.length,
2324
 
                                                         row[i], length);
2325
 
                  assert(extended_row.length+1 <= extended_row.max_length);
2326
 
                  /* drizzle_hex_string() already terminated string by '\0' */
2327
 
                  assert(extended_row.str[extended_row.length] == '\0');
 
2300
                  extended_row.append("0x");
 
2301
                  drizzle_hex_string(tmp_str, row[i], length);
 
2302
                  extended_row.append(tmp_str);
2328
2303
                }
2329
2304
                else
2330
2305
                {
2331
 
                  dynstr_append_checked(&extended_row,"'");
2332
 
                  extended_row.length +=
 
2306
                  extended_row.append("'");
2333
2307
                  drizzle_real_escape_string(&drizzle_connection,
2334
 
                                           &extended_row.str[extended_row.length],
2335
 
                                           row[i],length);
2336
 
                  extended_row.str[extended_row.length]='\0';
2337
 
                  dynstr_append_checked(&extended_row,"'");
 
2308
                                             tmp_str,
 
2309
                                             row[i],length);
 
2310
                  extended_row.append(tmp_str);
 
2311
                  extended_row.append("'");
2338
2312
                }
 
2313
                free(tmp_str);
2339
2314
              }
2340
2315
              else
2341
2316
              {
2343
2318
                char *ptr= row[i];
2344
2319
                if (my_isalpha(charset_info, *ptr) || (*ptr == '-' &&
2345
2320
                    my_isalpha(charset_info, ptr[1])))
2346
 
                  dynstr_append_checked(&extended_row, "NULL");
 
2321
                  extended_row.append( "NULL");
2347
2322
                else
2348
2323
                {
2349
 
                  dynstr_append_checked(&extended_row, ptr);
 
2324
                  extended_row.append( ptr);
2350
2325
                }
2351
2326
              }
2352
2327
            }
2353
2328
            else
2354
 
              dynstr_append_checked(&extended_row,"''");
 
2329
              extended_row.append("''");
2355
2330
          }
2356
2331
          else
2357
 
            dynstr_append_checked(&extended_row,"NULL");
 
2332
            extended_row.append("NULL");
2358
2333
        }
2359
2334
        else
2360
2335
        {
2433
2408
      if (extended_insert)
2434
2409
      {
2435
2410
        ulong row_length;
2436
 
        dynstr_append_checked(&extended_row,")");
2437
 
        row_length= 2 + extended_row.length;
 
2411
        extended_row.append(")");
 
2412
        row_length= 2 + extended_row.length();
2438
2413
        if (total_length + row_length < opt_net_buffer_length)
2439
2414
        {
2440
2415
          total_length+= row_length;
2441
2416
          fputc(',',md_result_file);            /* Always row break */
2442
 
          fputs(extended_row.str,md_result_file);
 
2417
          fputs(extended_row.c_str(),md_result_file);
2443
2418
        }
2444
2419
        else
2445
2420
        {
2447
2422
            fputs(";\n", md_result_file);
2448
2423
          row_break=1;                          /* This is first row */
2449
2424
 
2450
 
          fputs(insert_pat.str,md_result_file);
2451
 
          fputs(extended_row.str,md_result_file);
 
2425
          fputs(insert_pat.c_str(),md_result_file);
 
2426
          fputs(extended_row.c_str(),md_result_file);
2452
2427
          total_length= row_length+init_length;
2453
2428
        }
2454
2429
        check_io(md_result_file);
2500
2475
    }
2501
2476
    drizzle_free_result(res);
2502
2477
  }
2503
 
  dynstr_free(&query_string);
2504
2478
  return;
2505
2479
 
2506
2480
err:
2507
 
  dynstr_free(&query_string);
2508
2481
  maybe_exit(error);
2509
2482
  return;
2510
2483
} /* dump_table */
2656
2629
    }
2657
2630
  }
2658
2631
  if (extended_insert)
2659
 
    init_dynamic_string_checked(&extended_row, "", 1024, 1024);
 
2632
    extended_row.clear();
2660
2633
  return 0;
2661
2634
} /* init_dumping */
2662
2635
 
2688
2661
    print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
2689
2662
  if (lock_tables)
2690
2663
  {
2691
 
    DYNAMIC_STRING query;
2692
 
    init_dynamic_string_checked(&query, "LOCK TABLES ", 256, 1024);
 
2664
    string query;
 
2665
    query= "LOCK TABLES ";
2693
2666
    for (numrows= 0 ; (table= getTableName(1)) ; )
2694
2667
    {
2695
2668
      char *end= stpcpy(afterdot, table);
2696
2669
      if (include_table((uchar*) hash_key,end - hash_key))
2697
2670
      {
2698
2671
        numrows++;
2699
 
        dynstr_append_checked(&query, quote_name(table, table_buff, 1));
2700
 
        dynstr_append_checked(&query, " READ /*!32311 LOCAL */,");
 
2672
        query.append( quote_name(table, table_buff, 1));
 
2673
        query.append( " READ /*!32311 LOCAL */,");
2701
2674
      }
2702
2675
    }
2703
 
    if (numrows && drizzle_real_query(drizzle, query.str, query.length-1))
 
2676
    if (numrows && drizzle_real_query(drizzle, query.c_str(), query.length()-1))
2704
2677
      DB_error(drizzle, "when using LOCK TABLES");
2705
2678
            /* We shall continue here, if --force was given */
2706
 
    dynstr_free(&query);
 
2679
    query.clear();
2707
2680
  }
2708
2681
  if (flush_logs)
2709
2682
  {
2788
2761
static int dump_selected_tables(char *db, char **table_names, int tables)
2789
2762
{
2790
2763
  char table_buff[NAME_LEN*2+3];
2791
 
  DYNAMIC_STRING lock_tables_query;
 
2764
  string lock_tables_query;
2792
2765
  MEM_ROOT root;
2793
2766
  char **dump_tables, **pos, **end;
2794
2767
 
2800
2773
  if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
2801
2774
     die(EX_EOM, "alloc_root failure.");
2802
2775
 
2803
 
  init_dynamic_string_checked(&lock_tables_query, "LOCK TABLES ", 256, 1024);
 
2776
  lock_tables_query= "LOCK TABLES ";
2804
2777
  for (; tables > 0 ; tables-- , table_names++)
2805
2778
  {
2806
2779
    /* the table name passed on commandline may be wrong case */
2809
2782
      /* Add found table name to lock_tables_query */
2810
2783
      if (lock_tables)
2811
2784
      {
2812
 
        dynstr_append_checked(&lock_tables_query, quote_name(*pos, table_buff, 1));
2813
 
        dynstr_append_checked(&lock_tables_query, " READ /*!32311 LOCAL */,");
 
2785
        lock_tables_query.append( quote_name(*pos, table_buff, 1));
 
2786
        lock_tables_query.append( " READ /*!32311 LOCAL */,");
2814
2787
      }
2815
2788
      pos++;
2816
2789
    }
2818
2791
    {
2819
2792
      if (!ignore_errors)
2820
2793
      {
2821
 
        dynstr_free(&lock_tables_query);
2822
2794
        free_root(&root, MYF(0));
2823
2795
      }
2824
2796
      maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names);
2829
2801
 
2830
2802
  if (lock_tables)
2831
2803
  {
2832
 
    if (drizzle_real_query(drizzle, lock_tables_query.str,
2833
 
                         lock_tables_query.length-1))
 
2804
    if (drizzle_real_query(drizzle, lock_tables_query.c_str(),
 
2805
                         lock_tables_query.length()-1))
2834
2806
    {
2835
2807
      if (!ignore_errors)
2836
2808
      {
2837
 
        dynstr_free(&lock_tables_query);
2838
2809
        free_root(&root, MYF(0));
2839
2810
      }
2840
2811
      DB_error(drizzle, "when doing LOCK TABLES");
2841
2812
       /* We shall countinue here, if --force was given */
2842
2813
    }
2843
2814
  }
2844
 
  dynstr_free(&lock_tables_query);
2845
2815
  if (flush_logs)
2846
2816
  {
2847
2817
    if (drizzle_refresh(drizzle, REFRESH_LOG))
3085
3055
 
3086
3056
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
3087
3057
{
3088
 
  DYNAMIC_STRING str;
3089
3058
  int err;
3090
 
  init_dynamic_string_checked(&str, "PURGE BINARY LOGS TO '", 1024, 1024);
3091
 
  dynstr_append_checked(&str, log_name);
3092
 
  dynstr_append_checked(&str, "'");
3093
 
  err = drizzle_query_with_error_report(drizzle_con, 0, str.str);
3094
 
  dynstr_free(&str);
 
3059
  string str= "PURGE BINARY LOGS TO '";
 
3060
  str.append(log_name);
 
3061
  str.append("'");
 
3062
  err = drizzle_query_with_error_report(drizzle_con, 0, str.c_str());
3095
3063
  return err;
3096
3064
}
3097
3065
 
3371
3339
  return result;
3372
3340
}
3373
3341
 
3374
 
/*
3375
 
  The following functions are wrappers for the dynamic string functions
3376
 
  and if they fail, the wrappers will terminate the current process.
3377
 
*/
3378
 
 
3379
 
#define DYNAMIC_STR_ERROR_MSG "Couldn't perform DYNAMIC_STRING operation"
3380
 
 
3381
 
static void init_dynamic_string_checked(DYNAMIC_STRING *str, const char *init_str,
3382
 
                            uint init_alloc, uint alloc_increment)
3383
 
{
3384
 
  if (init_dynamic_string(str, init_str, init_alloc, alloc_increment))
3385
 
    die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3386
 
}
3387
 
 
3388
 
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src)
3389
 
{
3390
 
  if (dynstr_append(dest, src))
3391
 
    die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3392
 
}
3393
 
 
3394
 
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str)
3395
 
{
3396
 
  if (dynstr_set(str, init_str))
3397
 
    die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3398
 
}
3399
 
 
3400
 
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
3401
 
                          uint length)
3402
 
{
3403
 
  if (dynstr_append_mem(str, append, length))
3404
 
    die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3405
 
}
3406
 
 
3407
 
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size)
3408
 
{
3409
 
  if (dynstr_realloc(str, additional_size))
3410
 
    die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3411
 
}
3412
 
 
3413
3342
 
3414
3343
int main(int argc, char **argv)
3415
3344
{