~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000 MySQL AB
 
1
/* Copyright (C) 2008 Drizzle Open Source Development Project
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
/* mysqldump.c  - Dump a tables contents and format to an ASCII file
 
16
/* drizzledump.cc  - Dump a tables contents and format to an ASCII file
17
17
**
18
18
** The author's original notes follow :-
19
19
**
22
22
** WARRANTY: None, expressed, impressed, implied
23
23
**          or other
24
24
** STATUS: Public domain
25
 
** Adapted and optimized for MySQL by
26
 
** Michael Widenius, Sinisa Milivojevic, Jani Tolonen
27
 
** -w --where added 9/10/98 by Jim Faucette
28
 
** slave code by David Saez Padros <david@ols.es>
29
 
** master/autocommit code by Brian Aker <brian@tangent.org>
30
 
** SSL by
31
 
** Andrei Errapart <andreie@no.spam.ee>
32
 
** Tõnu Samuel  <tonu@please.do.not.remove.this.spam.ee>
33
 
** XML by Gary Huntress <ghuntress@mediaone.net> 10/10/01, cleaned up
34
 
** and adapted to mysqldump 05/11/01 by Jani Tolonen
35
 
** Added --single-transaction option 06/06/2002 by Peter Zaitsev
36
 
** 10 Jun 2003: SET NAMES and --no-set-names by Alexander Barkov
37
25
*/
38
26
 
39
27
#define DUMP_VERSION "10.13"
40
28
 
41
 
#include <my_global.h>
42
 
#include <my_sys.h>
43
 
#include <m_string.h>
44
 
#include <m_ctype.h>
45
 
#include <hash.h>
 
29
#include "config.h"
 
30
#include <string>
 
31
#include "client_priv.h"
 
32
 
 
33
#include <mysys/my_sys.h>
 
34
#include <mystrings/m_string.h>
 
35
#include <mystrings/m_ctype.h>
 
36
#include <mysys/hash.h>
46
37
#include <stdarg.h>
47
38
 
48
 
#include "client_priv.h"
49
 
#include "drizzle_version.h"
50
 
#include "mysqld_error.h"
 
39
#include <drizzled/error.h>
51
40
 
 
41
using namespace std;
52
42
/* Exit codes */
53
43
 
54
44
#define EX_USAGE 1
55
 
#define EX_MYSQLERR 2
 
45
#define EX_DRIZZLEERR 2
56
46
#define EX_CONSCHECK 3
57
47
#define EX_EOM 4
58
48
#define EX_EOF 5 /* ferror for output file was got */
74
64
#define IGNORE_DATA 0x01 /* don't dump data for this table */
75
65
#define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */
76
66
 
77
 
static void add_load_option(DYNAMIC_STRING *str, const char *option,
78
 
                             const char *option_value);
79
 
static ulong find_set(TYPELIB *lib, const char *x, uint length,
 
67
static void add_load_option(string &str, const char *option,
 
68
                            const char *option_value);
 
69
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
80
70
                      char **err_pos, uint *err_len);
81
71
 
82
 
static void field_escape(DYNAMIC_STRING* in, const char *from);
 
72
static void field_escape(string &in, const char *from);
83
73
static bool  verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
84
74
                quick= 1, extended_insert= 1,
85
75
                lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
98
88
                opt_include_master_host_port= 0,
99
89
                opt_events= 0,
100
90
                opt_alltspcs=0, opt_notspcs= 0;
101
 
static bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
102
 
static ulong opt_max_allowed_packet, opt_net_buffer_length;
103
 
static MYSQL mysql_connection,*mysql=0;
104
 
static DYNAMIC_STRING insert_pat;
 
91
static bool debug_info_flag= 0, debug_check_flag= 0;
 
92
static uint32_t opt_max_allowed_packet, opt_net_buffer_length;
 
93
static DRIZZLE drizzle_connection,*drizzle=0;
 
94
static string insert_pat;
105
95
static char  *opt_password=0,*current_user=0,
106
96
             *current_host=0,*path=0,*fields_terminated=0,
107
97
             *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
113
103
static char compatible_mode_normal_str[255];
114
104
/* Server supports character_set_results session variable? */
115
105
static bool server_supports_switching_charsets= true;
116
 
static ulong opt_compatible_mode= 0;
117
 
#define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1
118
 
#define MYSQL_OPT_MASTER_DATA_COMMENTED_SQL 2
119
 
#define MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
120
 
#define MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL 2
121
 
static uint opt_mysql_port= 0, opt_master_data;
 
106
static uint32_t opt_compatible_mode= 0;
 
107
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
 
108
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
 
109
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
 
110
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
 
111
static uint opt_drizzle_port= 0, opt_master_data;
122
112
static uint opt_slave_data;
123
113
static uint my_end_arg;
124
114
static int   first_error=0;
125
 
static DYNAMIC_STRING extended_row;
 
115
static string extended_row;
126
116
FILE *md_result_file= 0;
127
117
FILE *stderror_file=0;
128
118
 
129
 
static uint opt_protocol= MYSQL_PROTOCOL_TCP;
130
 
 
131
 
/*
132
 
Dynamic_string wrapper functions. In this file use these
133
 
wrappers, they will terminate the process if there is
134
 
an allocation failure.
135
 
*/
136
 
static void init_dynamic_string_checked(DYNAMIC_STRING *str, const char *init_str,
137
 
                            uint init_alloc, uint alloc_increment);
138
 
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src);
139
 
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str);
140
 
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
141
 
                          uint length);
142
 
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size);
143
119
/*
144
120
  Constant for detection of default value of default_charset.
145
 
  If default_charset is equal to mysql_universal_client_charset, then
 
121
  If default_charset is equal to drizzle_universal_client_charset, then
146
122
  it is the default value which assigned at the very beginning of main().
147
123
*/
148
 
static const char *mysql_universal_client_charset=
149
 
  MYSQL_UNIVERSAL_CLIENT_CHARSET;
 
124
static const char *drizzle_universal_client_charset=
 
125
  DRIZZLE_UNIVERSAL_CLIENT_CHARSET;
150
126
static char *default_charset;
151
 
static CHARSET_INFO *charset_info= &my_charset_latin1;
152
 
const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace";
 
127
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
 
128
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
153
129
/* have we seen any VIEWs during table scanning? */
154
130
bool seen_views= 0;
155
131
const char *compatible_mode_names[]=
157
133
  "MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
158
134
  "MAXDB", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS",
159
135
  "ANSI",
160
 
  NullS
 
136
  NULL
161
137
};
162
138
#define MASK_ANSI_QUOTES \
163
139
(\
202
178
  {"allow-keywords", OPT_KEYWORDS,
203
179
   "Allow creation of column names that are keywords.", (char**) &opt_keywords,
204
180
   (char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
205
 
  {"apply-slave-statements", OPT_MYSQLDUMP_SLAVE_APPLY,
 
181
  {"apply-slave-statements", OPT_DRIZZLEDUMP_SLAVE_APPLY,
206
182
   "Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
207
183
   (char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
208
184
   0, 0, 0, 0, 0, 0},
213
189
   (char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
214
190
   1, 0, 0, 0, 0, 0},
215
191
  {"compatible", OPT_COMPATIBLE,
216
 
   "Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires MySQL server version 4.1.0 or higher. This option is ignored with earlier server versions.",
 
192
   "Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires DRIZZLE server version 4.1.0 or higher. This option is ignored with earlier server versions.",
217
193
   (char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
218
194
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
219
195
  {"compact", OPT_COMPACT,
227
203
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
228
204
   0, 0, 0},
229
205
  {"create-options", OPT_CREATE_OPTIONS,
230
 
   "Include all MySQL specific create options.",
 
206
   "Include all DRIZZLE specific create options.",
231
207
   (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
232
208
   0, 0, 0, 0, 0},
233
209
  {"databases", 'B',
253
229
  {"disable-keys", 'K',
254
230
   "'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output.", (char**) &opt_disable_keys,
255
231
   (char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
256
 
  {"dump-slave", OPT_MYSQLDUMP_SLAVE_DATA,
 
232
  {"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
257
233
   "This causes the binary log position and filename of the master to be "
258
234
   "appended to the dumped data output. Setting the value to 1, will print"
259
235
   "it as a CHANGE MASTER command in the dumped data output; if equal"
265
241
   "any action on logs will happen at the exact moment of the dump."
266
242
   "Option automatically turns --lock-tables off.",
267
243
   (char**) &opt_slave_data, (char**) &opt_slave_data, 0,
268
 
   GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
 
244
   GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
269
245
  {"events", 'E', "Dump events.",
270
246
     (char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
271
247
     NO_ARG, 0, 0, 0, 0, 0, 0},
299
275
   (char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
300
276
   0, 0},
301
277
  {"flush-privileges", OPT_ESC, "Emit a FLUSH PRIVILEGES statement "
302
 
   "after dumping the mysql database.  This option should be used any "
303
 
   "time the dump contains the mysql database and any other database "
304
 
   "that depends on the data in the mysql database for proper restore. ",
 
278
   "after dumping the DRIZZLE database.  This option should be used any "
 
279
   "time the dump contains the DRIZZLE database and any other database "
 
280
   "that depends on the data in the DRIZZLE database for proper restore. ",
305
281
   (char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
306
282
   0, 0},
307
283
  {"force", 'f', "Continue even if we get an sql-error.",
319
295
   "use the directive multiple times, once for each table.  Each table must "
320
296
   "be specified with both database and table names, e.g. --ignore-table=database.table",
321
297
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
322
 
  {"include-master-host-port", OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT,
 
298
  {"include-master-host-port", OPT_DRIZZLEDUMP_INCLUDE_MASTER_HOST_PORT,
323
299
   "Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.",
324
300
   (char**) &opt_include_master_host_port, 
325
301
   (char**) &opt_include_master_host_port, 
352
328
   "any action on logs will happen at the exact moment of the dump."
353
329
   "Option automatically turns --lock-tables off.",
354
330
   (char**) &opt_master_data, (char**) &opt_master_data, 0,
355
 
   GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
 
331
   GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
356
332
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
357
333
    (char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
358
334
    GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
386
362
  {"password", 'p',
387
363
   "Password to use when connecting to server. If password is not given it's solicited on the tty.",
388
364
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
389
 
  {"port", 'P', "Port number to use for connection.", (char**) &opt_mysql_port,
390
 
   (char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
 
365
  {"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
 
366
   (char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
391
367
   0},
392
368
  {"quick", 'q', "Don't buffer query, dump directly to stdout.",
393
369
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
394
370
  {"quote-names",'Q', "Quote table and column names with backticks (`).",
395
371
   (char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
396
372
   0, 0},
397
 
  {"replace", OPT_MYSQL_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
 
373
  {"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
398
374
   (char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
399
375
   0, 0},
400
376
  {"result-file", 'r',
457
433
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
458
434
};
459
435
 
460
 
static const char *load_default_groups[]= { "mysqldump","client",0 };
 
436
static const char *load_default_groups[]= { "drizzledump","client",0 };
461
437
 
462
438
static void maybe_exit(int error);
463
439
static void die(int error, const char* reason, ...);
464
440
static void maybe_die(int error, const char* reason, ...);
465
441
static void write_header(FILE *sql_file, char *db_name);
466
 
static void print_value(FILE *file, MYSQL_RES  *result, MYSQL_ROW row,
 
442
static void print_value(FILE *file, DRIZZLE_RES  *result, DRIZZLE_ROW row,
467
443
                        const char *prefix,const char *name,
468
444
                        int string_value);
469
445
static int dump_selected_tables(char *db, char **table_names, int tables);
476
452
char check_if_ignore_table(const char *table_name, char *table_type);
477
453
static char *primary_key_fields(const char *table_name);
478
454
 
479
 
#include <help_start.h>
480
 
 
481
455
/*
482
456
  Print the supplied message if in verbose mode
483
457
 
486
460
    fmt   format specifier
487
461
    ...   variable number of parameters
488
462
*/
489
 
 
490
463
static void verbose_msg(const char *fmt, ...)
491
464
{
492
465
  va_list args;
519
492
static void print_version(void)
520
493
{
521
494
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
522
 
         MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
 
495
         drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
523
496
} /* print_version */
524
497
 
525
498
 
537
510
  print_version();
538
511
  puts("By Igor Romanenko, Monty, Jani & Sinisa");
539
512
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
540
 
  puts("Dumping definition and data mysql database or table");
 
513
  puts("Dumping definition and data DRIZZLE database or table");
541
514
  short_usage_sub();
542
515
  print_defaults("my",load_default_groups);
543
516
  my_print_help(my_long_options);
551
524
  printf("For more options, use %s --help\n", my_progname);
552
525
}
553
526
 
554
 
#include <help_end.h>
555
 
 
556
 
 
557
527
static void write_header(FILE *sql_file, char *db_name)
558
528
{
559
529
  if (opt_xml)
563
533
      Schema reference.  Allows use of xsi:nil for NULL values and 
564
534
      xsi:type to define an element's data type.
565
535
    */
566
 
    fputs("<mysqldump ", sql_file);
 
536
    fputs("<drizzledump ", sql_file);
567
537
    fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
568
538
          sql_file);
569
539
    fputs(">\n", sql_file);
574
544
    if (opt_comments)
575
545
    {
576
546
      fprintf(sql_file,
577
 
              "-- MySQL dump %s  Distrib %s, for %s (%s)\n--\n",
578
 
              DUMP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
 
547
              "-- DRIZZLE dump %s  Distrib %s, for %s (%s)\n--\n",
 
548
              DUMP_VERSION, drizzle_get_client_info(),
 
549
              SYSTEM_TYPE, MACHINE_TYPE);
579
550
      fprintf(sql_file, "-- Host: %s    Database: %s\n",
580
551
              current_host ? current_host : "localhost", db_name ? db_name :
581
552
              "");
582
553
      fputs("-- ------------------------------------------------------\n",
583
554
            sql_file);
584
555
      fprintf(sql_file, "-- Server version\t%s\n",
585
 
              mysql_get_server_info(&mysql_connection));
 
556
              drizzle_get_server_info(&drizzle_connection));
586
557
    }
587
558
    if (opt_set_charset)
588
559
      fprintf(sql_file,
589
 
"\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;"
590
 
"\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;"
591
560
"\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"
592
561
"\n/*!40101 SET NAMES %s */;\n",default_charset);
593
562
 
613
582
{
614
583
  if (opt_xml)
615
584
  {
616
 
    fputs("</mysqldump>\n", sql_file);
 
585
    fputs("</drizzledump>\n", sql_file);
617
586
    check_io(sql_file);
618
587
  }
619
588
  else if (!opt_compact)
629
598
    }
630
599
    if (opt_set_charset)
631
600
      fprintf(sql_file,
632
 
"/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n"
633
 
"/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n"
634
601
"/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
635
602
    fprintf(sql_file,
636
603
            "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
654
621
 
655
622
static void free_table_ent(char *key)
656
623
{
657
 
  my_free(key, MYF(0));
 
624
  free(key);
658
625
}
659
626
 
660
627
 
661
 
static uchar* get_table_key(const char *entry, size_t *length,
 
628
static unsigned char* get_table_key(const char *entry, size_t *length,
662
629
                            bool not_used __attribute__((unused)))
663
630
{
664
631
  *length= strlen(entry);
665
 
  return (uchar*) entry;
 
632
  return (unsigned char*) entry;
666
633
}
667
634
 
668
635
 
675
642
    if (argument)
676
643
    {
677
644
      char *start=argument;
678
 
      my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
 
645
      free(opt_password);
679
646
      opt_password=my_strdup(argument,MYF(MY_FAE));
680
647
      while (*argument) *argument++= 'x';               /* Destroy argument */
681
648
      if (*start)
686
653
      tty_password=1;
687
654
    break;
688
655
  case 'r':
689
 
    if (!(md_result_file= my_fopen(argument, O_WRONLY | FILE_BINARY,
 
656
    if (!(md_result_file= my_fopen(argument, O_WRONLY,
690
657
                                    MYF(MY_WME))))
691
658
      exit(1);
692
659
    break;
720
687
    exit(0);
721
688
  case (int) OPT_MASTER_DATA:
722
689
    if (!argument) /* work like in old versions */
723
 
      opt_master_data= MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL;
 
690
      opt_master_data= DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL;
724
691
    break;
725
 
  case (int) OPT_MYSQLDUMP_SLAVE_DATA:
 
692
  case (int) OPT_DRIZZLEDUMP_SLAVE_DATA:
726
693
    if (!argument) /* work like in old versions */
727
 
      opt_slave_data= MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL;
 
694
      opt_slave_data= DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL;
728
695
    break;
729
696
  case (int) OPT_OPTIMIZE:
730
697
    extended_insert= opt_drop= opt_lock= quick= create_options=
750
717
      fprintf(stderr, "Illegal use of option --ignore-table=<database>.<table>\n");
751
718
      exit(1);
752
719
    }
753
 
    if (my_hash_insert(&ignore_table, (uchar*)my_strdup(argument, MYF(0))))
 
720
    if (my_hash_insert(&ignore_table, (unsigned char*)my_strdup(argument, MYF(0))))
754
721
      exit(EX_EOM);
755
722
    break;
756
723
  }
758
725
    {
759
726
      char buff[255];
760
727
      char *end= compatible_mode_normal_str;
761
 
      int i;
762
 
      ulong mode;
763
 
      uint err_len;
 
728
      uint32_t i;
 
729
      uint32_t mode;
 
730
      uint32_t error_len;
764
731
 
765
732
      opt_quoted= 1;
766
733
      opt_set_charset= 0;
767
734
      opt_compatible_mode_str= argument;
768
735
      opt_compatible_mode= find_set(&compatible_mode_typelib,
769
736
                                    argument, strlen(argument),
770
 
                                    &err_ptr, &err_len);
771
 
      if (err_len)
 
737
                                    &err_ptr, &error_len);
 
738
      if (error_len)
772
739
      {
773
 
        strmake(buff, err_ptr, min(sizeof(buff), err_len));
 
740
        strmake(buff, err_ptr, min((uint32_t)sizeof(buff), error_len));
774
741
        fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
775
742
        exit(1);
776
743
      }
779
746
      {
780
747
        if (mode & 1)
781
748
        {
782
 
          end= strmov(end, compatible_mode_names[i]);
783
 
          end= strmov(end, ",");
 
749
          end= my_stpcpy(end, compatible_mode_names[i]);
 
750
          end= my_stpcpy(end, ",");
784
751
        }
785
752
      }
786
753
      if (end!=compatible_mode_normal_str)
789
756
        Set charset to the default compiled value if it hasn't
790
757
        been reset yet by --default-character-set=xxx.
791
758
      */
792
 
      if (default_charset == mysql_universal_client_charset)
793
 
        default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
 
759
      if (default_charset == drizzle_universal_client_charset)
 
760
        default_charset= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
794
761
      break;
795
762
    }
796
763
  }
800
767
static int get_options(int *argc, char ***argv)
801
768
{
802
769
  int ho_error;
803
 
  MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
 
770
  const DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
804
771
 
805
 
  opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
806
 
  opt_net_buffer_length= *mysql_params->p_net_buffer_length;
 
772
  opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
 
773
  opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
807
774
 
808
775
  md_result_file= stdout;
809
776
  load_defaults("my",load_default_groups,argc,argv);
815
782
    return(EX_EOM);
816
783
  /* Don't copy internal log tables */
817
784
  if (my_hash_insert(&ignore_table,
818
 
                     (uchar*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
819
 
      my_hash_insert(&ignore_table,
820
 
                     (uchar*) my_strdup("mysql.schema", MYF(MY_WME))) ||
821
 
      my_hash_insert(&ignore_table,
822
 
                     (uchar*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
823
 
      my_hash_insert(&ignore_table,
824
 
                     (uchar*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
825
 
      my_hash_insert(&ignore_table,
826
 
                     (uchar*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
827
 
      my_hash_insert(&ignore_table,
828
 
                     (uchar*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
 
785
                     (unsigned char*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
 
786
      my_hash_insert(&ignore_table,
 
787
                     (unsigned char*) my_strdup("mysql.schema", MYF(MY_WME))) ||
 
788
      my_hash_insert(&ignore_table,
 
789
                     (unsigned char*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
 
790
      my_hash_insert(&ignore_table,
 
791
                     (unsigned char*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
 
792
      my_hash_insert(&ignore_table,
 
793
                     (unsigned char*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
 
794
      my_hash_insert(&ignore_table,
 
795
                     (unsigned char*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
829
796
    return(EX_EOM);
830
797
 
831
798
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
832
799
    return(ho_error);
833
800
 
834
 
  *mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
835
 
  *mysql_params->p_net_buffer_length= opt_net_buffer_length;
 
801
  *drizzle_params->p_max_allowed_packet= opt_max_allowed_packet;
 
802
  *drizzle_params->p_net_buffer_length= opt_net_buffer_length;
836
803
  if (debug_info_flag)
837
804
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
838
805
  if (debug_check_flag)
858
825
 
859
826
  /* Ensure consistency of the set of binlog & locking options */
860
827
  if (opt_delete_master_logs && !opt_master_data)
861
 
    opt_master_data= MYSQL_OPT_MASTER_DATA_COMMENTED_SQL;
 
828
    opt_master_data= DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL;
862
829
  if (opt_single_transaction && opt_lock_all_tables)
863
830
  {
864
831
    fprintf(stderr, "%s: You can't use --single-transaction and "
894
861
    return EX_USAGE;
895
862
  }
896
863
  if (tty_password)
897
 
    opt_password=get_tty_password(NullS);
 
864
    opt_password=get_tty_password(NULL);
898
865
  return(0);
899
866
} /* get_options */
900
867
 
901
868
 
902
869
/*
903
 
** DB_error -- prints mysql error message and exits the program.
 
870
** DB_error -- prints DRIZZLE error message and exits the program.
904
871
*/
905
 
static void DB_error(MYSQL *mysql_arg, const char *when)
 
872
static void DB_error(DRIZZLE *drizzle_arg, const char *when)
906
873
{
907
874
 
908
 
  maybe_die(EX_MYSQLERR, "Got error: %d: %s %s",
909
 
          mysql_errno(mysql_arg), mysql_error(mysql_arg), when);
 
875
  maybe_die(EX_DRIZZLEERR, "Got error: %d: %s %s",
 
876
          drizzle_errno(drizzle_arg), drizzle_error(drizzle_arg), when);
910
877
  return;
911
878
}
912
879
 
980
947
  some.
981
948
 
982
949
  SYNOPSIS
983
 
    mysql_query_with_error_report()
984
 
    mysql_con       connection to use
 
950
    drizzle_query_with_error_report()
 
951
    drizzle_con       connection to use
985
952
    res             if non zero, result will be put there with
986
 
                    mysql_store_result()
 
953
                    drizzle_store_result()
987
954
    query           query to send to server
988
955
 
989
956
  RETURN VALUES
991
958
    1               error
992
959
*/
993
960
 
994
 
static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res,
 
961
static int drizzle_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
995
962
                                         const char *query)
996
963
{
997
 
  if (mysql_query(mysql_con, query) ||
998
 
      (res && !((*res)= mysql_store_result(mysql_con))))
 
964
  if (drizzle_query(drizzle_con, query) ||
 
965
      (res && !((*res)= drizzle_store_result(drizzle_con))))
999
966
  {
1000
 
    maybe_die(EX_MYSQLERR, "Couldn't execute '%s': %s (%d)",
1001
 
            query, mysql_error(mysql_con), mysql_errno(mysql_con));
 
967
    maybe_die(EX_DRIZZLEERR, "Couldn't execute '%s': %s (%d)",
 
968
            query, drizzle_error(drizzle_con), drizzle_errno(drizzle_con));
1002
969
    return 1;
1003
970
  }
1004
971
  return 0;
1017
984
 
1018
985
  @returns  whether there was an error or not
1019
986
*/
1020
 
static int switch_character_set_results(MYSQL *mysql, const char *cs_name)
 
987
static int switch_character_set_results(DRIZZLE *drizzle, const char *cs_name)
1021
988
{
1022
989
  char query_buffer[QUERY_LENGTH];
1023
990
  size_t query_length;
1031
998
                         "SET SESSION character_set_results = '%s'",
1032
999
                         (const char *) cs_name);
1033
1000
 
1034
 
  return mysql_real_query(mysql, query_buffer, query_length);
 
1001
  return drizzle_real_query(drizzle, query_buffer, query_length);
1035
1002
}
1036
1003
 
1037
1004
/*
1049
1016
{
1050
1017
  FILE* res;
1051
1018
  char filename[FN_REFLEN], tmp_path[FN_REFLEN];
1052
 
  convert_dirname(tmp_path,path,NullS);
 
1019
  convert_dirname(tmp_path,path,NULL);
1053
1020
  res= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4),
1054
1021
                O_WRONLY, MYF(MY_WME));
1055
1022
  return res;
1060
1027
{
1061
1028
  if (md_result_file && md_result_file != stdout)
1062
1029
    my_fclose(md_result_file, MYF(0));
1063
 
  my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
 
1030
  free(opt_password);
1064
1031
  if (hash_inited(&ignore_table))
1065
1032
    hash_free(&ignore_table);
1066
 
  if (extended_insert)
1067
 
    dynstr_free(&extended_row);
1068
 
  if (insert_pat_inited)
1069
 
    dynstr_free(&insert_pat);
1070
1033
  if (defaults_argv)
1071
1034
    free_defaults(defaults_argv);
1072
1035
  my_end(my_end_arg);
1079
1042
    first_error= error;
1080
1043
  if (ignore_errors)
1081
1044
    return;
1082
 
  if (mysql)
1083
 
    mysql_close(mysql);
 
1045
  if (drizzle)
 
1046
    drizzle_close(drizzle);
1084
1047
  free_resources();
1085
1048
  exit(error);
1086
1049
}
1096
1059
 
1097
1060
 
1098
1061
  verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1099
 
  mysql_init(&mysql_connection);
 
1062
  drizzle_create(&drizzle_connection);
1100
1063
  if (opt_compress)
1101
 
    mysql_options(&mysql_connection,MYSQL_OPT_COMPRESS,NullS);
1102
 
  if (opt_protocol)
1103
 
    mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
1104
 
  mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset);
1105
 
  if (!(mysql= mysql_real_connect(&mysql_connection,host,user,passwd,
1106
 
                                  NULL,opt_mysql_port, NULL,
 
1064
    drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NULL);
 
1065
  if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
 
1066
                                  NULL,opt_drizzle_port, NULL,
1107
1067
                                  0)))
1108
1068
  {
1109
 
    DB_error(&mysql_connection, "when trying to connect");
 
1069
    DB_error(&drizzle_connection, "when trying to connect");
1110
1070
    return(1);
1111
1071
  }
1112
 
  if (mysql_get_server_version(&mysql_connection) < 40100)
 
1072
  if (drizzle_get_server_version(&drizzle_connection) < 40100)
1113
1073
  {
1114
1074
    /* Don't dump SET NAMES with a pre-4.1 server (bug#7997).  */
1115
1075
    opt_set_charset= 0;
1124
1084
  if (opt_tz_utc)
1125
1085
  {
1126
1086
    snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
1127
 
    if (mysql_query_with_error_report(mysql, 0, buff))
 
1087
    if (drizzle_query_with_error_report(drizzle, 0, buff))
1128
1088
      return(1);
1129
1089
  }
1130
1090
  return(0);
1137
1097
static void dbDisconnect(char *host)
1138
1098
{
1139
1099
  verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost");
1140
 
  mysql_close(mysql);
 
1100
  drizzle_close(drizzle);
1141
1101
} /* dbDisconnect */
1142
1102
 
1143
1103
 
1146
1106
  char *tmp;
1147
1107
 
1148
1108
  if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1149
 
    die(EX_MYSQLERR, "Couldn't allocate memory");
 
1109
    die(EX_DRIZZLEERR, "Couldn't allocate memory");
1150
1110
 
1151
 
  mysql_real_escape_string(&mysql_connection, tmp, pos, length);
 
1111
  drizzle_escape_string(tmp, pos, length);
1152
1112
  fputc('\'', file);
1153
1113
  fputs(tmp, file);
1154
1114
  fputc('\'', file);
1155
1115
  check_io(file);
1156
 
  my_free(tmp, MYF(MY_WME));
 
1116
  free(tmp);
1157
1117
  return;
1158
1118
} /* unescape */
1159
1119
 
1160
1120
 
1161
1121
static bool test_if_special_chars(const char *str)
1162
1122
{
1163
 
#if MYSQL_VERSION_ID >= 32300
1164
1123
  for ( ; *str ; str++)
1165
1124
    if (!my_isvar(charset_info,*str) && *str != '$')
1166
1125
      return 1;
1167
 
#endif
1168
1126
  return 0;
1169
1127
} /* test_if_special_chars */
1170
1128
 
1217
1175
  DESCRIPTION
1218
1176
    Quote \, _, ' and % characters
1219
1177
 
1220
 
    Note: Because MySQL uses the C escape syntax in strings
 
1178
    Note: Because DRIZZLE uses the C escape syntax in strings
1221
1179
    (for example, '\n' to represent newline), you must double
1222
1180
    any '\' that you use in your LIKE  strings. For example, to
1223
1181
    search for '\n', specify it as '\\n'. To search for '\', specify
1263
1221
    Quote '<' '>' '&' '\"' chars and print a string to the xml_file.
1264
1222
*/
1265
1223
 
1266
 
static void print_quoted_xml(FILE *xml_file, const char *str, ulong len)
 
1224
static void print_quoted_xml(FILE *xml_file, const char *str, uint32_t len)
1267
1225
{
1268
1226
  const char *end;
1269
1227
 
1296
1254
 
1297
1255
  SYNOPSIS
1298
1256
    print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name, 
1299
 
                    ..., attribute_name_n, attribute_value_n, NullS)
 
1257
                    ..., attribute_name_n, attribute_value_n, NULL)
1300
1258
    xml_file              - output file
1301
1259
    sbeg                  - line beginning
1302
1260
    line_end              - line ending
1333
1291
 
1334
1292
  va_start(arg_list, first_attribute_name);
1335
1293
  attribute_name= first_attribute_name;
1336
 
  while (attribute_name != NullS)
 
1294
  while (attribute_name != NULL)
1337
1295
  {
1338
1296
    attribute_value= va_arg(arg_list, char *);
1339
 
    assert(attribute_value != NullS);
 
1297
    assert(attribute_value != NULL);
1340
1298
 
1341
1299
    fputc(' ', xml_file);
1342
1300
    fputs(attribute_name, xml_file);    
1407
1365
*/
1408
1366
 
1409
1367
static void print_xml_row(FILE *xml_file, const char *row_name,
1410
 
                          MYSQL_RES *tableRes, MYSQL_ROW *row)
 
1368
                          DRIZZLE_RES *tableRes, DRIZZLE_ROW *row)
1411
1369
{
1412
1370
  uint i;
1413
 
  MYSQL_FIELD *field;
1414
 
  uint32_t *lengths= mysql_fetch_lengths(tableRes);
 
1371
  DRIZZLE_FIELD *field;
 
1372
  uint32_t *lengths= drizzle_fetch_lengths(tableRes);
1415
1373
 
1416
1374
  fprintf(xml_file, "\t\t<%s", row_name);
1417
1375
  check_io(xml_file);
1418
 
  mysql_field_seek(tableRes, 0);
1419
 
  for (i= 0; (field= mysql_fetch_field(tableRes)); i++)
 
1376
  drizzle_field_seek(tableRes, 0);
 
1377
  for (i= 0; (field= drizzle_fetch_field(tableRes)); i++)
1420
1378
  {
1421
1379
    if ((*row)[i])
1422
1380
    {
1446
1404
    Print hex value for blob data.
1447
1405
*/
1448
1406
 
1449
 
static void print_blob_as_hex(FILE *output_file, const char *str, ulong len)
 
1407
static void print_blob_as_hex(FILE *output_file, const char *str, uint32_t len)
1450
1408
{
1451
1409
    /* sakaik got the idea to to provide blob's in hex notation. */
1452
1410
    const char *ptr= str, *end= ptr + len;
1453
1411
    for (; ptr < end ; ptr++)
1454
 
      fprintf(output_file, "%02X", *((uchar *)ptr));
 
1412
      fprintf(output_file, "%02X", *((unsigned char *)ptr));
1455
1413
    check_io(output_file);
1456
1414
}
1457
1415
 
1481
1439
  char       table_buff2[NAME_LEN*2+3], query_buff[QUERY_LENGTH];
1482
1440
  FILE       *sql_file= md_result_file;
1483
1441
  int        len;
1484
 
  MYSQL_RES  *result;
1485
 
  MYSQL_ROW  row;
 
1442
  DRIZZLE_RES  *result;
 
1443
  DRIZZLE_ROW  row;
1486
1444
 
1487
1445
  *ignore_flag= check_if_ignore_table(table, table_type);
1488
1446
 
1498
1456
  if ((write_data= !(*ignore_flag & IGNORE_DATA)))
1499
1457
  {
1500
1458
    complete_insert= opt_complete_insert;
1501
 
    if (!insert_pat_inited)
1502
 
    {
1503
 
      insert_pat_inited= 1;
1504
 
      init_dynamic_string_checked(&insert_pat, "", 1024, 1024);
1505
 
    }
1506
 
    else
1507
 
      dynstr_set_checked(&insert_pat, "");
 
1459
    insert_pat= "";
1508
1460
  }
1509
1461
 
1510
1462
  insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " :
1521
1473
 
1522
1474
  if (opt_order_by_primary)
1523
1475
  {
1524
 
    my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
 
1476
    free(order_by);
1525
1477
    order_by= primary_key_fields(result_table);
1526
1478
  }
1527
1479
 
1528
 
  if (!opt_xml && !mysql_query_with_error_report(mysql, 0, query_buff))
 
1480
  if (!opt_xml && !drizzle_query_with_error_report(drizzle, 0, query_buff))
1529
1481
  {
1530
1482
    /* using SHOW CREATE statement */
1531
1483
    if (!opt_no_create_info)
1532
1484
    {
1533
1485
      /* Make an sql-file, if path was given iow. option -T was given */
1534
1486
      char buff[20+FN_REFLEN];
1535
 
      MYSQL_FIELD *field;
 
1487
      const DRIZZLE_FIELD *field;
1536
1488
 
1537
1489
      snprintf(buff, sizeof(buff), "show create table %s", result_table);
1538
1490
 
1539
 
      if (switch_character_set_results(mysql, "binary") ||
1540
 
          mysql_query_with_error_report(mysql, &result, buff) ||
1541
 
          switch_character_set_results(mysql, default_charset))
 
1491
      if (switch_character_set_results(drizzle, "binary") ||
 
1492
          drizzle_query_with_error_report(drizzle, &result, buff) ||
 
1493
          switch_character_set_results(drizzle, default_charset))
1542
1494
        return(0);
1543
1495
 
1544
1496
      if (path)
1569
1521
        check_io(sql_file);
1570
1522
      }
1571
1523
 
1572
 
      field= mysql_fetch_field_direct(result, 0);
 
1524
      field= drizzle_fetch_field_direct(result, 0);
1573
1525
      if (strcmp(field->name, "View") == 0)
1574
1526
      {
1575
1527
        char *scv_buff= NULL;
1577
1529
        verbose_msg("-- It's a view, create dummy table for view\n");
1578
1530
 
1579
1531
        /* save "show create" statement for later */
1580
 
        if ((row= mysql_fetch_row(result)) && (scv_buff=row[1]))
 
1532
        if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
1581
1533
          scv_buff= my_strdup(scv_buff, MYF(0));
1582
1534
 
1583
 
        mysql_free_result(result);
 
1535
        drizzle_free_result(result);
1584
1536
 
1585
1537
        /*
1586
1538
          Create a table with the same name as the view and with columns of
1595
1547
        */
1596
1548
        snprintf(query_buff, sizeof(query_buff),
1597
1549
                 "SHOW FIELDS FROM %s", result_table);
1598
 
        if (switch_character_set_results(mysql, "binary") ||
1599
 
            mysql_query_with_error_report(mysql, &result, query_buff) ||
1600
 
            switch_character_set_results(mysql, default_charset))
 
1550
        if (switch_character_set_results(drizzle, "binary") ||
 
1551
            drizzle_query_with_error_report(drizzle, &result, query_buff) ||
 
1552
            switch_character_set_results(drizzle, default_charset))
1601
1553
        {
1602
1554
          /*
1603
1555
            View references invalid or privileged table/col/fun (err 1356),
1605
1557
            a comment with the view's 'show create' statement. (Bug #17371)
1606
1558
          */
1607
1559
 
1608
 
          if (mysql_errno(mysql) == ER_VIEW_INVALID)
 
1560
          if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1609
1561
            fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1610
1562
 
1611
 
          my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
 
1563
          free(scv_buff);
1612
1564
 
1613
1565
          return(0);
1614
1566
        }
1615
1567
        else
1616
 
          my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
 
1568
          free(scv_buff);
1617
1569
 
1618
 
        if (mysql_num_rows(result))
 
1570
        if (drizzle_num_rows(result))
1619
1571
        {
1620
1572
          if (opt_drop)
1621
1573
          {
1630
1582
          }
1631
1583
 
1632
1584
          fprintf(sql_file,
1633
 
                  "SET @saved_cs_client     = @@character_set_client;\n"
1634
 
                  "SET character_set_client = utf8;\n"
1635
1585
                  "/*!50001 CREATE TABLE %s (\n",
1636
1586
                  result_table);
1637
1587
 
1641
1591
            there should be a _trailing_ comma.
1642
1592
          */
1643
1593
 
1644
 
          row= mysql_fetch_row(result);
 
1594
          row= drizzle_fetch_row(result);
1645
1595
 
1646
1596
          fprintf(sql_file, "  %s %s", quote_name(row[0], name_buff, 0),
1647
1597
                  row[1]);
1648
1598
 
1649
 
          while((row= mysql_fetch_row(result)))
 
1599
          while((row= drizzle_fetch_row(result)))
1650
1600
          {
1651
1601
            /* col name, col type */
1652
1602
            fprintf(sql_file, ",\n  %s %s",
1653
1603
                    quote_name(row[0], name_buff, 0), row[1]);
1654
1604
          }
1655
 
          fprintf(sql_file,
1656
 
                  "\n) */;\n"
1657
 
                  "SET character_set_client = @saved_cs_client;\n");
1658
 
 
 
1605
          fprintf(sql_file, "\n) */;\n"); 
1659
1606
          check_io(sql_file);
1660
1607
        }
1661
1608
 
1662
 
        mysql_free_result(result);
 
1609
        drizzle_free_result(result);
1663
1610
 
1664
1611
        if (path)
1665
1612
          my_fclose(sql_file, MYF(MY_WME));
1668
1615
        return(0);
1669
1616
      }
1670
1617
 
1671
 
      row= mysql_fetch_row(result);
 
1618
      row= drizzle_fetch_row(result);
1672
1619
 
1673
 
      fprintf(sql_file,
1674
 
              "SET @saved_cs_client     = @@character_set_client;\n"
1675
 
              "SET character_set_client = utf8;\n"
1676
 
              "%s;\n"
1677
 
              "SET character_set_client = @saved_cs_client;\n",
1678
 
              row[1]);
 
1620
      fprintf(sql_file, "%s;\n", row[1]);
1679
1621
 
1680
1622
      check_io(sql_file);
1681
 
      mysql_free_result(result);
 
1623
      drizzle_free_result(result);
1682
1624
    }
1683
1625
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1684
1626
             result_table);
1685
 
    if (mysql_query_with_error_report(mysql, &result, query_buff))
 
1627
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1686
1628
    {
1687
1629
      if (path)
1688
1630
        my_fclose(sql_file, MYF(MY_WME));
1698
1640
    if (write_data)
1699
1641
    {
1700
1642
      if (opt_replace_into)
1701
 
        dynstr_append_checked(&insert_pat, "REPLACE ");
 
1643
        insert_pat.append("REPLACE ");
1702
1644
      else
1703
 
        dynstr_append_checked(&insert_pat, "INSERT ");
1704
 
      dynstr_append_checked(&insert_pat, insert_option);
1705
 
      dynstr_append_checked(&insert_pat, "INTO ");
1706
 
      dynstr_append_checked(&insert_pat, opt_quoted_table);
 
1645
        insert_pat.append("INSERT ");
 
1646
      insert_pat.append(insert_option);
 
1647
      insert_pat.append("INTO ");
 
1648
      insert_pat.append(opt_quoted_table);
1707
1649
      if (complete_insert)
1708
1650
      {
1709
 
        dynstr_append_checked(&insert_pat, " (");
 
1651
        insert_pat.append(" (");
1710
1652
      }
1711
1653
      else
1712
1654
      {
1713
 
        dynstr_append_checked(&insert_pat, " VALUES ");
 
1655
        insert_pat.append(" VALUES ");
1714
1656
        if (!extended_insert)
1715
 
          dynstr_append_checked(&insert_pat, "(");
 
1657
          insert_pat.append("(");
1716
1658
      }
1717
1659
    }
1718
1660
 
1719
 
    while ((row= mysql_fetch_row(result)))
 
1661
    while ((row= drizzle_fetch_row(result)))
1720
1662
    {
1721
1663
      if (complete_insert)
1722
1664
      {
1723
1665
        if (init)
1724
1666
        {
1725
 
          dynstr_append_checked(&insert_pat, ", ");
 
1667
          insert_pat.append(", ");
1726
1668
        }
1727
1669
        init=1;
1728
 
        dynstr_append_checked(&insert_pat,
1729
 
                      quote_name(row[SHOW_FIELDNAME], name_buff, 0));
 
1670
        insert_pat.append(quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1730
1671
      }
1731
1672
    }
1732
 
    num_fields= mysql_num_rows(result);
1733
 
    mysql_free_result(result);
 
1673
    num_fields= drizzle_num_rows(result);
 
1674
    drizzle_free_result(result);
1734
1675
  }
1735
1676
  else
1736
1677
  {
1737
1678
    verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
1738
 
                my_progname, mysql_error(mysql));
 
1679
                my_progname, drizzle_error(drizzle));
1739
1680
 
1740
1681
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1741
1682
             result_table);
1742
 
    if (mysql_query_with_error_report(mysql, &result, query_buff))
 
1683
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1743
1684
      return(0);
1744
1685
 
1745
1686
    /* Make an sql-file, if path was given iow. option -T was given */
1760
1701
        fprintf(sql_file, "CREATE TABLE %s (\n", result_table);
1761
1702
      else
1762
1703
        print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table, 
1763
 
                NullS);
 
1704
                NULL);
1764
1705
      check_io(sql_file);
1765
1706
    }
1766
1707
 
1767
1708
    if (write_data)
1768
1709
    {
1769
1710
      if (opt_replace_into)
1770
 
        dynstr_append_checked(&insert_pat, "REPLACE ");
 
1711
        insert_pat.append("REPLACE ");
1771
1712
      else
1772
 
        dynstr_append_checked(&insert_pat, "INSERT ");
1773
 
      dynstr_append_checked(&insert_pat, insert_option);
1774
 
      dynstr_append_checked(&insert_pat, "INTO ");
1775
 
      dynstr_append_checked(&insert_pat, result_table);
 
1713
        insert_pat.append("INSERT ");
 
1714
      insert_pat.append(insert_option);
 
1715
      insert_pat.append("INTO ");
 
1716
      insert_pat.append(result_table);
1776
1717
      if (complete_insert)
1777
 
        dynstr_append_checked(&insert_pat, " (");
 
1718
        insert_pat.append(" (");
1778
1719
      else
1779
1720
      {
1780
 
        dynstr_append_checked(&insert_pat, " VALUES ");
 
1721
        insert_pat.append(" VALUES ");
1781
1722
        if (!extended_insert)
1782
 
          dynstr_append_checked(&insert_pat, "(");
 
1723
          insert_pat.append("(");
1783
1724
      }
1784
1725
    }
1785
1726
 
1786
 
    while ((row= mysql_fetch_row(result)))
 
1727
    while ((row= drizzle_fetch_row(result)))
1787
1728
    {
1788
 
      uint32_t *lengths= mysql_fetch_lengths(result);
 
1729
      uint32_t *lengths= drizzle_fetch_lengths(result);
1789
1730
      if (init)
1790
1731
      {
1791
1732
        if (!opt_xml && !opt_no_create_info)
1794
1735
          check_io(sql_file);
1795
1736
        }
1796
1737
        if (complete_insert)
1797
 
          dynstr_append_checked(&insert_pat, ", ");
 
1738
          insert_pat.append(", ");
1798
1739
      }
1799
1740
      init=1;
1800
1741
      if (complete_insert)
1801
 
        dynstr_append_checked(&insert_pat,
1802
 
                      quote_name(row[SHOW_FIELDNAME], name_buff, 0));
 
1742
        insert_pat.append(quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1803
1743
      if (!opt_no_create_info)
1804
1744
      {
1805
1745
        if (opt_xml)
1828
1768
        check_io(sql_file);
1829
1769
      }
1830
1770
    }
1831
 
    num_fields= mysql_num_rows(result);
1832
 
    mysql_free_result(result);
 
1771
    num_fields= drizzle_num_rows(result);
 
1772
    drizzle_free_result(result);
1833
1773
    if (!opt_no_create_info)
1834
1774
    {
1835
1775
      /* Make an sql-file, if path was given iow. option -T was given */
1836
1776
      char buff[20+FN_REFLEN];
1837
1777
      uint keynr,primary_key;
1838
1778
      snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1839
 
      if (mysql_query_with_error_report(mysql, &result, buff))
 
1779
      if (drizzle_query_with_error_report(drizzle, &result, buff))
1840
1780
      {
1841
 
        if (mysql_errno(mysql) == ER_WRONG_OBJECT)
 
1781
        if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
1842
1782
        {
1843
1783
          /* it is VIEW */
1844
1784
          fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1845
1785
          goto continue_xml;
1846
1786
        }
1847
1787
        fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
1848
 
                my_progname, result_table, mysql_error(mysql));
 
1788
                my_progname, result_table, drizzle_error(drizzle));
1849
1789
        if (path)
1850
1790
          my_fclose(sql_file, MYF(MY_WME));
1851
1791
        return(0);
1854
1794
      /* Find first which key is primary key */
1855
1795
      keynr=0;
1856
1796
      primary_key=INT_MAX;
1857
 
      while ((row= mysql_fetch_row(result)))
 
1797
      while ((row= drizzle_fetch_row(result)))
1858
1798
      {
1859
1799
        if (atoi(row[3]) == 1)
1860
1800
        {
1870
1810
          }
1871
1811
        }
1872
1812
      }
1873
 
      mysql_data_seek(result,0);
 
1813
      drizzle_data_seek(result,0);
1874
1814
      keynr=0;
1875
 
      while ((row= mysql_fetch_row(result)))
 
1815
      while ((row= drizzle_fetch_row(result)))
1876
1816
      {
1877
1817
        if (opt_xml)
1878
1818
        {
1900
1840
          fprintf(sql_file, " (%s)",row[7]);      /* Sub key */
1901
1841
        check_io(sql_file);
1902
1842
      }
1903
 
      mysql_free_result(result);
 
1843
      drizzle_free_result(result);
1904
1844
      if (!opt_xml)
1905
1845
      {
1906
1846
        if (keynr)
1909
1849
        check_io(sql_file);
1910
1850
      }
1911
1851
 
1912
 
      /* Get MySQL specific create options */
 
1852
      /* Get DRIZZLE specific create options */
1913
1853
      if (create_options)
1914
1854
      {
1915
1855
        char show_name_buff[NAME_LEN*2+2+24];
1918
1858
        snprintf(buff, sizeof(buff), "show table status like %s",
1919
1859
                 quote_for_like(table, show_name_buff));
1920
1860
 
1921
 
        if (mysql_query_with_error_report(mysql, &result, buff))
 
1861
        if (drizzle_query_with_error_report(drizzle, &result, buff))
1922
1862
        {
1923
 
          if (mysql_errno(mysql) != ER_PARSE_ERROR)
1924
 
          {                                     /* If old MySQL version */
 
1863
          if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
 
1864
          {                                     /* If old DRIZZLE version */
1925
1865
            verbose_msg("-- Warning: Couldn't get status information for " \
1926
 
                        "table %s (%s)\n", result_table,mysql_error(mysql));
 
1866
                        "table %s (%s)\n", result_table,drizzle_error(drizzle));
1927
1867
          }
1928
1868
        }
1929
 
        else if (!(row= mysql_fetch_row(result)))
 
1869
        else if (!(row= drizzle_fetch_row(result)))
1930
1870
        {
1931
1871
          fprintf(stderr,
1932
1872
                  "Error: Couldn't read status information for table %s (%s)\n",
1933
 
                  result_table,mysql_error(mysql));
 
1873
                  result_table,drizzle_error(drizzle));
1934
1874
        }
1935
1875
        else
1936
1876
        {
1946
1886
            check_io(sql_file);
1947
1887
          }
1948
1888
        }
1949
 
        mysql_free_result(result);              /* Is always safe to free */
 
1889
        drizzle_free_result(result);              /* Is always safe to free */
1950
1890
      }
1951
1891
continue_xml:
1952
1892
      if (!opt_xml)
1958
1898
  }
1959
1899
  if (complete_insert)
1960
1900
  {
1961
 
    dynstr_append_checked(&insert_pat, ") VALUES ");
 
1901
    insert_pat.append(") VALUES ");
1962
1902
    if (!extended_insert)
1963
 
      dynstr_append_checked(&insert_pat, "(");
 
1903
      insert_pat.append("(");
1964
1904
  }
1965
1905
  if (sql_file != md_result_file)
1966
1906
  {
1971
1911
  return((uint) num_fields);
1972
1912
} /* get_table_structure */
1973
1913
 
1974
 
static void add_load_option(DYNAMIC_STRING *str, const char *option,
1975
 
                             const char *option_value)
 
1914
static void add_load_option(string &str, const char *option,
 
1915
                            const char *option_value)
1976
1916
{
1977
1917
  if (!option_value)
1978
1918
  {
1980
1920
    return;
1981
1921
  }
1982
1922
 
1983
 
  dynstr_append_checked(str, option);
 
1923
  str.append(option);
1984
1924
  
1985
1925
  if (strncmp(option_value, "0x", sizeof("0x")-1) == 0)
1986
1926
  {
1987
1927
    /* It's a hex constant, don't escape */
1988
 
    dynstr_append_checked(str, option_value);
 
1928
    str.append(option_value);
1989
1929
  }
1990
1930
  else
1991
1931
  {
2002
1942
  syntax errors from the SQL parser.
2003
1943
*/
2004
1944
 
2005
 
static void field_escape(DYNAMIC_STRING* in, const char *from)
 
1945
static void field_escape(string &in, const char *from)
2006
1946
{
2007
1947
  uint end_backslashes= 0; 
2008
1948
 
2009
 
  dynstr_append_checked(in, "'");
 
1949
  in.append("'");
2010
1950
 
2011
1951
  while (*from)
2012
1952
  {
2013
 
    dynstr_append_mem_checked(in, from, 1);
 
1953
    in.append(from, 1);
2014
1954
 
2015
1955
    if (*from == '\\')
2016
1956
      end_backslashes^=1;    /* find odd number of backslashes */
2018
1958
    {
2019
1959
      if (*from == '\'' && !end_backslashes)
2020
1960
      {
2021
 
        /* We want a duplicate of "'" for MySQL */
2022
 
        dynstr_append_checked(in, "\'");
 
1961
        /* We want a duplicate of "'" for DRIZZLE */
 
1962
        in.append("\'");
2023
1963
      }
2024
1964
      end_backslashes=0;
2025
1965
    }
2027
1967
  }
2028
1968
  /* Add missing backslashes if user has specified odd number of backs.*/
2029
1969
  if (end_backslashes)
2030
 
    dynstr_append_checked(in, "\\");
2031
 
  
2032
 
  dynstr_append_checked(in, "'");
 
1970
    in.append("\\");
 
1971
 
 
1972
  in.append("'");
2033
1973
}
2034
1974
 
2035
1975
 
2054
1994
{
2055
1995
  char ignore_flag;
2056
1996
  char buf[200], table_buff[NAME_LEN+3];
2057
 
  DYNAMIC_STRING query_string;
 
1997
  string query_string;
2058
1998
  char table_type[NAME_LEN];
2059
1999
  char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table;
2060
2000
  int error= 0;
2061
 
  ulong         rownr, row_break, total_length, init_length;
 
2001
  uint32_t         rownr, row_break, total_length, init_length;
2062
2002
  uint num_fields;
2063
 
  MYSQL_RES     *res;
2064
 
  MYSQL_FIELD   *field;
2065
 
  MYSQL_ROW     row;
 
2003
  DRIZZLE_RES     *res;
 
2004
  DRIZZLE_FIELD   *field;
 
2005
  DRIZZLE_ROW     row;
2066
2006
 
2067
2007
 
2068
2008
  /*
2108
2048
     discarding SHOW CREATE EVENT statements generation. The myslq.event
2109
2049
     table data should be skipped too.
2110
2050
  */
2111
 
  if (!opt_events && !my_strcasecmp(&my_charset_latin1, db, "mysql") &&
2112
 
      !my_strcasecmp(&my_charset_latin1, table, "event"))
 
2051
  if (!opt_events && !my_strcasecmp(&my_charset_utf8_general_ci, db, "mysql") &&
 
2052
      !my_strcasecmp(&my_charset_utf8_general_ci, table, "event"))
2113
2053
  {
2114
2054
    verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2115
2055
    return;
2120
2060
 
2121
2061
  verbose_msg("-- Sending SELECT query...\n");
2122
2062
 
2123
 
  init_dynamic_string_checked(&query_string, "", 1024, 1024);
 
2063
  query_string.clear();
 
2064
  query_string.reserve(1024);
2124
2065
 
2125
2066
  if (path)
2126
2067
  {
2130
2071
      Convert the path to native os format
2131
2072
      and resolve to the full filepath.
2132
2073
    */
2133
 
    convert_dirname(tmp_path,path,NullS);    
 
2074
    convert_dirname(tmp_path,path,NULL);    
2134
2075
    my_load_path(tmp_path, tmp_path, NULL);
2135
2076
    fn_format(filename, table, tmp_path, ".txt", MYF(MY_UNPACK_FILENAME));
2136
2077
 
2142
2083
 
2143
2084
    /* now build the query string */
2144
2085
 
2145
 
    dynstr_append_checked(&query_string, "SELECT * INTO OUTFILE '");
2146
 
    dynstr_append_checked(&query_string, filename);
2147
 
    dynstr_append_checked(&query_string, "'");
 
2086
    query_string.append( "SELECT * INTO OUTFILE '");
 
2087
    query_string.append( filename);
 
2088
    query_string.append( "'");
2148
2089
 
2149
2090
    if (fields_terminated || enclosed || opt_enclosed || escaped)
2150
 
      dynstr_append_checked(&query_string, " FIELDS");
 
2091
      query_string.append( " FIELDS");
2151
2092
    
2152
 
    add_load_option(&query_string, " TERMINATED BY ", fields_terminated);
2153
 
    add_load_option(&query_string, " ENCLOSED BY ", enclosed);
2154
 
    add_load_option(&query_string, " OPTIONALLY ENCLOSED BY ", opt_enclosed);
2155
 
    add_load_option(&query_string, " ESCAPED BY ", escaped);
2156
 
    add_load_option(&query_string, " LINES TERMINATED BY ", lines_terminated);
 
2093
    add_load_option(query_string, " TERMINATED BY ", fields_terminated);
 
2094
    add_load_option(query_string, " ENCLOSED BY ", enclosed);
 
2095
    add_load_option(query_string, " OPTIONALLY ENCLOSED BY ", opt_enclosed);
 
2096
    add_load_option(query_string, " ESCAPED BY ", escaped);
 
2097
    add_load_option(query_string, " LINES TERMINATED BY ", lines_terminated);
2157
2098
 
2158
 
    dynstr_append_checked(&query_string, " FROM ");
2159
 
    dynstr_append_checked(&query_string, result_table);
 
2099
    query_string.append( " FROM ");
 
2100
    query_string.append( result_table);
2160
2101
 
2161
2102
    if (where)
2162
2103
    {
2163
 
      dynstr_append_checked(&query_string, " WHERE ");
2164
 
      dynstr_append_checked(&query_string, where);
 
2104
      query_string.append( " WHERE ");
 
2105
      query_string.append( where);
2165
2106
    }
2166
2107
 
2167
2108
    if (order_by)
2168
2109
    {
2169
 
      dynstr_append_checked(&query_string, " ORDER BY ");
2170
 
      dynstr_append_checked(&query_string, order_by);
 
2110
      query_string.append( " ORDER BY ");
 
2111
      query_string.append( order_by);
2171
2112
    }
2172
2113
 
2173
 
    if (mysql_real_query(mysql, query_string.str, query_string.length))
 
2114
    if (drizzle_real_query(drizzle, query_string.c_str(), query_string.length()))
2174
2115
    {
2175
 
      DB_error(mysql, "when executing 'SELECT INTO OUTFILE'");
2176
 
      dynstr_free(&query_string);
 
2116
      DB_error(drizzle, "when executing 'SELECT INTO OUTFILE'");
2177
2117
      return;
2178
2118
    }
2179
2119
  }
2186
2126
      check_io(md_result_file);
2187
2127
    }
2188
2128
    
2189
 
    dynstr_append_checked(&query_string, "SELECT * FROM ");
2190
 
    dynstr_append_checked(&query_string, result_table);
 
2129
    query_string.append( "SELECT * FROM ");
 
2130
    query_string.append( result_table);
2191
2131
 
2192
2132
    if (where)
2193
2133
    {
2197
2137
        check_io(md_result_file);
2198
2138
      }
2199
2139
      
2200
 
      dynstr_append_checked(&query_string, " WHERE ");
2201
 
      dynstr_append_checked(&query_string, where);
 
2140
      query_string.append( " WHERE ");
 
2141
      query_string.append( where);
2202
2142
    }
2203
2143
    if (order_by)
2204
2144
    {
2207
2147
        fprintf(md_result_file, "-- ORDER BY:  %s\n", order_by);
2208
2148
        check_io(md_result_file);
2209
2149
      }
2210
 
      dynstr_append_checked(&query_string, " ORDER BY ");
2211
 
      dynstr_append_checked(&query_string, order_by);
 
2150
      query_string.append( " ORDER BY ");
 
2151
      query_string.append( order_by);
2212
2152
    }
2213
2153
 
2214
2154
    if (!opt_xml && !opt_compact)
2216
2156
      fputs("\n", md_result_file);
2217
2157
      check_io(md_result_file);
2218
2158
    }
2219
 
    if (mysql_query_with_error_report(mysql, 0, query_string.str))
 
2159
    if (drizzle_query_with_error_report(drizzle, 0, query_string.c_str()))
2220
2160
    {
2221
 
      DB_error(mysql, "when retrieving data from server");
 
2161
      DB_error(drizzle, "when retrieving data from server");
2222
2162
      goto err;
2223
2163
    }
2224
2164
    if (quick)
2225
 
      res=mysql_use_result(mysql);
 
2165
      res=drizzle_use_result(drizzle);
2226
2166
    else
2227
 
      res=mysql_store_result(mysql);
 
2167
      res=drizzle_store_result(drizzle);
2228
2168
    if (!res)
2229
2169
    {
2230
 
      DB_error(mysql, "when retrieving data from server");
 
2170
      DB_error(drizzle, "when retrieving data from server");
2231
2171
      goto err;
2232
2172
    }
2233
2173
 
2234
2174
    verbose_msg("-- Retrieving rows...\n");
2235
 
    if (mysql_num_fields(res) != num_fields)
 
2175
    if (drizzle_num_fields(res) != num_fields)
2236
2176
    {
2237
2177
      fprintf(stderr,"%s: Error in field count for table: %s !  Aborting.\n",
2238
2178
              my_progname, result_table);
2256
2196
    total_length= opt_net_buffer_length;                /* Force row break */
2257
2197
    row_break=0;
2258
2198
    rownr=0;
2259
 
    init_length=(uint) insert_pat.length+4;
 
2199
    init_length=(uint) insert_pat.length()+4;
2260
2200
    if (opt_xml)
2261
2201
      print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
2262
 
              NullS);
 
2202
              NULL);
2263
2203
    if (opt_autocommit)
2264
2204
    {
2265
2205
      fprintf(md_result_file, "set autocommit=0;\n");
2266
2206
      check_io(md_result_file);
2267
2207
    }
2268
2208
 
2269
 
    while ((row= mysql_fetch_row(res)))
 
2209
    while ((row= drizzle_fetch_row(res)))
2270
2210
    {
2271
2211
      uint i;
2272
 
      uint32_t *lengths= mysql_fetch_lengths(res);
 
2212
      uint32_t *lengths= drizzle_fetch_lengths(res);
2273
2213
      rownr++;
2274
2214
      if (!extended_insert && !opt_xml)
2275
2215
      {
2276
 
        fputs(insert_pat.str,md_result_file);
 
2216
        fputs(insert_pat.c_str(),md_result_file);
2277
2217
        check_io(md_result_file);
2278
2218
      }
2279
 
      mysql_field_seek(res,0);
 
2219
      drizzle_field_seek(res,0);
2280
2220
 
2281
2221
      if (opt_xml)
2282
2222
      {
2284
2224
        check_io(md_result_file);
2285
2225
      }
2286
2226
 
2287
 
      for (i= 0; i < mysql_num_fields(res); i++)
 
2227
      for (i= 0; i < drizzle_num_fields(res); i++)
2288
2228
      {
2289
2229
        int is_blob;
2290
 
        ulong length= lengths[i];
 
2230
        uint32_t length= lengths[i];
2291
2231
 
2292
 
        if (!(field= mysql_fetch_field(res)))
 
2232
        if (!(field= drizzle_fetch_field(res)))
2293
2233
          die(EX_CONSCHECK,
2294
2234
                      "Not enough fields from table %s! Aborting.\n",
2295
2235
                      result_table);
2300
2240
           we'll dump in hex only BLOB columns.
2301
2241
        */
2302
2242
        is_blob= (opt_hex_blob && field->charsetnr == 63 &&
2303
 
                  (field->type == MYSQL_TYPE_STRING ||
2304
 
                   field->type == MYSQL_TYPE_VARCHAR ||
2305
 
                   field->type == MYSQL_TYPE_BLOB)) ? 1 : 0;
 
2243
                  (field->type == DRIZZLE_TYPE_VARCHAR ||
 
2244
                   field->type == DRIZZLE_TYPE_BLOB)) ? 1 : 0;
2306
2245
        if (extended_insert && !opt_xml)
2307
2246
        {
2308
2247
          if (i == 0)
2309
 
            dynstr_set_checked(&extended_row,"(");
 
2248
            extended_row= "(";
2310
2249
          else
2311
 
            dynstr_append_checked(&extended_row,",");
 
2250
            extended_row.append(",");
2312
2251
 
2313
2252
          if (row[i])
2314
2253
          {
2315
2254
            if (length)
2316
2255
            {
2317
 
              if (!IS_NUM_FIELD(field))
 
2256
              if (!(field->type & NUM_FLAG))
2318
2257
              {
2319
2258
                /*
2320
2259
                  "length * 2 + 2" is OK for both HEX and non-HEX modes:
2324
2263
                  plus 2 bytes for leading and trailing '\'' characters.
2325
2264
                  Also we need to reserve 1 byte for terminating '\0'.
2326
2265
                */
2327
 
                dynstr_realloc_checked(&extended_row,length * 2 + 2 + 1);
 
2266
                char * tmp_str= (char *)malloc(length * 2 + 2 + 1);
 
2267
                memset(tmp_str, '\0', length * 2 + 2 + 1);
2328
2268
                if (opt_hex_blob && is_blob)
2329
2269
                {
2330
 
                  dynstr_append_checked(&extended_row, "0x");
2331
 
                  extended_row.length+= mysql_hex_string(extended_row.str +
2332
 
                                                         extended_row.length,
2333
 
                                                         row[i], length);
2334
 
                  assert(extended_row.length+1 <= extended_row.max_length);
2335
 
                  /* mysql_hex_string() already terminated string by '\0' */
2336
 
                  assert(extended_row.str[extended_row.length] == '\0');
 
2270
                  extended_row.append("0x");
 
2271
                  drizzle_hex_string(tmp_str, row[i], length);
 
2272
                  extended_row.append(tmp_str);
2337
2273
                }
2338
2274
                else
2339
2275
                {
2340
 
                  dynstr_append_checked(&extended_row,"'");
2341
 
                  extended_row.length +=
2342
 
                  mysql_real_escape_string(&mysql_connection,
2343
 
                                           &extended_row.str[extended_row.length],
2344
 
                                           row[i],length);
2345
 
                  extended_row.str[extended_row.length]='\0';
2346
 
                  dynstr_append_checked(&extended_row,"'");
 
2276
                  extended_row.append("'");
 
2277
                  drizzle_escape_string(tmp_str,
 
2278
                                        row[i],length);
 
2279
                  extended_row.append(tmp_str);
 
2280
                  extended_row.append("'");
2347
2281
                }
 
2282
                free(tmp_str);
2348
2283
              }
2349
2284
              else
2350
2285
              {
2352
2287
                char *ptr= row[i];
2353
2288
                if (my_isalpha(charset_info, *ptr) || (*ptr == '-' &&
2354
2289
                    my_isalpha(charset_info, ptr[1])))
2355
 
                  dynstr_append_checked(&extended_row, "NULL");
 
2290
                  extended_row.append( "NULL");
2356
2291
                else
2357
2292
                {
2358
 
                  dynstr_append_checked(&extended_row, ptr);
 
2293
                  extended_row.append( ptr);
2359
2294
                }
2360
2295
              }
2361
2296
            }
2362
2297
            else
2363
 
              dynstr_append_checked(&extended_row,"''");
 
2298
              extended_row.append("''");
2364
2299
          }
2365
2300
          else
2366
 
            dynstr_append_checked(&extended_row,"NULL");
 
2301
            extended_row.append("NULL");
2367
2302
        }
2368
2303
        else
2369
2304
        {
2374
2309
          }
2375
2310
          if (row[i])
2376
2311
          {
2377
 
            if (!IS_NUM_FIELD(field))
 
2312
            if (!(field->type & NUM_FLAG))
2378
2313
            {
2379
2314
              if (opt_xml)
2380
2315
              {
2382
2317
                {
2383
2318
                  /* Define xsi:type="xs:hexBinary" for hex encoded data */
2384
2319
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2385
 
                                field->name, "xsi:type=", "xs:hexBinary", NullS);
 
2320
                                field->name, "xsi:type=", "xs:hexBinary", NULL);
2386
2321
                  print_blob_as_hex(md_result_file, row[i], length);
2387
2322
                }
2388
2323
                else
2389
2324
                {
2390
2325
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=", 
2391
 
                                field->name, NullS);
 
2326
                                field->name, NULL);
2392
2327
                  print_quoted_xml(md_result_file, row[i], length);
2393
2328
                }
2394
2329
                fputs("</field>\n", md_result_file);
2408
2343
              if (opt_xml)
2409
2344
              {
2410
2345
                print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2411
 
                        field->name, NullS);
 
2346
                        field->name, NULL);
2412
2347
                fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
2413
2348
                      md_result_file);
2414
2349
                fputs("</field>\n", md_result_file);
2441
2376
 
2442
2377
      if (extended_insert)
2443
2378
      {
2444
 
        ulong row_length;
2445
 
        dynstr_append_checked(&extended_row,")");
2446
 
        row_length= 2 + extended_row.length;
 
2379
        uint32_t row_length;
 
2380
        extended_row.append(")");
 
2381
        row_length= 2 + extended_row.length();
2447
2382
        if (total_length + row_length < opt_net_buffer_length)
2448
2383
        {
2449
2384
          total_length+= row_length;
2450
2385
          fputc(',',md_result_file);            /* Always row break */
2451
 
          fputs(extended_row.str,md_result_file);
 
2386
          fputs(extended_row.c_str(),md_result_file);
2452
2387
        }
2453
2388
        else
2454
2389
        {
2456
2391
            fputs(";\n", md_result_file);
2457
2392
          row_break=1;                          /* This is first row */
2458
2393
 
2459
 
          fputs(insert_pat.str,md_result_file);
2460
 
          fputs(extended_row.str,md_result_file);
 
2394
          fputs(insert_pat.c_str(),md_result_file);
 
2395
          fputs(extended_row.c_str(),md_result_file);
2461
2396
          total_length= row_length+init_length;
2462
2397
        }
2463
2398
        check_io(md_result_file);
2476
2411
      fputs(";\n", md_result_file);             /* If not empty table */
2477
2412
    fflush(md_result_file);
2478
2413
    check_io(md_result_file);
2479
 
    if (mysql_errno(mysql))
 
2414
    if (drizzle_errno(drizzle))
2480
2415
    {
2481
2416
      snprintf(buf, sizeof(buf),
2482
 
               "%s: Error %d: %s when dumping table %s at row: %ld\n",
 
2417
               "%s: Error %d: %s when dumping table %s at row: %d\n",
2483
2418
               my_progname,
2484
 
               mysql_errno(mysql),
2485
 
               mysql_error(mysql),
 
2419
               drizzle_errno(drizzle),
 
2420
               drizzle_error(drizzle),
2486
2421
               result_table,
2487
2422
               rownr);
2488
2423
      fputs(buf,stderr);
2507
2442
      fprintf(md_result_file, "commit;\n");
2508
2443
      check_io(md_result_file);
2509
2444
    }
2510
 
    mysql_free_result(res);
 
2445
    drizzle_free_result(res);
2511
2446
  }
2512
 
  dynstr_free(&query_string);
2513
2447
  return;
2514
2448
 
2515
2449
err:
2516
 
  dynstr_free(&query_string);
2517
2450
  maybe_exit(error);
2518
2451
  return;
2519
2452
} /* dump_table */
2521
2454
 
2522
2455
static char *getTableName(int reset)
2523
2456
{
2524
 
  static MYSQL_RES *res= NULL;
2525
 
  MYSQL_ROW    row;
 
2457
  static DRIZZLE_RES *res= NULL;
 
2458
  DRIZZLE_ROW    row;
2526
2459
 
2527
2460
  if (!res)
2528
2461
  {
2529
 
    if (!(res= mysql_list_tables(mysql,NullS)))
 
2462
    if (!(res= drizzle_list_tables(drizzle,NULL)))
2530
2463
      return(NULL);
2531
2464
  }
2532
 
  if ((row= mysql_fetch_row(res)))
 
2465
  if ((row= drizzle_fetch_row(res)))
2533
2466
    return((char*) row[0]);
2534
2467
 
2535
2468
  if (reset)
2536
 
    mysql_data_seek(res,0);      /* We want to read again */
 
2469
    drizzle_data_seek(res,0);      /* We want to read again */
2537
2470
  else
2538
2471
  {
2539
 
    mysql_free_result(res);
 
2472
    drizzle_free_result(res);
2540
2473
    res= NULL;
2541
2474
  }
2542
2475
  return(NULL);
2545
2478
 
2546
2479
static int dump_all_databases()
2547
2480
{
2548
 
  MYSQL_ROW row;
2549
 
  MYSQL_RES *tableres;
 
2481
  DRIZZLE_ROW row;
 
2482
  DRIZZLE_RES *tableres;
2550
2483
  int result=0;
2551
2484
 
2552
 
  if (mysql_query_with_error_report(mysql, &tableres, "SHOW DATABASES"))
 
2485
  if (drizzle_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
2553
2486
    return 1;
2554
 
  while ((row= mysql_fetch_row(tableres)))
 
2487
  while ((row= drizzle_fetch_row(tableres)))
2555
2488
  {
2556
2489
    if (dump_all_tables_in_db(row[0]))
2557
2490
      result=1;
2595
2528
  if (!opt_create_db)
2596
2529
  {
2597
2530
    char qbuf[256];
2598
 
    MYSQL_ROW row;
2599
 
    MYSQL_RES *dbinfo;
 
2531
    DRIZZLE_ROW row;
 
2532
    DRIZZLE_RES *dbinfo;
2600
2533
 
2601
2534
    snprintf(qbuf, sizeof(qbuf),
2602
2535
             "SHOW CREATE DATABASE IF NOT EXISTS %s",
2603
2536
             qdatabase);
2604
2537
 
2605
 
    if (mysql_query(mysql, qbuf) || !(dbinfo = mysql_store_result(mysql)))
 
2538
    if (drizzle_query(drizzle, qbuf) || !(dbinfo = drizzle_store_result(drizzle)))
2606
2539
    {
2607
2540
      /* Old server version, dump generic CREATE DATABASE */
2608
2541
      if (opt_drop_database)
2619
2552
        fprintf(md_result_file,
2620
2553
                "\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2621
2554
                qdatabase);
2622
 
      row = mysql_fetch_row(dbinfo);
 
2555
      row = drizzle_fetch_row(dbinfo);
2623
2556
      if (row[1])
2624
2557
      {
2625
2558
        fprintf(md_result_file,"\n%s;\n",row[1]);
2626
2559
      }
2627
 
      mysql_free_result(dbinfo);
 
2560
      drizzle_free_result(dbinfo);
2628
2561
    }
2629
2562
  }
2630
2563
  return(0);
2633
2566
 
2634
2567
static int init_dumping(char *database, int init_func(char*))
2635
2568
{
2636
 
  if (mysql_get_server_version(mysql) >= 50003 &&
2637
 
      !my_strcasecmp(&my_charset_latin1, database, "information_schema"))
 
2569
  if (drizzle_get_server_version(drizzle) >= 50003 &&
 
2570
      !my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
2638
2571
    return 1;
2639
2572
 
2640
 
  if (mysql_select_db(mysql, database))
 
2573
  if (drizzle_select_db(drizzle, database))
2641
2574
  {
2642
 
    DB_error(mysql, "when selecting the database");
 
2575
    DB_error(drizzle, "when selecting the database");
2643
2576
    return 1;                   /* If --force */
2644
2577
  }
2645
2578
  if (!path && !opt_xml)
2665
2598
    }
2666
2599
  }
2667
2600
  if (extended_insert)
2668
 
    init_dynamic_string_checked(&extended_row, "", 1024, 1024);
 
2601
    extended_row.clear();
2669
2602
  return 0;
2670
2603
} /* init_dumping */
2671
2604
 
2672
2605
 
2673
2606
/* Return 1 if we should copy the table */
2674
2607
 
2675
 
static bool include_table(const uchar *hash_key, size_t len)
 
2608
static bool include_table(const unsigned char *hash_key, size_t len)
2676
2609
{
2677
2610
  return !hash_search(&ignore_table, hash_key, len);
2678
2611
}
2685
2618
  char table_buff[NAME_LEN*2+3];
2686
2619
  char hash_key[2*NAME_LEN+2];  /* "db.tablename" */
2687
2620
  char *afterdot;
2688
 
  int using_mysql_db= my_strcasecmp(&my_charset_latin1, database, "mysql");
2689
 
 
2690
 
 
2691
 
  afterdot= strmov(hash_key, database);
 
2621
  int using_mysql_db= my_strcasecmp(&my_charset_utf8_general_ci, database, "mysql");
 
2622
 
 
2623
 
 
2624
  afterdot= my_stpcpy(hash_key, database);
2692
2625
  *afterdot++= '.';
2693
2626
 
2694
2627
  if (init_dumping(database, init_dumping_tables))
2695
2628
    return(1);
2696
2629
  if (opt_xml)
2697
 
    print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
 
2630
    print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NULL);
2698
2631
  if (lock_tables)
2699
2632
  {
2700
 
    DYNAMIC_STRING query;
2701
 
    init_dynamic_string_checked(&query, "LOCK TABLES ", 256, 1024);
 
2633
    string query;
 
2634
    query= "LOCK TABLES ";
2702
2635
    for (numrows= 0 ; (table= getTableName(1)) ; )
2703
2636
    {
2704
 
      char *end= strmov(afterdot, table);
2705
 
      if (include_table((uchar*) hash_key,end - hash_key))
 
2637
      char *end= my_stpcpy(afterdot, table);
 
2638
      if (include_table((unsigned char*) hash_key,end - hash_key))
2706
2639
      {
2707
2640
        numrows++;
2708
 
        dynstr_append_checked(&query, quote_name(table, table_buff, 1));
2709
 
        dynstr_append_checked(&query, " READ /*!32311 LOCAL */,");
 
2641
        query.append( quote_name(table, table_buff, 1));
 
2642
        query.append( " READ /*!32311 LOCAL */,");
2710
2643
      }
2711
2644
    }
2712
 
    if (numrows && mysql_real_query(mysql, query.str, query.length-1))
2713
 
      DB_error(mysql, "when using LOCK TABLES");
 
2645
    if (numrows && drizzle_real_query(drizzle, query.c_str(), query.length()-1))
 
2646
      DB_error(drizzle, "when using LOCK TABLES");
2714
2647
            /* We shall continue here, if --force was given */
2715
 
    dynstr_free(&query);
 
2648
    query.clear();
2716
2649
  }
2717
2650
  if (flush_logs)
2718
2651
  {
2719
 
    if (mysql_refresh(mysql, REFRESH_LOG))
2720
 
      DB_error(mysql, "when doing refresh");
 
2652
    if (drizzle_refresh(drizzle, REFRESH_LOG))
 
2653
      DB_error(drizzle, "when doing refresh");
2721
2654
           /* We shall continue here, if --force was given */
2722
2655
  }
2723
2656
  while ((table= getTableName(0)))
2724
2657
  {
2725
 
    char *end= strmov(afterdot, table);
2726
 
    if (include_table((uchar*) hash_key, end - hash_key))
 
2658
    char *end= my_stpcpy(afterdot, table);
 
2659
    if (include_table((unsigned char*) hash_key, end - hash_key))
2727
2660
    {
2728
2661
      dump_table(table,database);
2729
 
      my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
 
2662
      free(order_by);
2730
2663
      order_by= 0;
2731
2664
    }
2732
2665
  }
2736
2669
    check_io(md_result_file);
2737
2670
  }
2738
2671
  if (lock_tables)
2739
 
    VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
 
2672
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2740
2673
  if (flush_privileges && using_mysql_db == 0)
2741
2674
  {
2742
2675
    fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
2760
2693
static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root)
2761
2694
{
2762
2695
  char *name= 0;
2763
 
  MYSQL_RES  *table_res;
2764
 
  MYSQL_ROW  row;
 
2696
  DRIZZLE_RES  *table_res;
 
2697
  DRIZZLE_ROW  row;
2765
2698
  char query[50 + 2*NAME_LEN];
2766
2699
  char show_name_buff[FN_REFLEN];
2767
2700
 
2771
2704
  snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2772
2705
           quote_for_like(old_table_name, show_name_buff));
2773
2706
 
2774
 
  if (mysql_query_with_error_report(mysql, 0, query))
2775
 
    return NullS;
 
2707
  if (drizzle_query_with_error_report(drizzle, 0, query))
 
2708
    return NULL;
2776
2709
 
2777
 
  if ((table_res= mysql_store_result(mysql)))
 
2710
  if ((table_res= drizzle_store_result(drizzle)))
2778
2711
  {
2779
 
    uint64_t num_rows= mysql_num_rows(table_res);
 
2712
    uint64_t num_rows= drizzle_num_rows(table_res);
2780
2713
    if (num_rows > 0)
2781
2714
    {
2782
2715
      uint32_t *lengths;
2784
2717
        Return first row
2785
2718
        TODO: Return all matching rows
2786
2719
      */
2787
 
      row= mysql_fetch_row(table_res);
2788
 
      lengths= mysql_fetch_lengths(table_res);
 
2720
      row= drizzle_fetch_row(table_res);
 
2721
      lengths= drizzle_fetch_lengths(table_res);
2789
2722
      name= strmake_root(root, row[0], lengths[0]);
2790
2723
    }
2791
 
    mysql_free_result(table_res);
 
2724
    drizzle_free_result(table_res);
2792
2725
  }
2793
2726
  return(name);
2794
2727
}
2797
2730
static int dump_selected_tables(char *db, char **table_names, int tables)
2798
2731
{
2799
2732
  char table_buff[NAME_LEN*2+3];
2800
 
  DYNAMIC_STRING lock_tables_query;
 
2733
  string lock_tables_query;
2801
2734
  MEM_ROOT root;
2802
2735
  char **dump_tables, **pos, **end;
2803
2736
 
2809
2742
  if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
2810
2743
     die(EX_EOM, "alloc_root failure.");
2811
2744
 
2812
 
  init_dynamic_string_checked(&lock_tables_query, "LOCK TABLES ", 256, 1024);
 
2745
  lock_tables_query= "LOCK TABLES ";
2813
2746
  for (; tables > 0 ; tables-- , table_names++)
2814
2747
  {
2815
2748
    /* the table name passed on commandline may be wrong case */
2818
2751
      /* Add found table name to lock_tables_query */
2819
2752
      if (lock_tables)
2820
2753
      {
2821
 
        dynstr_append_checked(&lock_tables_query, quote_name(*pos, table_buff, 1));
2822
 
        dynstr_append_checked(&lock_tables_query, " READ /*!32311 LOCAL */,");
 
2754
        lock_tables_query.append( quote_name(*pos, table_buff, 1));
 
2755
        lock_tables_query.append( " READ /*!32311 LOCAL */,");
2823
2756
      }
2824
2757
      pos++;
2825
2758
    }
2827
2760
    {
2828
2761
      if (!ignore_errors)
2829
2762
      {
2830
 
        dynstr_free(&lock_tables_query);
2831
2763
        free_root(&root, MYF(0));
2832
2764
      }
2833
2765
      maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names);
2838
2770
 
2839
2771
  if (lock_tables)
2840
2772
  {
2841
 
    if (mysql_real_query(mysql, lock_tables_query.str,
2842
 
                         lock_tables_query.length-1))
 
2773
    if (drizzle_real_query(drizzle, lock_tables_query.c_str(),
 
2774
                         lock_tables_query.length()-1))
2843
2775
    {
2844
2776
      if (!ignore_errors)
2845
2777
      {
2846
 
        dynstr_free(&lock_tables_query);
2847
2778
        free_root(&root, MYF(0));
2848
2779
      }
2849
 
      DB_error(mysql, "when doing LOCK TABLES");
 
2780
      DB_error(drizzle, "when doing LOCK TABLES");
2850
2781
       /* We shall countinue here, if --force was given */
2851
2782
    }
2852
2783
  }
2853
 
  dynstr_free(&lock_tables_query);
2854
2784
  if (flush_logs)
2855
2785
  {
2856
 
    if (mysql_refresh(mysql, REFRESH_LOG))
 
2786
    if (drizzle_refresh(drizzle, REFRESH_LOG))
2857
2787
    {
2858
2788
      if (!ignore_errors)
2859
2789
        free_root(&root, MYF(0));
2860
 
      DB_error(mysql, "when doing refresh");
 
2790
      DB_error(drizzle, "when doing refresh");
2861
2791
    }
2862
2792
     /* We shall countinue here, if --force was given */
2863
2793
  }
2864
2794
  if (opt_xml)
2865
 
    print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS);
 
2795
    print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
2866
2796
 
2867
2797
  /* Dump each selected table */
2868
2798
  for (pos= dump_tables; pos < end; pos++)
2869
2799
    dump_table(*pos, db);
2870
2800
 
2871
2801
  free_root(&root, MYF(0));
2872
 
  my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
 
2802
  free(order_by);
2873
2803
  order_by= 0;
2874
2804
  if (opt_xml)
2875
2805
  {
2877
2807
    check_io(md_result_file);
2878
2808
  }
2879
2809
  if (lock_tables)
2880
 
    VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
 
2810
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2881
2811
  return(0);
2882
2812
} /* dump_selected_tables */
2883
2813
 
2884
2814
 
2885
 
static int do_show_master_status(MYSQL *mysql_con)
 
2815
static int do_show_master_status(DRIZZLE *drizzle_con)
2886
2816
{
2887
 
  MYSQL_ROW row;
2888
 
  MYSQL_RES *master;
 
2817
  DRIZZLE_ROW row;
 
2818
  DRIZZLE_RES *master;
2889
2819
  const char *comment_prefix=
2890
 
    (opt_master_data == MYSQL_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2891
 
  if (mysql_query_with_error_report(mysql_con, &master, "SHOW MASTER STATUS"))
 
2820
    (opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
 
2821
  if (drizzle_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
2892
2822
  {
2893
2823
    return 1;
2894
2824
  }
2895
2825
  else
2896
2826
  {
2897
 
    row= mysql_fetch_row(master);
 
2827
    row= drizzle_fetch_row(master);
2898
2828
    if (row && row[0] && row[1])
2899
2829
    {
2900
2830
      /* SHOW MASTER STATUS reports file and position */
2912
2842
      /* SHOW MASTER STATUS reports nothing and --force is not enabled */
2913
2843
      my_printf_error(0, "Error: Binlogging on server not active",
2914
2844
                      MYF(0));
2915
 
      mysql_free_result(master);
2916
 
      maybe_exit(EX_MYSQLERR);
 
2845
      drizzle_free_result(master);
 
2846
      maybe_exit(EX_DRIZZLEERR);
2917
2847
      return 1;
2918
2848
    }
2919
 
    mysql_free_result(master);
 
2849
    drizzle_free_result(master);
2920
2850
  }
2921
2851
  return 0;
2922
2852
}
2923
2853
 
2924
 
static int do_stop_slave_sql(MYSQL *mysql_con)
 
2854
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
2925
2855
{
2926
 
  MYSQL_RES *slave;
 
2856
  DRIZZLE_RES *slave;
2927
2857
  /* We need to check if the slave sql is running in the first place */
2928
 
  if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
 
2858
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2929
2859
    return(1);
2930
2860
  else
2931
2861
  {
2932
 
    MYSQL_ROW row= mysql_fetch_row(slave);
 
2862
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
2933
2863
    if (row && row[11])
2934
2864
    {
2935
2865
      /* if SLAVE SQL is not running, we don't stop it */
2936
2866
      if (!strcmp(row[11],"No"))
2937
2867
      {
2938
 
        mysql_free_result(slave);
 
2868
        drizzle_free_result(slave);
2939
2869
        /* Silently assume that they don't have the slave running */
2940
2870
        return(0);
2941
2871
      }
2942
2872
    }
2943
2873
  }
2944
 
  mysql_free_result(slave);
 
2874
  drizzle_free_result(slave);
2945
2875
 
2946
2876
  /* now, stop slave if running */
2947
 
  if (mysql_query_with_error_report(mysql_con, 0, "STOP SLAVE SQL_THREAD"))
 
2877
  if (drizzle_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
2948
2878
    return(1);
2949
2879
 
2950
2880
  return(0);
2968
2898
  return(0);
2969
2899
}
2970
2900
 
2971
 
static int do_show_slave_status(MYSQL *mysql_con)
 
2901
static int do_show_slave_status(DRIZZLE *drizzle_con)
2972
2902
{
2973
 
  MYSQL_RES *slave;
 
2903
  DRIZZLE_RES *slave;
2974
2904
  const char *comment_prefix=
2975
 
    (opt_slave_data == MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2976
 
  if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
 
2905
    (opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
 
2906
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2977
2907
  {
2978
2908
    if (!ignore_errors)
2979
2909
    {
2984
2914
  }
2985
2915
  else
2986
2916
  {
2987
 
    MYSQL_ROW row= mysql_fetch_row(slave);
 
2917
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
2988
2918
    if (row && row[9] && row[21])
2989
2919
    {
2990
2920
      /* SHOW MASTER STATUS reports file and position */
3007
2937
 
3008
2938
      check_io(md_result_file);
3009
2939
    }
3010
 
    mysql_free_result(slave);
 
2940
    drizzle_free_result(slave);
3011
2941
  }
3012
2942
  return 0;
3013
2943
}
3014
2944
 
3015
 
static int do_start_slave_sql(MYSQL *mysql_con)
 
2945
static int do_start_slave_sql(DRIZZLE *drizzle_con)
3016
2946
{
3017
 
  MYSQL_RES *slave;
 
2947
  DRIZZLE_RES *slave;
3018
2948
  /* We need to check if the slave sql is stopped in the first place */
3019
 
  if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
 
2949
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
3020
2950
    return(1);
3021
2951
  else
3022
2952
  {
3023
 
    MYSQL_ROW row= mysql_fetch_row(slave);
 
2953
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
3024
2954
    if (row && row[11])
3025
2955
    {
3026
2956
      /* if SLAVE SQL is not running, we don't start it */
3027
2957
      if (!strcmp(row[11],"Yes"))
3028
2958
      {
3029
 
        mysql_free_result(slave);
 
2959
        drizzle_free_result(slave);
3030
2960
        /* Silently assume that they don't have the slave running */
3031
2961
        return(0);
3032
2962
      }
3033
2963
    }
3034
2964
  }
3035
 
  mysql_free_result(slave);
 
2965
  drizzle_free_result(slave);
3036
2966
 
3037
2967
  /* now, start slave if stopped */
3038
 
  if (mysql_query_with_error_report(mysql_con, 0, "START SLAVE"))
 
2968
  if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
3039
2969
  {
3040
2970
    my_printf_error(0, "Error: Unable to start slave", MYF(0));
3041
2971
    return 1;
3045
2975
 
3046
2976
 
3047
2977
 
3048
 
static int do_flush_tables_read_lock(MYSQL *mysql_con)
 
2978
static int do_flush_tables_read_lock(DRIZZLE *drizzle_con)
3049
2979
{
3050
2980
  /*
3051
2981
    We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
3056
2986
    update starts between the two FLUSHes, we have that bad stall.
3057
2987
  */
3058
2988
  return
3059
 
    ( mysql_query_with_error_report(mysql_con, 0, "FLUSH TABLES") ||
3060
 
      mysql_query_with_error_report(mysql_con, 0,
 
2989
    ( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
 
2990
      drizzle_query_with_error_report(drizzle_con, 0,
3061
2991
                                    "FLUSH TABLES WITH READ LOCK") );
3062
2992
}
3063
2993
 
3064
2994
 
3065
 
static int do_unlock_tables(MYSQL *mysql_con)
 
2995
static int do_unlock_tables(DRIZZLE *drizzle_con)
3066
2996
{
3067
 
  return mysql_query_with_error_report(mysql_con, 0, "UNLOCK TABLES");
 
2997
  return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
3068
2998
}
3069
2999
 
3070
 
static int get_bin_log_name(MYSQL *mysql_con,
 
3000
static int get_bin_log_name(DRIZZLE *drizzle_con,
3071
3001
                            char* buff_log_name, uint buff_len)
3072
3002
{
3073
 
  MYSQL_RES *res;
3074
 
  MYSQL_ROW row;
 
3003
  DRIZZLE_RES *res;
 
3004
  DRIZZLE_ROW row;
3075
3005
 
3076
 
  if (mysql_query(mysql_con, "SHOW MASTER STATUS") ||
3077
 
      !(res= mysql_store_result(mysql)))
 
3006
  if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
 
3007
      !(res= drizzle_store_result(drizzle)))
3078
3008
    return 1;
3079
3009
 
3080
 
  if (!(row= mysql_fetch_row(res)))
 
3010
  if (!(row= drizzle_fetch_row(res)))
3081
3011
  {
3082
 
    mysql_free_result(res);
 
3012
    drizzle_free_result(res);
3083
3013
    return 1;
3084
3014
  }
3085
3015
  /*
3088
3018
  */
3089
3019
  strmake(buff_log_name, row[0], buff_len - 1);
3090
3020
 
3091
 
  mysql_free_result(res);
 
3021
  drizzle_free_result(res);
3092
3022
  return 0;
3093
3023
}
3094
3024
 
3095
 
static int purge_bin_logs_to(MYSQL *mysql_con, char* log_name)
 
3025
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
3096
3026
{
3097
 
  DYNAMIC_STRING str;
3098
3027
  int err;
3099
 
  init_dynamic_string_checked(&str, "PURGE BINARY LOGS TO '", 1024, 1024);
3100
 
  dynstr_append_checked(&str, log_name);
3101
 
  dynstr_append_checked(&str, "'");
3102
 
  err = mysql_query_with_error_report(mysql_con, 0, str.str);
3103
 
  dynstr_free(&str);
 
3028
  string str= "PURGE BINARY LOGS TO '";
 
3029
  str.append(log_name);
 
3030
  str.append("'");
 
3031
  err = drizzle_query_with_error_report(drizzle_con, 0, str.c_str());
3104
3032
  return err;
3105
3033
}
3106
3034
 
3107
3035
 
3108
 
static int start_transaction(MYSQL *mysql_con)
 
3036
static int start_transaction(DRIZZLE *drizzle_con)
3109
3037
{
3110
3038
  /*
3111
3039
    We use BEGIN for old servers. --single-transaction --master-data will fail
3116
3044
    need the REPEATABLE READ level (not anything lower, for example READ
3117
3045
    COMMITTED would give one new consistent read per dumped table).
3118
3046
  */
3119
 
  if ((mysql_get_server_version(mysql_con) < 40100) && opt_master_data)
 
3047
  if ((drizzle_get_server_version(drizzle_con) < 40100) && opt_master_data)
3120
3048
  {
3121
3049
    fprintf(stderr, "-- %s: the combination of --single-transaction and "
3122
 
            "--master-data requires a MySQL server version of at least 4.1 "
 
3050
            "--master-data requires a DRIZZLE server version of at least 4.1 "
3123
3051
            "(current server's version is %s). %s\n",
3124
3052
            ignore_errors ? "Warning" : "Error",
3125
 
            mysql_con->server_version ? mysql_con->server_version : "unknown",
 
3053
            drizzle_con->server_version ? drizzle_con->server_version : "unknown",
3126
3054
            ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3127
3055
    if (!ignore_errors)
3128
 
      exit(EX_MYSQLERR);
 
3056
      exit(EX_DRIZZLEERR);
3129
3057
  }
3130
3058
 
3131
 
  return (mysql_query_with_error_report(mysql_con, 0,
 
3059
  return (drizzle_query_with_error_report(drizzle_con, 0,
3132
3060
                                        "SET SESSION TRANSACTION ISOLATION "
3133
3061
                                        "LEVEL REPEATABLE READ") ||
3134
 
          mysql_query_with_error_report(mysql_con, 0,
 
3062
          drizzle_query_with_error_report(drizzle_con, 0,
3135
3063
                                        "START TRANSACTION "
3136
3064
                                        "/*!40100 WITH CONSISTENT SNAPSHOT */"));
3137
3065
}
3138
3066
 
3139
3067
 
3140
 
static ulong find_set(TYPELIB *lib, const char *x, uint length,
 
3068
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
3141
3069
                      char **err_pos, uint *err_len)
3142
3070
{
3143
3071
  const char *end= x + length;
3144
 
  ulong found= 0;
 
3072
  uint32_t found= 0;
3145
3073
  uint find;
3146
3074
  char buff[255];
3147
3075
 
3156
3084
    for (;;)
3157
3085
    {
3158
3086
      const char *pos= start;
3159
 
      uint var_len;
 
3087
      uint32_t var_len;
3160
3088
 
3161
3089
      for (; pos != end && *pos != ','; pos++) ;
3162
 
      var_len= (uint) (pos - start);
3163
 
      strmake(buff, start, min(sizeof(buff), var_len));
 
3090
      var_len= (uint32_t) (pos - start);
 
3091
      strmake(buff, start, min((uint32_t)sizeof(buff), var_len));
3164
3092
      find= find_type(buff, lib, var_len);
3165
3093
      if (!find)
3166
3094
      {
3179
3107
 
3180
3108
 
3181
3109
/* Print a value with a prefix on file */
3182
 
static void print_value(FILE *file, MYSQL_RES  *result, MYSQL_ROW row,
 
3110
static void print_value(FILE *file, DRIZZLE_RES  *result, DRIZZLE_ROW row,
3183
3111
                        const char *prefix, const char *name,
3184
3112
                        int string_value)
3185
3113
{
3186
 
  MYSQL_FIELD   *field;
3187
 
  mysql_field_seek(result, 0);
 
3114
  DRIZZLE_FIELD   *field;
 
3115
  drizzle_field_seek(result, 0);
3188
3116
 
3189
 
  for ( ; (field= mysql_fetch_field(result)) ; row++)
 
3117
  for ( ; (field= drizzle_fetch_field(result)) ; row++)
3190
3118
  {
3191
3119
    if (!strcmp(field->name,name))
3192
3120
    {
3224
3152
    table_type                  Type of table
3225
3153
 
3226
3154
  GLOBAL VARIABLES
3227
 
    mysql                       MySQL connection
 
3155
    drizzle                       Drizzle connection
3228
3156
    verbose                     Write warning messages
3229
3157
 
3230
3158
  RETURN
3235
3163
{
3236
3164
  char result= IGNORE_NONE;
3237
3165
  char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
3238
 
  MYSQL_RES *res= NULL;
3239
 
  MYSQL_ROW row;
 
3166
  DRIZZLE_RES *res= NULL;
 
3167
  DRIZZLE_ROW row;
3240
3168
 
3241
3169
 
3242
3170
  /* Check memory for quote_for_like() */
3243
3171
  assert(2*sizeof(table_name) < sizeof(show_name_buff));
3244
3172
  snprintf(buff, sizeof(buff), "show table status like %s",
3245
3173
           quote_for_like(table_name, show_name_buff));
3246
 
  if (mysql_query_with_error_report(mysql, &res, buff))
 
3174
  if (drizzle_query_with_error_report(drizzle, &res, buff))
3247
3175
  {
3248
 
    if (mysql_errno(mysql) != ER_PARSE_ERROR)
3249
 
    {                                   /* If old MySQL version */
 
3176
    if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
 
3177
    {                                   /* If old DRIZZLE version */
3250
3178
      verbose_msg("-- Warning: Couldn't get status information for "
3251
 
                  "table %s (%s)\n", table_name, mysql_error(mysql));
 
3179
                  "table %s (%s)\n", table_name, drizzle_error(drizzle));
3252
3180
      return(result);                       /* assume table is ok */
3253
3181
    }
3254
3182
  }
3255
 
  if (!(row= mysql_fetch_row(res)))
 
3183
  if (!(row= drizzle_fetch_row(res)))
3256
3184
  {
3257
3185
    fprintf(stderr,
3258
3186
            "Error: Couldn't read status information for table %s (%s)\n",
3259
 
            table_name, mysql_error(mysql));
3260
 
    mysql_free_result(res);
 
3187
            table_name, drizzle_error(drizzle));
 
3188
    drizzle_free_result(res);
3261
3189
    return(result);                         /* assume table is ok */
3262
3190
  }
3263
3191
  if (!(row[1]))
3285
3213
      If these two types, we do want to skip dumping the table
3286
3214
    */
3287
3215
    if (!opt_no_data &&
3288
 
        (!my_strcasecmp(&my_charset_latin1, table_type, "MRG_MyISAM") ||
 
3216
        (!my_strcasecmp(&my_charset_utf8_general_ci, table_type, "MRG_MyISAM") ||
3289
3217
         !strcmp(table_type,"MRG_ISAM")))
3290
3218
      result= IGNORE_DATA;
3291
3219
  }
3292
 
  mysql_free_result(res);
 
3220
  drizzle_free_result(res);
3293
3221
  return(result);
3294
3222
}
3295
3223
 
3314
3242
 
3315
3243
static char *primary_key_fields(const char *table_name)
3316
3244
{
3317
 
  MYSQL_RES  *res= NULL;
3318
 
  MYSQL_ROW  row;
 
3245
  DRIZZLE_RES  *res= NULL;
 
3246
  DRIZZLE_ROW  row;
3319
3247
  /* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3320
3248
  char show_keys_buff[15 + NAME_LEN * 2 + 3];
3321
3249
  uint result_length= 0;
3325
3253
 
3326
3254
  snprintf(show_keys_buff, sizeof(show_keys_buff),
3327
3255
           "SHOW KEYS FROM %s", table_name);
3328
 
  if (mysql_query(mysql, show_keys_buff) ||
3329
 
      !(res= mysql_store_result(mysql)))
 
3256
  if (drizzle_query(drizzle, show_keys_buff) ||
 
3257
      !(res= drizzle_store_result(drizzle)))
3330
3258
  {
3331
3259
    fprintf(stderr, "Warning: Couldn't read keys from table %s;"
3332
3260
            " records are NOT sorted (%s)\n",
3333
 
            table_name, mysql_error(mysql));
 
3261
            table_name, drizzle_error(drizzle));
3334
3262
    /* Don't exit, because it's better to print out unsorted records */
3335
3263
    goto cleanup;
3336
3264
  }
3341
3269
   * row, and UNIQUE keys come before others.  So we only need to check
3342
3270
   * the first key, not all keys.
3343
3271
   */
3344
 
  if ((row= mysql_fetch_row(res)) && atoi(row[1]) == 0)
 
3272
  if ((row= drizzle_fetch_row(res)) && atoi(row[1]) == 0)
3345
3273
  {
3346
3274
    /* Key is unique */
3347
3275
    do
3348
3276
    {
3349
3277
      quoted_field= quote_name(row[4], buff, 0);
3350
3278
      result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3351
 
    } while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1);
 
3279
    } while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1);
3352
3280
  }
3353
3281
 
3354
3282
  /* Build the ORDER BY clause result */
3356
3284
  {
3357
3285
    char *end;
3358
3286
    /* result (terminating \0 is already in result_length) */
3359
 
    result= my_malloc(result_length + 10, MYF(MY_WME));
 
3287
    result= (char *)my_malloc(result_length + 10, MYF(MY_WME));
3360
3288
    if (!result)
3361
3289
    {
3362
3290
      fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n");
3363
3291
      goto cleanup;
3364
3292
    }
3365
 
    mysql_data_seek(res, 0);
3366
 
    row= mysql_fetch_row(res);
 
3293
    drizzle_data_seek(res, 0);
 
3294
    row= drizzle_fetch_row(res);
3367
3295
    quoted_field= quote_name(row[4], buff, 0);
3368
 
    end= strmov(result, quoted_field);
3369
 
    while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1)
 
3296
    end= my_stpcpy(result, quoted_field);
 
3297
    while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1)
3370
3298
    {
3371
3299
      quoted_field= quote_name(row[4], buff, 0);
3372
 
      end= strxmov(end, ",", quoted_field, NullS);
 
3300
      end= strxmov(end, ",", quoted_field, NULL);
3373
3301
    }
3374
3302
  }
3375
3303
 
3376
3304
cleanup:
3377
3305
  if (res)
3378
 
    mysql_free_result(res);
 
3306
    drizzle_free_result(res);
3379
3307
 
3380
3308
  return result;
3381
3309
}
3382
3310
 
3383
 
/*
3384
 
  The following functions are wrappers for the dynamic string functions
3385
 
  and if they fail, the wrappers will terminate the current process.
3386
 
*/
3387
 
 
3388
 
#define DYNAMIC_STR_ERROR_MSG "Couldn't perform DYNAMIC_STRING operation"
3389
 
 
3390
 
static void init_dynamic_string_checked(DYNAMIC_STRING *str, const char *init_str,
3391
 
                            uint init_alloc, uint alloc_increment)
3392
 
{
3393
 
  if (init_dynamic_string(str, init_str, init_alloc, alloc_increment))
3394
 
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3395
 
}
3396
 
 
3397
 
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src)
3398
 
{
3399
 
  if (dynstr_append(dest, src))
3400
 
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3401
 
}
3402
 
 
3403
 
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str)
3404
 
{
3405
 
  if (dynstr_set(str, init_str))
3406
 
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3407
 
}
3408
 
 
3409
 
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
3410
 
                          uint length)
3411
 
{
3412
 
  if (dynstr_append_mem(str, append, length))
3413
 
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3414
 
}
3415
 
 
3416
 
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size)
3417
 
{
3418
 
  if (dynstr_realloc(str, additional_size))
3419
 
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
3420
 
}
3421
 
 
3422
3311
 
3423
3312
int main(int argc, char **argv)
3424
3313
{
3427
3316
  MY_INIT("mysqldump");
3428
3317
 
3429
3318
  compatible_mode_normal_str[0]= 0;
3430
 
  default_charset= (char *)mysql_universal_client_charset;
3431
 
  bzero((char*) &ignore_table, sizeof(ignore_table));
 
3319
  default_charset= (char *)drizzle_universal_client_charset;
 
3320
  memset(&ignore_table, 0, sizeof(ignore_table));
3432
3321
 
3433
3322
  exit_code= get_options(&argc, &argv);
3434
3323
  if (exit_code)
3442
3331
    if(!(stderror_file= freopen(log_error_file, "a+", stderr)))
3443
3332
    {
3444
3333
      free_resources();
3445
 
      exit(EX_MYSQLERR);
 
3334
      exit(EX_DRIZZLEERR);
3446
3335
    }
3447
3336
  }
3448
3337
 
3449
3338
  if (connect_to_db(current_host, current_user, opt_password))
3450
3339
  {
3451
3340
    free_resources();
3452
 
    exit(EX_MYSQLERR);
 
3341
    exit(EX_DRIZZLEERR);
3453
3342
  }
3454
3343
  if (!path)
3455
3344
    write_header(md_result_file, *argv);
3456
3345
 
3457
 
  if (opt_slave_data && do_stop_slave_sql(mysql))
 
3346
  if (opt_slave_data && do_stop_slave_sql(drizzle))
3458
3347
    goto err;
3459
3348
 
3460
3349
  if ((opt_lock_all_tables || opt_master_data) &&
3461
 
      do_flush_tables_read_lock(mysql))
 
3350
      do_flush_tables_read_lock(drizzle))
3462
3351
    goto err;
3463
 
  if (opt_single_transaction && start_transaction(mysql))
 
3352
  if (opt_single_transaction && start_transaction(drizzle))
3464
3353
      goto err;
3465
3354
  if (opt_delete_master_logs)
3466
3355
  {
3467
 
    if (mysql_refresh(mysql, REFRESH_LOG) ||
3468
 
        get_bin_log_name(mysql, bin_log_name, sizeof(bin_log_name)))
 
3356
    if (drizzle_refresh(drizzle, REFRESH_LOG) ||
 
3357
        get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
3469
3358
      goto err;
3470
3359
    flush_logs= 0;
3471
3360
  }
3472
3361
  if (opt_lock_all_tables || opt_master_data)
3473
3362
  {
3474
 
    if (flush_logs && mysql_refresh(mysql, REFRESH_LOG))
 
3363
    if (flush_logs && drizzle_refresh(drizzle, REFRESH_LOG))
3475
3364
      goto err;
3476
3365
    flush_logs= 0; /* not anymore; that would not be sensible */
3477
3366
  }
3478
3367
  /* Add 'STOP SLAVE to beginning of dump */
3479
3368
  if (opt_slave_apply && add_stop_slave())
3480
3369
    goto err;
3481
 
  if (opt_master_data && do_show_master_status(mysql))
3482
 
    goto err;
3483
 
  if (opt_slave_data && do_show_slave_status(mysql))
3484
 
    goto err;
3485
 
  if (opt_single_transaction && do_unlock_tables(mysql)) /* unlock but no commit! */
 
3370
  if (opt_master_data && do_show_master_status(drizzle))
 
3371
    goto err;
 
3372
  if (opt_slave_data && do_show_slave_status(drizzle))
 
3373
    goto err;
 
3374
  if (opt_single_transaction && do_unlock_tables(drizzle)) /* unlock but no commit! */
3486
3375
    goto err;
3487
3376
 
3488
3377
  if (opt_alldbs)
3500
3389
  }
3501
3390
 
3502
3391
  /* if --dump-slave , start the slave sql thread */
3503
 
  if (opt_slave_data && do_start_slave_sql(mysql))
 
3392
  if (opt_slave_data && do_start_slave_sql(drizzle))
3504
3393
    goto err;
3505
3394
 
3506
3395
  /* add 'START SLAVE' to end of dump */
3511
3400
  if (md_result_file && fflush(md_result_file))
3512
3401
  {
3513
3402
    if (!first_error)
3514
 
      first_error= EX_MYSQLERR;
 
3403
      first_error= EX_DRIZZLEERR;
3515
3404
    goto err;
3516
3405
  }
3517
3406
  /* everything successful, purge the old logs files */
3518
 
  if (opt_delete_master_logs && purge_bin_logs_to(mysql, bin_log_name))
 
3407
  if (opt_delete_master_logs && purge_bin_logs_to(drizzle, bin_log_name))
3519
3408
    goto err;
3520
3409
 
3521
3410
  /*