~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysqldump.c

  • Committer: Brian Aker
  • Date: 2008-07-14 16:24:25 UTC
  • Revision ID: brian@tangent.org-20080714162425-juw3vw221gs9kysh
Cleanup around intptr_t

Show diffs side-by-side

added added

removed removed

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