~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-21 01:02:23 UTC
  • mto: (960.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: osullivan.padraig@gmail.com-20090321010223-j8cph7eeyt1u3xol
Fixed function object to ensure it correctly returns a boolean type since
memcmp returns an integer. Added some more comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
#define DUMP_VERSION "10.13"
28
28
 
29
 
#include "config.h"
 
29
#include "client_priv.h"
30
30
#include <string>
31
 
#include "client_priv.h"
32
31
 
33
32
#include <mysys/my_sys.h>
34
33
#include <mystrings/m_string.h>
35
34
#include <mystrings/m_ctype.h>
36
35
#include <mysys/hash.h>
37
36
#include <stdarg.h>
 
37
#include <algorithm>
 
38
 
 
39
#include <drizzled/gettext.h>
38
40
 
39
41
#include <drizzled/error.h>
40
42
 
47
49
#define EX_EOM 4
48
50
#define EX_EOF 5 /* ferror for output file was got */
49
51
#define EX_ILLEGAL_TABLE 6
 
52
#define EX_TABLE_STATUS 7
50
53
 
51
54
/* index into 'show fields from table' */
52
55
 
66
69
 
67
70
static void add_load_option(string &str, const char *option,
68
71
                            const char *option_value);
69
 
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
70
 
                      char **err_pos, uint *err_len);
 
72
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
 
73
                      char **err_pos, uint32_t *err_len);
71
74
 
72
75
static void field_escape(string &in, const char *from);
73
 
static bool  verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
74
 
                quick= 1, extended_insert= 1,
75
 
                lock_tables=1,ignore_errors=0,flush_logs=0,flush_privileges=0,
76
 
                opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
77
 
                opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0,
78
 
                opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0,
79
 
                opt_set_charset=0, opt_dump_date=1,
80
 
                opt_autocommit=0,opt_disable_keys=1,opt_xml=0,
81
 
                opt_delete_master_logs=0, tty_password=0,
82
 
                opt_single_transaction=0, opt_comments= 0, opt_compact= 0,
83
 
                opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0,
84
 
                opt_complete_insert= 0, opt_drop_database= 0,
85
 
                opt_replace_into= 0,
86
 
                opt_routines=0, opt_tz_utc=1,
87
 
                opt_slave_apply= 0, 
88
 
                opt_include_master_host_port= 0,
89
 
                opt_events= 0,
90
 
                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;
 
76
static bool  verbose= false, opt_no_create_info= false, opt_no_data= false,
 
77
                quick= true, extended_insert= true,
 
78
                lock_tables= true, ignore_errors= false, flush_logs= false,
 
79
                opt_drop= true, opt_keywords= false,
 
80
                opt_lock= true, opt_compress= false,
 
81
                opt_delayed= false, create_options= true, opt_quoted= false,
 
82
                opt_databases= false, opt_alldbs= false, opt_create_db= false,
 
83
                opt_lock_all_tables= false,
 
84
                opt_set_charset= false, opt_dump_date= true,
 
85
                opt_autocommit= false, opt_disable_keys= true, opt_xml= false,
 
86
                opt_delete_master_logs= false, tty_password= false,
 
87
                opt_single_transaction= false, opt_comments= false,
 
88
                opt_compact= false, opt_hex_blob= false, 
 
89
                opt_order_by_primary=false, opt_ignore= false,
 
90
                opt_complete_insert= false, opt_drop_database= false,
 
91
                opt_replace_into= false,
 
92
                opt_routines= false,
 
93
                opt_slave_apply= false,
 
94
                opt_include_master_host_port= false,
 
95
                opt_alltspcs= false;
 
96
static bool debug_info_flag= false, debug_check_flag= false;
 
97
static uint32_t opt_max_allowed_packet, opt_net_buffer_length, show_progress_size= 0;
 
98
static uint64_t total_rows= 0;
 
99
static DRIZZLE drizzleclient_connection, *drizzle= 0;
94
100
static string insert_pat;
95
 
static char  *opt_password=0,*current_user=0,
96
 
             *current_host=0,*path=0,*fields_terminated=0,
97
 
             *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
98
 
             *where=0, *order_by=0,
99
 
             *opt_compatible_mode_str= 0,
100
 
             *err_ptr= 0,
101
 
             *log_error_file= NULL;
102
 
static char **defaults_argv= 0;
 
101
static char  *opt_password= NULL, *current_user= NULL,
 
102
             *current_host= NULL, *path= NULL, *fields_terminated= NULL,
 
103
             *lines_terminated= NULL, *enclosed= NULL, *opt_enclosed= NULL,
 
104
             *escaped= NULL,
 
105
             *where= NULL, *order_by= NULL,
 
106
             *opt_compatible_mode_str= NULL,
 
107
             *err_ptr= NULL;
 
108
static char **defaults_argv= NULL;
103
109
static char compatible_mode_normal_str[255];
104
 
/* Server supports character_set_results session variable? */
105
 
static bool server_supports_switching_charsets= true;
106
110
static uint32_t opt_compatible_mode= 0;
107
111
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
108
112
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
109
113
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
110
114
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
111
 
static uint opt_drizzle_port= 0, opt_master_data;
112
 
static uint opt_slave_data;
113
 
static uint my_end_arg;
114
 
static int   first_error=0;
 
115
static uint32_t opt_drizzle_port= 0;
 
116
static uint32_t opt_master_data;
 
117
static uint32_t opt_slave_data;
 
118
static uint32_t my_end_arg;
 
119
static int first_error= 0;
115
120
static string extended_row;
116
121
FILE *md_result_file= 0;
117
 
FILE *stderror_file=0;
 
122
FILE *stderror_file= 0;
118
123
 
119
124
/*
120
125
  Constant for detection of default value of default_charset.
126
131
static char *default_charset;
127
132
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
128
133
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
129
 
/* have we seen any VIEWs during table scanning? */
130
 
bool seen_views= 0;
131
134
const char *compatible_mode_names[]=
132
135
{
133
136
  "MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
162
165
   "Dump all the tablespaces.",
163
166
   (char**) &opt_alltspcs, (char**) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
164
167
   0, 0},
165
 
  {"no-tablespaces", 'y',
166
 
   "Do not dump any tablespace information.",
167
 
   (char**) &opt_notspcs, (char**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
168
 
   0, 0},
169
168
  {"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
170
169
   (char**) &opt_drop_database, (char**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
171
170
   0},
182
181
   "Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
183
182
   (char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
184
183
   0, 0, 0, 0, 0, 0},
185
 
  {"character-sets-dir", OPT_CHARSETS_DIR,
186
 
   "Directory where character sets are.", (char**) &charsets_dir,
187
 
   (char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
188
184
  {"comments", 'i', "Write additional information.",
189
185
   (char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
190
186
   1, 0, 0, 0, 0, 0},
227
223
   (char**) &opt_delete_master_logs, (char**) &opt_delete_master_logs, 0,
228
224
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
229
225
  {"disable-keys", 'K',
230
 
   "'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output.", (char**) &opt_disable_keys,
 
226
   "'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.", (char**) &opt_disable_keys,
231
227
   (char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
232
228
  {"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
233
229
   "This causes the binary log position and filename of the master to be "
242
238
   "Option automatically turns --lock-tables off.",
243
239
   (char**) &opt_slave_data, (char**) &opt_slave_data, 0,
244
240
   GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
245
 
  {"events", 'E', "Dump events.",
246
 
     (char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
247
 
     NO_ARG, 0, 0, 0, 0, 0, 0},
248
241
  {"extended-insert", 'e',
249
242
   "Allows utilization of the new, much faster INSERT syntax.",
250
243
   (char**) &extended_insert, (char**) &extended_insert, 0, GET_BOOL, NO_ARG,
274
267
   "--lock-all-tables or --master-data with --flush-logs",
275
268
   (char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
276
269
   0, 0},
277
 
  {"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. ",
281
 
   (char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
282
 
   0, 0},
283
270
  {"force", 'f', "Continue even if we get an sql-error.",
284
271
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG,
285
272
   0, 0, 0, 0, 0, 0},
297
284
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
298
285
  {"include-master-host-port", OPT_DRIZZLEDUMP_INCLUDE_MASTER_HOST_PORT,
299
286
   "Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.",
300
 
   (char**) &opt_include_master_host_port, 
301
 
   (char**) &opt_include_master_host_port, 
 
287
   (char**) &opt_include_master_host_port,
 
288
   (char**) &opt_include_master_host_port,
302
289
   0, GET_BOOL, NO_ARG,
303
290
   0, 0, 0, 0, 0, 0},
304
291
  {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
314
301
   0, 0, 0, 0, 0, 0},
315
302
  {"lock-tables", 'l', "Lock all tables for read.", (char**) &lock_tables,
316
303
   (char**) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
317
 
  {"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.",
318
 
   (char**) &log_error_file, (char**) &log_error_file, 0, GET_STR,
319
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
320
304
  {"master-data", OPT_MASTER_DATA,
321
305
   "This causes the binary log position and filename to be appended to the "
322
306
   "output. If equal to 1, will print it as a CHANGE MASTER command; if equal"
331
315
   GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
332
316
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
333
317
    (char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
334
 
    GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
 
318
    GET_UINT32, REQUIRED_ARG, 24*1024*1024, 4096,
335
319
   (int64_t) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
336
320
  {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
337
321
    (char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0,
338
 
    GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
 
322
    GET_UINT32, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
339
323
   MALLOC_OVERHEAD-1024, 1024, 0},
340
324
  {"no-autocommit", OPT_AUTOCOMMIT,
341
325
   "Wrap tables with autocommit/commit statements.",
342
326
   (char**) &opt_autocommit, (char**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
343
327
   0, 0, 0, 0, 0, 0},
344
328
  {"no-create-db", 'n',
345
 
   "'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
 
329
   "'CREATE DATABASE IF NOT EXISTS db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
346
330
   (char**) &opt_create_db, (char**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
347
331
   0, 0, 0, 0},
348
332
  {"no-create-info", 't', "Don't write table creation info.",
359
343
  {"order-by-primary", OPT_ORDER_BY_PRIMARY,
360
344
   "Sorts each table's rows by primary key, or first unique key, if such a key exists.  Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer.",
361
345
   (char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
362
 
  {"password", 'p',
 
346
  {"password", 'P',
363
347
   "Password to use when connecting to server. If password is not given it's solicited on the tty.",
364
348
   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,
367
 
   0},
 
349
  {"port", 'p', "Port number to use for connection.", 
 
350
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
368
351
  {"quick", 'q', "Don't buffer query, dump directly to stdout.",
369
352
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
370
353
  {"quote-names",'Q', "Quote table and column names with backticks (`).",
379
362
  {"routines", 'R', "Dump stored routines (functions and procedures).",
380
363
     (char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
381
364
     NO_ARG, 0, 0, 0, 0, 0, 0},
382
 
  {"set-charset", OPT_SET_CHARSET,
383
 
   "Add 'SET NAMES default_character_set' to the output.",
384
 
   (char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
385
 
   0, 0, 0, 0, 0},
386
 
  {"set-variable", 'O',
387
 
   "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
388
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
389
365
  /*
390
366
    Note that the combination --single-transaction --master-data
391
367
    will give bullet-proof binlog position only if server >=4.1.3. That's the
414
390
   (char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
415
391
  {"tables", OPT_TABLES, "Overrides option --databases (-B).",
416
392
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
417
 
  {"tz-utc", OPT_TZ_UTC,
418
 
    "SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones.",
419
 
    (char**) &opt_tz_utc, (char**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
393
  {"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of rows before each output progress report (requires --verbose)."),
 
394
   (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
 
395
   10000, 0, 0, 0, 0, 0},
420
396
#ifndef DONT_ALLOW_USER_CHANGE
421
397
  {"user", 'u', "User for login if not current user.",
422
398
   (char**) &current_user, (char**) &current_user, 0, GET_STR, REQUIRED_ARG,
442
418
static void print_value(FILE *file, DRIZZLE_RES  *result, DRIZZLE_ROW row,
443
419
                        const char *prefix,const char *name,
444
420
                        int string_value);
 
421
static const char* fetch_named_row(DRIZZLE_RES *result, DRIZZLE_ROW row, const char* name);
445
422
static int dump_selected_tables(char *db, char **table_names, int tables);
446
423
static int dump_all_tables_in_db(char *db);
447
424
static int init_dumping_tables(char *);
486
463
static void check_io(FILE *file)
487
464
{
488
465
  if (ferror(file))
489
 
    die(EX_EOF, "Got errno %d on write", errno);
 
466
    die(EX_EOF, _("Got errno %d on write"), errno);
490
467
}
491
468
 
492
469
static void print_version(void)
493
470
{
494
 
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
495
 
         drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
471
  printf(_("%s  Ver %s Distrib %s, for %s (%s)\n"),my_progname,DUMP_VERSION,
 
472
         drizzleclient_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
496
473
} /* print_version */
497
474
 
498
475
 
499
476
static void short_usage_sub(void)
500
477
{
501
 
  printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
502
 
  printf("OR     %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n",
 
478
  printf(_("Usage: %s [OPTIONS] database [tables]\n"), my_progname);
 
479
  printf(_("OR     %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
503
480
         my_progname);
504
 
  printf("OR     %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname);
 
481
  printf(_("OR     %s [OPTIONS] --all-databases [OPTIONS]\n"), my_progname);
505
482
}
506
483
 
507
484
 
508
485
static void usage(void)
509
486
{
510
487
  print_version();
511
 
  puts("By Igor Romanenko, Monty, Jani & Sinisa");
512
 
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
513
 
  puts("Dumping definition and data DRIZZLE database or table");
 
488
  puts(_("By Igor Romanenko, Monty, Jani & Sinisa"));
 
489
  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"));
 
490
  puts(_("Dumping definition and data DRIZZLE database or table"));
514
491
  short_usage_sub();
515
 
  print_defaults("my",load_default_groups);
 
492
  print_defaults("drizzle",load_default_groups);
516
493
  my_print_help(my_long_options);
517
494
  my_print_variables(my_long_options);
518
495
} /* usage */
521
498
static void short_usage(void)
522
499
{
523
500
  short_usage_sub();
524
 
  printf("For more options, use %s --help\n", my_progname);
 
501
  printf(_("For more options, use %s --help\n"), my_progname);
525
502
}
526
503
 
527
504
static void write_header(FILE *sql_file, char *db_name)
530
507
  {
531
508
    fputs("<?xml version=\"1.0\"?>\n", sql_file);
532
509
    /*
533
 
      Schema reference.  Allows use of xsi:nil for NULL values and 
 
510
      Schema reference.  Allows use of xsi:nil for NULL values and
534
511
      xsi:type to define an element's data type.
535
512
    */
536
513
    fputs("<drizzledump ", sql_file);
545
522
    {
546
523
      fprintf(sql_file,
547
524
              "-- DRIZZLE dump %s  Distrib %s, for %s (%s)\n--\n",
548
 
              DUMP_VERSION, drizzle_get_client_info(),
 
525
              DUMP_VERSION, drizzleclient_get_client_info(),
549
526
              SYSTEM_TYPE, MACHINE_TYPE);
550
527
      fprintf(sql_file, "-- Host: %s    Database: %s\n",
551
528
              current_host ? current_host : "localhost", db_name ? db_name :
553
530
      fputs("-- ------------------------------------------------------\n",
554
531
            sql_file);
555
532
      fprintf(sql_file, "-- Server version\t%s\n",
556
 
              drizzle_get_server_info(&drizzle_connection));
 
533
              drizzleclient_get_server_info(&drizzleclient_connection));
557
534
    }
558
535
    if (opt_set_charset)
559
536
      fprintf(sql_file,
560
 
"\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"
561
 
"\n/*!40101 SET NAMES %s */;\n",default_charset);
562
 
 
563
 
    if (opt_tz_utc)
564
 
    {
565
 
      fprintf(sql_file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
566
 
      fprintf(sql_file, "/*!40103 SET TIME_ZONE='+00:00' */;\n");
567
 
    }
 
537
"\nSET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;"
 
538
"\nSET NAMES %s;\n",default_charset);
568
539
 
569
540
    if (!path)
570
541
    {
571
542
      fprintf(md_result_file,"\
572
 
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n\
573
 
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n\
 
543
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;\n\
 
544
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\n\
574
545
");
575
546
    }
576
547
    check_io(sql_file);
587
558
  }
588
559
  else if (!opt_compact)
589
560
  {
590
 
    if (opt_tz_utc)
591
 
      fprintf(sql_file,"/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n");
592
 
 
593
561
    if (!path)
594
562
    {
595
563
      fprintf(md_result_file,"\
596
 
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n\
597
 
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n");
 
564
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;\n\
 
565
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;\n");
598
566
    }
599
567
    if (opt_set_charset)
600
 
      fprintf(sql_file,
601
 
"/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
602
 
    fprintf(sql_file,
603
 
            "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
604
 
    fputs("\n", sql_file);
 
568
      fprintf(sql_file, "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;\n");
605
569
    if (opt_comments)
606
570
    {
607
571
      if (opt_dump_date)
625
589
}
626
590
 
627
591
 
628
 
static unsigned char* get_table_key(const char *entry, size_t *length,
629
 
                            bool not_used __attribute__((unused)))
 
592
static unsigned char* get_table_key(const char *entry, size_t *length, bool)
630
593
{
631
594
  *length= strlen(entry);
632
595
  return (unsigned char*) entry;
633
596
}
634
597
 
635
598
 
636
 
static bool
637
 
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
638
 
               char *argument)
 
599
extern "C"
 
600
bool get_one_option(int optid, const struct my_option *, char *argument)
639
601
{
 
602
  char *endchar= NULL;
 
603
  uint64_t temp_drizzle_port= 0;
 
604
 
640
605
  switch (optid) {
641
606
  case 'p':
 
607
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
 
608
    /* if there is an alpha character this is not a valid port */
 
609
    if (strlen(endchar) != 0)
 
610
    {
 
611
      fprintf(stderr, _("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead.\n"));
 
612
      exit(EX_USAGE);
 
613
    }
 
614
    /* If the port number is > 65535 it is not a valid port
 
615
 *        This also helps with potential data loss casting unsigned long to a
 
616
 *               uint32_t. */
 
617
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
 
618
    {
 
619
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
 
620
      exit(EX_USAGE);
 
621
    }
 
622
    else
 
623
    {
 
624
      opt_drizzle_port= (uint32_t) temp_drizzle_port;
 
625
    }
 
626
    break;
 
627
  case 'P':
642
628
    if (argument)
643
629
    {
644
 
      char *start=argument;
645
 
      free(opt_password);
646
 
      opt_password=my_strdup(argument,MYF(MY_FAE));
647
 
      while (*argument) *argument++= 'x';               /* Destroy argument */
 
630
      char *start= argument;
 
631
      if (opt_password)
 
632
        free(opt_password);
 
633
      opt_password= strdup(argument);
 
634
      if (opt_password == NULL)
 
635
      {
 
636
        fprintf(stderr, _("Memory allocation error while copying password. "
 
637
                        "Aborting.\n"));
 
638
        exit(ENOMEM);
 
639
      }
 
640
      while (*argument)
 
641
      {
 
642
        /* Overwriting password with 'x' */
 
643
        *argument++= 'x';
 
644
      }
648
645
      if (*start)
649
 
        start[1]=0;                             /* Cut length of argument */
 
646
      {
 
647
        /* Cut length of argument */
 
648
        start[1]= 0;
 
649
      }
650
650
      tty_password= 0;
651
651
    }
652
652
    else
653
 
      tty_password=1;
 
653
    {
 
654
      tty_password= 1;
 
655
    }
654
656
    break;
655
657
  case 'r':
656
 
    if (!(md_result_file= my_fopen(argument, O_WRONLY | FILE_BINARY,
657
 
                                    MYF(MY_WME))))
 
658
    if (!(md_result_file= fopen(argument, "w")))
658
659
      exit(1);
659
660
    break;
660
661
  case 'N':
671
672
        a crash even if the input destination buffer is large enough
672
673
        to hold the output.
673
674
      */
674
 
      die(EX_USAGE, "Input filename too long: %s", argument);
 
675
      die(EX_USAGE, _("Input filename too long: %s"), argument);
675
676
    }
676
677
 
677
678
    break;
714
715
  {
715
716
    if (!strchr(argument, '.'))
716
717
    {
717
 
      fprintf(stderr, "Illegal use of option --ignore-table=<database>.<table>\n");
 
718
      fprintf(stderr, _("Illegal use of option --ignore-table=<database>.<table>\n"));
718
719
      exit(1);
719
720
    }
720
 
    if (my_hash_insert(&ignore_table, (unsigned char*)my_strdup(argument, MYF(0))))
 
721
    char * tmpptr= strdup(argument);
 
722
    if (!(tmpptr) || my_hash_insert(&ignore_table, (unsigned char*)tmpptr))
721
723
      exit(EX_EOM);
722
724
    break;
723
725
  }
737
739
                                    &err_ptr, &error_len);
738
740
      if (error_len)
739
741
      {
740
 
        strmake(buff, err_ptr, min((uint32_t)sizeof(buff), error_len));
741
 
        fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
 
742
        strncpy(buff, err_ptr, min((uint32_t)sizeof(buff), error_len));
 
743
        fprintf(stderr, _("Invalid mode to --compatible: %s\n"), buff);
742
744
        exit(1);
743
745
      }
744
746
      mode= opt_compatible_mode;
746
748
      {
747
749
        if (mode & 1)
748
750
        {
749
 
          end= my_stpcpy(end, compatible_mode_names[i]);
750
 
          end= my_stpcpy(end, ",");
 
751
          uint32_t len = strlen(compatible_mode_names[i]);
 
752
          end= strcpy(end, compatible_mode_names[i]) + len;
 
753
          end= strcpy(end, ",")+1;
751
754
        }
752
755
      }
753
756
      if (end!=compatible_mode_normal_str)
767
770
static int get_options(int *argc, char ***argv)
768
771
{
769
772
  int ho_error;
770
 
  const DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
 
773
  const DRIZZLE_PARAMETERS *drizzle_params= drizzleclient_get_parameters();
771
774
 
772
775
  opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
773
776
  opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
774
777
 
775
778
  md_result_file= stdout;
776
 
  load_defaults("my",load_default_groups,argc,argv);
 
779
  load_defaults("drizzle",load_default_groups,argc,argv);
777
780
  defaults_argv= *argv;
778
781
 
779
782
  if (hash_init(&ignore_table, charset_info, 16, 0, 0,
780
783
                (hash_get_key) get_table_key,
781
784
                (hash_free_key) free_table_ent, 0))
782
785
    return(EX_EOM);
783
 
  /* Don't copy internal log tables */
784
 
  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))))
796
 
    return(EX_EOM);
797
786
 
798
787
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
799
788
    return(ho_error);
811
800
                fields_terminated))
812
801
  {
813
802
    fprintf(stderr,
814
 
            "%s: You must use option --tab with --fields-...\n", my_progname);
 
803
            _("%s: You must use option --tab with --fields-...\n"), my_progname);
815
804
    return(EX_USAGE);
816
805
  }
817
806
 
828
817
    opt_master_data= DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL;
829
818
  if (opt_single_transaction && opt_lock_all_tables)
830
819
  {
831
 
    fprintf(stderr, "%s: You can't use --single-transaction and "
832
 
            "--lock-all-tables at the same time.\n", my_progname);
 
820
    fprintf(stderr, _("%s: You can't use --single-transaction and "
 
821
            "--lock-all-tables at the same time.\n"), my_progname);
833
822
    return(EX_USAGE);
834
823
  }
835
824
  if (opt_master_data)
841
830
    lock_tables= 0;
842
831
  if (enclosed && opt_enclosed)
843
832
  {
844
 
    fprintf(stderr, "%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n", my_progname);
 
833
    fprintf(stderr, _("%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n"), my_progname);
845
834
    return(EX_USAGE);
846
835
  }
847
836
  if ((opt_databases || opt_alldbs) && path)
848
837
  {
849
838
    fprintf(stderr,
850
 
            "%s: --databases or --all-databases can't be used with --tab.\n",
 
839
            _("%s: --databases or --all-databases can't be used with --tab.\n"),
851
840
            my_progname);
852
841
    return(EX_USAGE);
853
842
  }
854
843
  if (strcmp(default_charset, charset_info->csname) &&
855
 
      !(charset_info= get_charset_by_csname(default_charset,
856
 
                                            MY_CS_PRIMARY, MYF(MY_WME))))
 
844
      !(charset_info= get_charset_by_csname(default_charset, MY_CS_PRIMARY)))
857
845
    exit(1);
858
846
  if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs))
859
847
  {
861
849
    return EX_USAGE;
862
850
  }
863
851
  if (tty_password)
864
 
    opt_password=get_tty_password(NULL);
 
852
    opt_password=drizzleclient_get_tty_password(NULL);
865
853
  return(0);
866
854
} /* get_options */
867
855
 
872
860
static void DB_error(DRIZZLE *drizzle_arg, const char *when)
873
861
{
874
862
 
875
 
  maybe_die(EX_DRIZZLEERR, "Got error: %d: %s %s",
876
 
          drizzle_errno(drizzle_arg), drizzle_error(drizzle_arg), when);
 
863
  maybe_die(EX_DRIZZLEERR, _("Got error: %d: %s %s"),
 
864
          drizzleclient_errno(drizzle_arg), drizzleclient_error(drizzle_arg), when);
877
865
  return;
878
866
}
879
867
 
887
875
    error_num   - process return value
888
876
    fmt_reason  - a format string for use by vsnprintf.
889
877
    ...         - variable arguments for above fmt_reason string
890
 
  
 
878
 
891
879
  DESCRIPTION
892
880
    This call prints out the formatted error message to stderr and then
893
881
    terminates the process.
916
904
    error_num   - process return value
917
905
    fmt_reason  - a format string for use by vsnprintf.
918
906
    ...         - variable arguments for above fmt_reason string
919
 
  
 
907
 
920
908
  DESCRIPTION
921
909
    This call prints out the formatted error message to stderr and then
922
910
    terminates the process, unless the --force command line option is used.
923
 
    
 
911
 
924
912
    This call should be used for non-fatal errors (such as database
925
913
    errors) that the code may still be able to continue to the next unit
926
914
    of work.
927
 
    
 
915
 
928
916
*/
929
917
static void maybe_die(int error_num, const char* fmt_reason, ...)
930
918
{
947
935
  some.
948
936
 
949
937
  SYNOPSIS
950
 
    drizzle_query_with_error_report()
 
938
    drizzleclient_query_with_error_report()
951
939
    drizzle_con       connection to use
952
940
    res             if non zero, result will be put there with
953
 
                    drizzle_store_result()
 
941
                    drizzleclient_store_result()
954
942
    query           query to send to server
955
943
 
956
944
  RETURN VALUES
958
946
    1               error
959
947
*/
960
948
 
961
 
static int drizzle_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
 
949
static int drizzleclient_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
962
950
                                         const char *query)
963
951
{
964
 
  if (drizzle_query(drizzle_con, query) ||
965
 
      (res && !((*res)= drizzle_store_result(drizzle_con))))
 
952
  if (drizzleclient_query(drizzle_con, query) ||
 
953
      (res && !((*res)= drizzleclient_store_result(drizzle_con))))
966
954
  {
967
 
    maybe_die(EX_DRIZZLEERR, "Couldn't execute '%s': %s (%d)",
968
 
            query, drizzle_error(drizzle_con), drizzle_errno(drizzle_con));
 
955
    maybe_die(EX_DRIZZLEERR, _("Couldn't execute '%s': %s (%d)"),
 
956
            query, drizzleclient_error(drizzle_con), drizzleclient_errno(drizzle_con));
969
957
    return 1;
970
958
  }
971
959
  return 0;
972
960
}
973
961
 
974
 
 
975
 
/**
976
 
  Switch charset for results to some specified charset.  If the server does not
977
 
  support character_set_results variable, nothing can be done here.  As for
978
 
  whether something should be done here, future new callers of this function
979
 
  should be aware that the server lacking the facility of switching charsets is
980
 
  treated as success.
981
 
 
982
 
  @note  If the server lacks support, then nothing is changed and no error
983
 
         condition is returned.
984
 
 
985
 
  @returns  whether there was an error or not
986
 
*/
987
 
static int switch_character_set_results(DRIZZLE *drizzle, const char *cs_name)
988
 
{
989
 
  char query_buffer[QUERY_LENGTH];
990
 
  size_t query_length;
991
 
 
992
 
  /* Server lacks facility.  This is not an error, by arbitrary decision . */
993
 
  if (!server_supports_switching_charsets)
994
 
    return false;
995
 
 
996
 
  query_length= snprintf(query_buffer,
997
 
                         sizeof (query_buffer),
998
 
                         "SET SESSION character_set_results = '%s'",
999
 
                         (const char *) cs_name);
1000
 
 
1001
 
  return drizzle_real_query(drizzle, query_buffer, query_length);
1002
 
}
1003
 
 
1004
962
/*
1005
963
  Open a new .sql file to dump the table or view into
1006
964
 
1017
975
  FILE* res;
1018
976
  char filename[FN_REFLEN], tmp_path[FN_REFLEN];
1019
977
  convert_dirname(tmp_path,path,NULL);
1020
 
  res= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4),
1021
 
                O_WRONLY, MYF(MY_WME));
 
978
  res= fopen(fn_format(filename, table, tmp_path, ".sql", 4), "w");
 
979
 
1022
980
  return res;
1023
981
}
1024
982
 
1026
984
static void free_resources(void)
1027
985
{
1028
986
  if (md_result_file && md_result_file != stdout)
1029
 
    my_fclose(md_result_file, MYF(0));
 
987
    fclose(md_result_file);
1030
988
  free(opt_password);
1031
989
  if (hash_inited(&ignore_table))
1032
990
    hash_free(&ignore_table);
1043
1001
  if (ignore_errors)
1044
1002
    return;
1045
1003
  if (drizzle)
1046
 
    drizzle_close(drizzle);
 
1004
    drizzleclient_close(drizzle);
1047
1005
  free_resources();
1048
1006
  exit(error);
1049
1007
}
1055
1013
 
1056
1014
static int connect_to_db(char *host, char *user,char *passwd)
1057
1015
{
1058
 
  char buff[20+FN_REFLEN];
1059
 
 
1060
 
 
1061
 
  verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1062
 
  drizzle_create(&drizzle_connection);
 
1016
  verbose_msg(_("-- Connecting to %s...\n"), host ? host : "localhost");
 
1017
  drizzleclient_create(&drizzleclient_connection);
1063
1018
  if (opt_compress)
1064
 
    drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NULL);
1065
 
  if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
 
1019
    drizzleclient_options(&drizzleclient_connection,DRIZZLE_OPT_COMPRESS,NULL);
 
1020
  if (!(drizzle= drizzleclient_connect(&drizzleclient_connection,host,user,passwd,
1066
1021
                                  NULL,opt_drizzle_port, NULL,
1067
1022
                                  0)))
1068
1023
  {
1069
 
    DB_error(&drizzle_connection, "when trying to connect");
 
1024
    DB_error(&drizzleclient_connection, "when trying to connect");
1070
1025
    return(1);
1071
1026
  }
1072
 
  if (drizzle_get_server_version(&drizzle_connection) < 40100)
1073
 
  {
1074
 
    /* Don't dump SET NAMES with a pre-4.1 server (bug#7997).  */
1075
 
    opt_set_charset= 0;
1076
1027
 
1077
 
    /* Don't switch charsets for 4.1 and earlier.  (bug#34192). */
1078
 
    server_supports_switching_charsets= false;
1079
 
  } 
1080
 
  /*
1081
 
    set time_zone to UTC to allow dumping date types between servers with
1082
 
    different time zone settings
1083
 
  */
1084
 
  if (opt_tz_utc)
1085
 
  {
1086
 
    snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
1087
 
    if (drizzle_query_with_error_report(drizzle, 0, buff))
1088
 
      return(1);
1089
 
  }
1090
1028
  return(0);
1091
1029
} /* connect_to_db */
1092
1030
 
1096
1034
*/
1097
1035
static void dbDisconnect(char *host)
1098
1036
{
1099
 
  verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost");
1100
 
  drizzle_close(drizzle);
 
1037
  verbose_msg(_("-- Disconnecting from %s...\n"), host ? host : "localhost");
 
1038
  drizzleclient_close(drizzle);
1101
1039
} /* dbDisconnect */
1102
1040
 
1103
1041
 
1104
 
static void unescape(FILE *file,char *pos,uint length)
 
1042
static void unescape(FILE *file,char *pos,uint32_t length)
1105
1043
{
1106
1044
  char *tmp;
1107
1045
 
1108
 
  if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1109
 
    die(EX_DRIZZLEERR, "Couldn't allocate memory");
 
1046
  if (!(tmp=(char*) malloc(length*2+1)))
 
1047
    die(EX_DRIZZLEERR, _("Couldn't allocate memory"));
1110
1048
 
1111
 
  drizzle_escape_string(tmp, pos, length);
 
1049
  drizzleclient_escape_string(tmp, pos, length);
1112
1050
  fputc('\'', file);
1113
1051
  fputs(tmp, file);
1114
1052
  fputc('\'', file);
1253
1191
  Print xml tag. Optionally add attribute(s).
1254
1192
 
1255
1193
  SYNOPSIS
1256
 
    print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name, 
 
1194
    print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name,
1257
1195
                    ..., attribute_name_n, attribute_value_n, NULL)
1258
1196
    xml_file              - output file
1259
1197
    sbeg                  - line beginning
1268
1206
    Print XML tag with any number of attribute="value" pairs to the xml_file.
1269
1207
 
1270
1208
    Format is:
1271
 
      sbeg<tag_name first_attribute_name="first_attribute_value" ... 
 
1209
      sbeg<tag_name first_attribute_name="first_attribute_value" ...
1272
1210
      attribute_name_n="attribute_value_n">send
1273
1211
  NOTE
1274
1212
    Additional arguments must be present in attribute/value pairs.
1278
1216
*/
1279
1217
 
1280
1218
static void print_xml_tag(FILE * xml_file, const char* sbeg,
1281
 
                          const char* line_end, 
1282
 
                          const char* tag_name, 
 
1219
                          const char* line_end,
 
1220
                          const char* tag_name,
1283
1221
                          const char* first_attribute_name, ...)
1284
1222
{
1285
1223
  va_list arg_list;
1287
1225
 
1288
1226
  fputs(sbeg, xml_file);
1289
1227
  fputc('<', xml_file);
1290
 
  fputs(tag_name, xml_file);  
 
1228
  fputs(tag_name, xml_file);
1291
1229
 
1292
1230
  va_start(arg_list, first_attribute_name);
1293
1231
  attribute_name= first_attribute_name;
1297
1235
    assert(attribute_value != NULL);
1298
1236
 
1299
1237
    fputc(' ', xml_file);
1300
 
    fputs(attribute_name, xml_file);    
 
1238
    fputs(attribute_name, xml_file);
1301
1239
    fputc('\"', xml_file);
1302
 
    
 
1240
 
1303
1241
    print_quoted_xml(xml_file, attribute_value, strlen(attribute_value));
1304
1242
    fputc('\"', xml_file);
1305
1243
 
1367
1305
static void print_xml_row(FILE *xml_file, const char *row_name,
1368
1306
                          DRIZZLE_RES *tableRes, DRIZZLE_ROW *row)
1369
1307
{
1370
 
  uint i;
 
1308
  uint32_t i;
1371
1309
  DRIZZLE_FIELD *field;
1372
 
  uint32_t *lengths= drizzle_fetch_lengths(tableRes);
 
1310
  uint32_t *lengths= drizzleclient_fetch_lengths(tableRes);
1373
1311
 
1374
1312
  fprintf(xml_file, "\t\t<%s", row_name);
1375
1313
  check_io(xml_file);
1376
 
  drizzle_field_seek(tableRes, 0);
1377
 
  for (i= 0; (field= drizzle_fetch_field(tableRes)); i++)
 
1314
  drizzleclient_field_seek(tableRes, 0);
 
1315
  for (i= 0; (field= drizzleclient_fetch_field(tableRes)); i++)
1378
1316
  {
1379
1317
    if ((*row)[i])
1380
1318
    {
1423
1361
    db          - db name
1424
1362
    table_type  - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW"
1425
1363
    ignore_flag - what we must particularly ignore - see IGNORE_ defines above
 
1364
    num_fields  - number of fields in the table
1426
1365
 
1427
1366
  RETURN
1428
 
    number of fields in table, 0 if error
 
1367
    true if success, false if error
1429
1368
*/
1430
1369
 
1431
 
static uint get_table_structure(char *table, char *db, char *table_type,
1432
 
                                char *ignore_flag)
 
1370
static bool get_table_structure(char *table, char *db, char *table_type,
 
1371
                                char *ignore_flag, uint64_t *num_fields)
1433
1372
{
1434
1373
  bool    init=0, delayed, write_data, complete_insert;
1435
 
  uint64_t num_fields;
1436
1374
  char       *result_table, *opt_quoted_table;
1437
1375
  const char *insert_option;
1438
1376
  char       name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3];
1439
1377
  char       table_buff2[NAME_LEN*2+3], query_buff[QUERY_LENGTH];
1440
1378
  FILE       *sql_file= md_result_file;
1441
 
  int        len;
1442
1379
  DRIZZLE_RES  *result;
1443
1380
  DRIZZLE_ROW  row;
1444
1381
 
1448
1385
  if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED))
1449
1386
  {
1450
1387
    delayed= 0;
1451
 
    verbose_msg("-- Warning: Unable to use delayed inserts for table '%s' "
1452
 
                "because it's of type %s\n", table, table_type);
 
1388
    verbose_msg(_("-- Warning: Unable to use delayed inserts for table '%s' "
 
1389
                "because it's of type %s\n"), table, table_type);
1453
1390
  }
1454
1391
 
1455
1392
  complete_insert= 0;
1456
1393
  if ((write_data= !(*ignore_flag & IGNORE_DATA)))
1457
1394
  {
1458
1395
    complete_insert= opt_complete_insert;
1459
 
    insert_pat= "";
 
1396
    insert_pat.clear();
1460
1397
  }
1461
1398
 
1462
1399
  insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " :
1463
1400
                  delayed ? " DELAYED " : opt_ignore ? " IGNORE " : "");
1464
1401
 
1465
 
  verbose_msg("-- Retrieving table structure for table %s...\n", table);
1466
 
 
1467
 
  len= snprintf(query_buff, sizeof(query_buff),
1468
 
                "SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
1469
 
                (opt_quoted || opt_keywords));
 
1402
  verbose_msg(_("-- Retrieving table structure for table %s...\n"), table);
1470
1403
 
1471
1404
  result_table=     quote_name(table, table_buff, 1);
1472
1405
  opt_quoted_table= quote_name(table, table_buff2, 0);
1477
1410
    order_by= primary_key_fields(result_table);
1478
1411
  }
1479
1412
 
1480
 
  if (!opt_xml && !drizzle_query_with_error_report(drizzle, 0, query_buff))
 
1413
  if (!opt_xml)
1481
1414
  {
1482
1415
    /* using SHOW CREATE statement */
1483
1416
    if (!opt_no_create_info)
1488
1421
 
1489
1422
      snprintf(buff, sizeof(buff), "show create table %s", result_table);
1490
1423
 
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))
1494
 
        return(0);
 
1424
      if (drizzleclient_query_with_error_report(drizzle, &result, buff))
 
1425
        return false;
1495
1426
 
1496
1427
      if (path)
1497
1428
      {
1498
1429
        if (!(sql_file= open_sql_file_for_table(table)))
1499
 
          return(0);
 
1430
          return false;
1500
1431
 
1501
1432
        write_header(sql_file, db);
1502
1433
      }
1503
1434
      if (!opt_xml && opt_comments)
1504
1435
      {
1505
 
      if (strcmp (table_type, "VIEW") == 0)         /* view */
1506
 
        fprintf(sql_file, "\n--\n-- Temporary table structure for view %s\n--\n\n",
1507
 
                result_table);
1508
 
      else
1509
1436
        fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n",
1510
1437
                result_table);
1511
1438
        check_io(sql_file);
1513
1440
      if (opt_drop)
1514
1441
      {
1515
1442
      /*
1516
 
        Even if the "table" is a view, we do a DROP TABLE here.  The
1517
 
        view-specific code below fills in the DROP VIEW.
 
1443
        Even if the "table" is a view, we do a DROP TABLE here.
1518
1444
       */
1519
 
        fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
1520
 
                opt_quoted_table);
 
1445
        fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table);
1521
1446
        check_io(sql_file);
1522
1447
      }
1523
1448
 
1524
 
      field= drizzle_fetch_field_direct(result, 0);
1525
 
      if (strcmp(field->name, "View") == 0)
1526
 
      {
1527
 
        char *scv_buff= NULL;
1528
 
 
1529
 
        verbose_msg("-- It's a view, create dummy table for view\n");
1530
 
 
1531
 
        /* save "show create" statement for later */
1532
 
        if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
1533
 
          scv_buff= my_strdup(scv_buff, MYF(0));
1534
 
 
1535
 
        drizzle_free_result(result);
1536
 
 
1537
 
        /*
1538
 
          Create a table with the same name as the view and with columns of
1539
 
          the same name in order to satisfy views that depend on this view.
1540
 
          The table will be removed when the actual view is created.
1541
 
 
1542
 
          The properties of each column, aside from the data type, are not
1543
 
          preserved in this temporary table, because they are not necessary.
1544
 
 
1545
 
          This will not be necessary once we can determine dependencies
1546
 
          between views and can simply dump them in the appropriate order.
1547
 
        */
1548
 
        snprintf(query_buff, sizeof(query_buff),
1549
 
                 "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))
1553
 
        {
1554
 
          /*
1555
 
            View references invalid or privileged table/col/fun (err 1356),
1556
 
            so we cannot create a stand-in table.  Be defensive and dump
1557
 
            a comment with the view's 'show create' statement. (Bug #17371)
1558
 
          */
1559
 
 
1560
 
          if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1561
 
            fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1562
 
 
1563
 
          free(scv_buff);
1564
 
 
1565
 
          return(0);
1566
 
        }
1567
 
        else
1568
 
          free(scv_buff);
1569
 
 
1570
 
        if (drizzle_num_rows(result))
1571
 
        {
1572
 
          if (opt_drop)
1573
 
          {
1574
 
            /*
1575
 
              We have already dropped any table of the same name above, so
1576
 
              here we just drop the view.
1577
 
            */
1578
 
 
1579
 
            fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n",
1580
 
                    opt_quoted_table);
1581
 
            check_io(sql_file);
1582
 
          }
1583
 
 
1584
 
          fprintf(sql_file,
1585
 
                  "/*!50001 CREATE TABLE %s (\n",
1586
 
                  result_table);
1587
 
 
1588
 
          /*
1589
 
            Get first row, following loop will prepend comma - keeps from
1590
 
            having to know if the row being printed is last to determine if
1591
 
            there should be a _trailing_ comma.
1592
 
          */
1593
 
 
1594
 
          row= drizzle_fetch_row(result);
1595
 
 
1596
 
          fprintf(sql_file, "  %s %s", quote_name(row[0], name_buff, 0),
1597
 
                  row[1]);
1598
 
 
1599
 
          while((row= drizzle_fetch_row(result)))
1600
 
          {
1601
 
            /* col name, col type */
1602
 
            fprintf(sql_file, ",\n  %s %s",
1603
 
                    quote_name(row[0], name_buff, 0), row[1]);
1604
 
          }
1605
 
          fprintf(sql_file, "\n) */;\n"); 
1606
 
          check_io(sql_file);
1607
 
        }
1608
 
 
1609
 
        drizzle_free_result(result);
1610
 
 
1611
 
        if (path)
1612
 
          my_fclose(sql_file, MYF(MY_WME));
1613
 
 
1614
 
        seen_views= 1;
1615
 
        return(0);
1616
 
      }
1617
 
 
1618
 
      row= drizzle_fetch_row(result);
 
1449
      field= drizzleclient_fetch_field_direct(result, 0);
 
1450
 
 
1451
      row= drizzleclient_fetch_row(result);
1619
1452
 
1620
1453
      fprintf(sql_file, "%s;\n", row[1]);
1621
1454
 
1622
1455
      check_io(sql_file);
1623
 
      drizzle_free_result(result);
 
1456
      drizzleclient_free_result(result);
1624
1457
    }
1625
1458
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1626
1459
             result_table);
1627
 
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
 
1460
    if (drizzleclient_query_with_error_report(drizzle, &result, query_buff))
1628
1461
    {
1629
1462
      if (path)
1630
 
        my_fclose(sql_file, MYF(MY_WME));
1631
 
      return(0);
 
1463
        fclose(sql_file);
 
1464
      return false;
1632
1465
    }
1633
1466
 
1634
1467
    /*
1658
1491
      }
1659
1492
    }
1660
1493
 
1661
 
    while ((row= drizzle_fetch_row(result)))
 
1494
    while ((row= drizzleclient_fetch_row(result)))
1662
1495
    {
1663
1496
      if (complete_insert)
1664
1497
      {
1670
1503
        insert_pat.append(quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1671
1504
      }
1672
1505
    }
1673
 
    num_fields= drizzle_num_rows(result);
1674
 
    drizzle_free_result(result);
 
1506
    *num_fields= drizzleclient_num_rows(result);
 
1507
    drizzleclient_free_result(result);
1675
1508
  }
1676
1509
  else
1677
1510
  {
1678
 
    verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
1679
 
                my_progname, drizzle_error(drizzle));
 
1511
    verbose_msg(_("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n"),
 
1512
                my_progname, drizzleclient_error(drizzle));
1680
1513
 
1681
1514
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1682
1515
             result_table);
1683
 
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1684
 
      return(0);
 
1516
    if (drizzleclient_query_with_error_report(drizzle, &result, query_buff))
 
1517
      return false;
1685
1518
 
1686
1519
    /* Make an sql-file, if path was given iow. option -T was given */
1687
1520
    if (!opt_no_create_info)
1689
1522
      if (path)
1690
1523
      {
1691
1524
        if (!(sql_file= open_sql_file_for_table(table)))
1692
 
          return(0);
 
1525
          return false;
1693
1526
        write_header(sql_file, db);
1694
1527
      }
1695
1528
      if (!opt_xml && opt_comments)
1700
1533
      if (!opt_xml)
1701
1534
        fprintf(sql_file, "CREATE TABLE %s (\n", result_table);
1702
1535
      else
1703
 
        print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table, 
 
1536
        print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table,
1704
1537
                NULL);
1705
1538
      check_io(sql_file);
1706
1539
    }
1724
1557
      }
1725
1558
    }
1726
1559
 
1727
 
    while ((row= drizzle_fetch_row(result)))
 
1560
    while ((row= drizzleclient_fetch_row(result)))
1728
1561
    {
1729
 
      uint32_t *lengths= drizzle_fetch_lengths(result);
 
1562
      uint32_t *lengths= drizzleclient_fetch_lengths(result);
1730
1563
      if (init)
1731
1564
      {
1732
1565
        if (!opt_xml && !opt_no_create_info)
1768
1601
        check_io(sql_file);
1769
1602
      }
1770
1603
    }
1771
 
    num_fields= drizzle_num_rows(result);
1772
 
    drizzle_free_result(result);
 
1604
    *num_fields= drizzleclient_num_rows(result);
 
1605
    drizzleclient_free_result(result);
1773
1606
    if (!opt_no_create_info)
1774
1607
    {
1775
1608
      /* Make an sql-file, if path was given iow. option -T was given */
1776
1609
      char buff[20+FN_REFLEN];
1777
 
      uint keynr,primary_key;
 
1610
      uint32_t keynr,primary_key;
1778
1611
      snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1779
 
      if (drizzle_query_with_error_report(drizzle, &result, buff))
 
1612
      if (drizzleclient_query_with_error_report(drizzle, &result, buff))
1780
1613
      {
1781
 
        if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
 
1614
        if (drizzleclient_errno(drizzle) == ER_WRONG_OBJECT)
1782
1615
        {
1783
1616
          /* it is VIEW */
1784
1617
          fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1785
1618
          goto continue_xml;
1786
1619
        }
1787
 
        fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
1788
 
                my_progname, result_table, drizzle_error(drizzle));
 
1620
        fprintf(stderr, _("%s: Can't get keys for table %s (%s)\n"),
 
1621
                my_progname, result_table, drizzleclient_error(drizzle));
1789
1622
        if (path)
1790
 
          my_fclose(sql_file, MYF(MY_WME));
1791
 
        return(0);
 
1623
          fclose(sql_file);
 
1624
        return false;
1792
1625
      }
1793
1626
 
1794
1627
      /* Find first which key is primary key */
1795
1628
      keynr=0;
1796
1629
      primary_key=INT_MAX;
1797
 
      while ((row= drizzle_fetch_row(result)))
 
1630
      while ((row= drizzleclient_fetch_row(result)))
1798
1631
      {
1799
1632
        if (atoi(row[3]) == 1)
1800
1633
        {
1810
1643
          }
1811
1644
        }
1812
1645
      }
1813
 
      drizzle_data_seek(result,0);
 
1646
      drizzleclient_data_seek(result,0);
1814
1647
      keynr=0;
1815
 
      while ((row= drizzle_fetch_row(result)))
 
1648
      while ((row= drizzleclient_fetch_row(result)))
1816
1649
      {
1817
1650
        if (opt_xml)
1818
1651
        {
1840
1673
          fprintf(sql_file, " (%s)",row[7]);      /* Sub key */
1841
1674
        check_io(sql_file);
1842
1675
      }
1843
 
      drizzle_free_result(result);
 
1676
      drizzleclient_free_result(result);
1844
1677
      if (!opt_xml)
1845
1678
      {
1846
1679
        if (keynr)
1848
1681
        fputs("\n)",sql_file);
1849
1682
        check_io(sql_file);
1850
1683
      }
1851
 
 
1852
1684
      /* Get DRIZZLE specific create options */
1853
1685
      if (create_options)
1854
1686
      {
1858
1690
        snprintf(buff, sizeof(buff), "show table status like %s",
1859
1691
                 quote_for_like(table, show_name_buff));
1860
1692
 
1861
 
        if (drizzle_query_with_error_report(drizzle, &result, buff))
 
1693
        if (drizzleclient_query_with_error_report(drizzle, &result, buff))
1862
1694
        {
1863
 
          if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
 
1695
          if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
1864
1696
          {                                     /* If old DRIZZLE version */
1865
 
            verbose_msg("-- Warning: Couldn't get status information for " \
1866
 
                        "table %s (%s)\n", result_table,drizzle_error(drizzle));
 
1697
            verbose_msg(_("-- Warning: Couldn't get status information for " \
 
1698
                        "table %s (%s)\n"), result_table,drizzleclient_error(drizzle));
1867
1699
          }
1868
1700
        }
1869
 
        else if (!(row= drizzle_fetch_row(result)))
 
1701
        else if (!(row= drizzleclient_fetch_row(result)))
1870
1702
        {
1871
1703
          fprintf(stderr,
1872
 
                  "Error: Couldn't read status information for table %s (%s)\n",
1873
 
                  result_table,drizzle_error(drizzle));
 
1704
                  _("Error: Couldn't read status information for table %s (%s)\n"),
 
1705
                  result_table,drizzleclient_error(drizzle));
1874
1706
        }
1875
1707
        else
1876
1708
        {
1882
1714
            print_value(sql_file,result,row,"engine=","Engine",0);
1883
1715
            print_value(sql_file,result,row,"","Create_options",0);
1884
1716
            print_value(sql_file,result,row,"comment=","Comment",1);
 
1717
 
1885
1718
            fputs(" */",sql_file);
1886
1719
            check_io(sql_file);
1887
1720
          }
1888
1721
        }
1889
 
        drizzle_free_result(result);              /* Is always safe to free */
 
1722
        drizzleclient_free_result(result);              /* Is always safe to free */
1890
1723
      }
1891
1724
continue_xml:
1892
1725
      if (!opt_xml)
1896
1729
      check_io(sql_file);
1897
1730
    }
1898
1731
  }
1899
 
  if (complete_insert)
1900
 
  {
 
1732
  if (complete_insert) {
1901
1733
    insert_pat.append(") VALUES ");
1902
1734
    if (!extended_insert)
1903
1735
      insert_pat.append("(");
1906
1738
  {
1907
1739
    fputs("\n", sql_file);
1908
1740
    write_footer(sql_file);
1909
 
    my_fclose(sql_file, MYF(MY_WME));
 
1741
    fclose(sql_file);
1910
1742
  }
1911
 
  return((uint) num_fields);
 
1743
  return true;
1912
1744
} /* get_table_structure */
1913
1745
 
1914
1746
static void add_load_option(string &str, const char *option,
1921
1753
  }
1922
1754
 
1923
1755
  str.append(option);
1924
 
  
 
1756
 
1925
1757
  if (strncmp(option_value, "0x", sizeof("0x")-1) == 0)
1926
1758
  {
1927
1759
    /* It's a hex constant, don't escape */
1944
1776
 
1945
1777
static void field_escape(string &in, const char *from)
1946
1778
{
1947
 
  uint end_backslashes= 0; 
 
1779
  uint32_t end_backslashes= 0;
1948
1780
 
1949
1781
  in.append("'");
1950
1782
 
1998
1830
  char table_type[NAME_LEN];
1999
1831
  char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table;
2000
1832
  int error= 0;
2001
 
  uint32_t         rownr, row_break, total_length, init_length;
2002
 
  uint num_fields;
 
1833
  uint32_t rownr, row_break, total_length, init_length;
 
1834
  uint64_t num_fields= 0;
2003
1835
  DRIZZLE_RES     *res;
2004
1836
  DRIZZLE_FIELD   *field;
2005
1837
  DRIZZLE_ROW     row;
2009
1841
    Make sure you get the create table info before the following check for
2010
1842
    --no-data flag below. Otherwise, the create table info won't be printed.
2011
1843
  */
2012
 
  num_fields= get_table_structure(table, db, table_type, &ignore_flag);
2013
 
 
2014
 
  /*
2015
 
    The "table" could be a view.  If so, we don't do anything here.
2016
 
  */
2017
 
  if (strcmp(table_type, "VIEW") == 0)
 
1844
  if (!get_table_structure(table, db, table_type, &ignore_flag, &num_fields))
 
1845
  {
 
1846
    maybe_die(EX_TABLE_STATUS, _("Error retrieving table structure for table: \"%s\""), table);
2018
1847
    return;
 
1848
  }
2019
1849
 
2020
1850
  /* Check --no-data flag */
2021
1851
  if (opt_no_data)
2022
1852
  {
2023
 
    verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
 
1853
    verbose_msg(_("-- Skipping dump data for table '%s', --no-data was used\n"),
2024
1854
                table);
2025
1855
    return;
2026
1856
  }
2031
1861
  */
2032
1862
  if (ignore_flag & IGNORE_DATA)
2033
1863
  {
2034
 
    verbose_msg("-- Warning: Skipping data for table '%s' because " \
2035
 
                "it's of type %s\n", table, table_type);
 
1864
    verbose_msg(_("-- Warning: Skipping data for table '%s' because " \
 
1865
                "it's of type %s\n"), table, table_type);
2036
1866
    return;
2037
1867
  }
2038
1868
  /* Check that there are any fields in the table */
2039
1869
  if (num_fields == 0)
2040
1870
  {
2041
 
    verbose_msg("-- Skipping dump data for table '%s', it has no fields\n",
 
1871
    verbose_msg(_("-- Skipping dump data for table '%s', it has no fields\n"),
2042
1872
                table);
2043
1873
    return;
2044
1874
  }
2045
1875
 
2046
 
  /*
2047
 
     Check --skip-events flag: it is not enough to skip creation of events
2048
 
     discarding SHOW CREATE EVENT statements generation. The myslq.event
2049
 
     table data should be skipped too.
2050
 
  */
2051
 
  if (!opt_events && !my_strcasecmp(&my_charset_utf8_general_ci, db, "mysql") &&
2052
 
      !my_strcasecmp(&my_charset_utf8_general_ci, table, "event"))
2053
 
  {
2054
 
    verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2055
 
    return;
2056
 
  }
2057
 
 
2058
1876
  result_table= quote_name(table,table_buff, 1);
2059
1877
  opt_quoted_table= quote_name(table, table_buff2, 0);
2060
1878
 
2061
 
  verbose_msg("-- Sending SELECT query...\n");
 
1879
  verbose_msg(_("-- Sending SELECT query...\n"));
2062
1880
 
2063
1881
  query_string.clear();
2064
1882
  query_string.reserve(1024);
2071
1889
      Convert the path to native os format
2072
1890
      and resolve to the full filepath.
2073
1891
    */
2074
 
    convert_dirname(tmp_path,path,NULL);    
 
1892
    convert_dirname(tmp_path,path,NULL);
2075
1893
    my_load_path(tmp_path, tmp_path, NULL);
2076
1894
    fn_format(filename, table, tmp_path, ".txt", MYF(MY_UNPACK_FILENAME));
2077
1895
 
2078
1896
    /* Must delete the file that 'INTO OUTFILE' will write to */
2079
1897
    my_delete(filename, MYF(0));
2080
1898
 
2081
 
    /* convert to a unix path name to stick into the query */
2082
 
    to_unix_path(filename);
2083
 
 
2084
1899
    /* now build the query string */
2085
1900
 
2086
1901
    query_string.append( "SELECT * INTO OUTFILE '");
2089
1904
 
2090
1905
    if (fields_terminated || enclosed || opt_enclosed || escaped)
2091
1906
      query_string.append( " FIELDS");
2092
 
    
 
1907
 
2093
1908
    add_load_option(query_string, " TERMINATED BY ", fields_terminated);
2094
1909
    add_load_option(query_string, " ENCLOSED BY ", enclosed);
2095
1910
    add_load_option(query_string, " OPTIONALLY ENCLOSED BY ", opt_enclosed);
2111
1926
      query_string.append( order_by);
2112
1927
    }
2113
1928
 
2114
 
    if (drizzle_real_query(drizzle, query_string.c_str(), query_string.length()))
 
1929
    if (drizzleclient_real_query(drizzle, query_string.c_str(), query_string.length()))
2115
1930
    {
2116
 
      DB_error(drizzle, "when executing 'SELECT INTO OUTFILE'");
 
1931
      DB_error(drizzle, _("when executing 'SELECT INTO OUTFILE'"));
2117
1932
      return;
2118
1933
    }
2119
1934
  }
2121
1936
  {
2122
1937
    if (!opt_xml && opt_comments)
2123
1938
    {
2124
 
      fprintf(md_result_file,"\n--\n-- Dumping data for table %s\n--\n",
 
1939
      fprintf(md_result_file,_("\n--\n-- Dumping data for table %s\n--\n"),
2125
1940
              result_table);
2126
1941
      check_io(md_result_file);
2127
1942
    }
2128
 
    
 
1943
 
2129
1944
    query_string.append( "SELECT * FROM ");
2130
1945
    query_string.append( result_table);
2131
1946
 
2136
1951
        fprintf(md_result_file, "-- WHERE:  %s\n", where);
2137
1952
        check_io(md_result_file);
2138
1953
      }
2139
 
      
 
1954
 
2140
1955
      query_string.append( " WHERE ");
2141
1956
      query_string.append( where);
2142
1957
    }
2156
1971
      fputs("\n", md_result_file);
2157
1972
      check_io(md_result_file);
2158
1973
    }
2159
 
    if (drizzle_query_with_error_report(drizzle, 0, query_string.c_str()))
 
1974
    if (drizzleclient_query_with_error_report(drizzle, 0, query_string.c_str()))
2160
1975
    {
2161
 
      DB_error(drizzle, "when retrieving data from server");
 
1976
      DB_error(drizzle, _("when retrieving data from server"));
2162
1977
      goto err;
2163
1978
    }
2164
1979
    if (quick)
2165
 
      res=drizzle_use_result(drizzle);
 
1980
      res=drizzleclient_use_result(drizzle);
2166
1981
    else
2167
 
      res=drizzle_store_result(drizzle);
 
1982
      res=drizzleclient_store_result(drizzle);
2168
1983
    if (!res)
2169
1984
    {
2170
 
      DB_error(drizzle, "when retrieving data from server");
 
1985
      DB_error(drizzle, _("when retrieving data from server"));
2171
1986
      goto err;
2172
1987
    }
2173
1988
 
2174
 
    verbose_msg("-- Retrieving rows...\n");
2175
 
    if (drizzle_num_fields(res) != num_fields)
 
1989
    verbose_msg(_("-- Retrieving rows...\n"));
 
1990
    if (drizzleclient_num_fields(res) != num_fields)
2176
1991
    {
2177
 
      fprintf(stderr,"%s: Error in field count for table: %s !  Aborting.\n",
 
1992
      fprintf(stderr,_("%s: Error in field count for table: %s !  Aborting.\n"),
2178
1993
              my_progname, result_table);
2179
1994
      error= EX_CONSCHECK;
2180
1995
      goto err;
2188
2003
    /* Moved disable keys to after lock per bug 15977 */
2189
2004
    if (opt_disable_keys)
2190
2005
    {
2191
 
      fprintf(md_result_file, "/*!40000 ALTER TABLE %s DISABLE KEYS */;\n",
 
2006
      fprintf(md_result_file, "ALTER TABLE %s DISABLE KEYS;\n",
2192
2007
              opt_quoted_table);
2193
2008
      check_io(md_result_file);
2194
2009
    }
2196
2011
    total_length= opt_net_buffer_length;                /* Force row break */
2197
2012
    row_break=0;
2198
2013
    rownr=0;
2199
 
    init_length=(uint) insert_pat.length()+4;
 
2014
    init_length=(uint32_t) insert_pat.length()+4;
2200
2015
    if (opt_xml)
2201
2016
      print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
2202
2017
              NULL);
2206
2021
      check_io(md_result_file);
2207
2022
    }
2208
2023
 
2209
 
    while ((row= drizzle_fetch_row(res)))
 
2024
    while ((row= drizzleclient_fetch_row(res)))
2210
2025
    {
2211
 
      uint i;
2212
 
      uint32_t *lengths= drizzle_fetch_lengths(res);
 
2026
      uint32_t i;
 
2027
      uint32_t *lengths= drizzleclient_fetch_lengths(res);
2213
2028
      rownr++;
 
2029
      if ((rownr % show_progress_size) == 0)
 
2030
      {
 
2031
        verbose_msg(_("-- %"PRIu32" of ~%"PRIu64" rows dumped for table %s\n"), rownr, total_rows, opt_quoted_table);
 
2032
      }
2214
2033
      if (!extended_insert && !opt_xml)
2215
2034
      {
2216
2035
        fputs(insert_pat.c_str(),md_result_file);
2217
2036
        check_io(md_result_file);
2218
2037
      }
2219
 
      drizzle_field_seek(res,0);
 
2038
      drizzleclient_field_seek(res,0);
2220
2039
 
2221
2040
      if (opt_xml)
2222
2041
      {
2224
2043
        check_io(md_result_file);
2225
2044
      }
2226
2045
 
2227
 
      for (i= 0; i < drizzle_num_fields(res); i++)
 
2046
      for (i= 0; i < drizzleclient_num_fields(res); i++)
2228
2047
      {
2229
2048
        int is_blob;
2230
2049
        uint32_t length= lengths[i];
2231
2050
 
2232
 
        if (!(field= drizzle_fetch_field(res)))
 
2051
        if (!(field= drizzleclient_fetch_field(res)))
2233
2052
          die(EX_CONSCHECK,
2234
 
                      "Not enough fields from table %s! Aborting.\n",
 
2053
                      _("Not enough fields from table %s! Aborting.\n"),
2235
2054
                      result_table);
2236
2055
 
2237
2056
        /*
2245
2064
        if (extended_insert && !opt_xml)
2246
2065
        {
2247
2066
          if (i == 0)
2248
 
            extended_row= "(";
 
2067
          {
 
2068
            extended_row.clear();
 
2069
            extended_row.append("(");
 
2070
          }
2249
2071
          else
2250
2072
            extended_row.append(",");
2251
2073
 
2268
2090
                if (opt_hex_blob && is_blob)
2269
2091
                {
2270
2092
                  extended_row.append("0x");
2271
 
                  drizzle_hex_string(tmp_str, row[i], length);
 
2093
                  drizzleclient_drizzleclient_octet2hex(tmp_str, row[i], length);
2272
2094
                  extended_row.append(tmp_str);
2273
2095
                }
2274
2096
                else
2275
2097
                {
2276
2098
                  extended_row.append("'");
2277
 
                  drizzle_escape_string(tmp_str,
 
2099
                  drizzleclient_escape_string(tmp_str,
2278
2100
                                        row[i],length);
2279
2101
                  extended_row.append(tmp_str);
2280
2102
                  extended_row.append("'");
2322
2144
                }
2323
2145
                else
2324
2146
                {
2325
 
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=", 
 
2147
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2326
2148
                                field->name, NULL);
2327
2149
                  print_quoted_xml(md_result_file, row[i], length);
2328
2150
                }
2411
2233
      fputs(";\n", md_result_file);             /* If not empty table */
2412
2234
    fflush(md_result_file);
2413
2235
    check_io(md_result_file);
2414
 
    if (drizzle_errno(drizzle))
 
2236
    if (drizzleclient_errno(drizzle))
2415
2237
    {
2416
2238
      snprintf(buf, sizeof(buf),
2417
 
               "%s: Error %d: %s when dumping table %s at row: %d\n",
 
2239
               _("%s: Error %d: %s when dumping table %s at row: %d\n"),
2418
2240
               my_progname,
2419
 
               drizzle_errno(drizzle),
2420
 
               drizzle_error(drizzle),
 
2241
               drizzleclient_errno(drizzle),
 
2242
               drizzleclient_error(drizzle),
2421
2243
               result_table,
2422
2244
               rownr);
2423
2245
      fputs(buf,stderr);
2428
2250
    /* Moved enable keys to before unlock per bug 15977 */
2429
2251
    if (opt_disable_keys)
2430
2252
    {
2431
 
      fprintf(md_result_file,"/*!40000 ALTER TABLE %s ENABLE KEYS */;\n",
 
2253
      fprintf(md_result_file,"ALTER TABLE %s ENABLE KEYS;\n",
2432
2254
              opt_quoted_table);
2433
2255
      check_io(md_result_file);
2434
2256
    }
2442
2264
      fprintf(md_result_file, "commit;\n");
2443
2265
      check_io(md_result_file);
2444
2266
    }
2445
 
    drizzle_free_result(res);
 
2267
    drizzleclient_free_result(res);
2446
2268
  }
2447
2269
  return;
2448
2270
 
2459
2281
 
2460
2282
  if (!res)
2461
2283
  {
2462
 
    if (!(res= drizzle_list_tables(drizzle,NULL)))
 
2284
    if (!(res= drizzleclient_list_tables(drizzle,NULL)))
2463
2285
      return(NULL);
2464
2286
  }
2465
 
  if ((row= drizzle_fetch_row(res)))
 
2287
  if ((row= drizzleclient_fetch_row(res)))
2466
2288
    return((char*) row[0]);
2467
2289
 
2468
2290
  if (reset)
2469
 
    drizzle_data_seek(res,0);      /* We want to read again */
 
2291
    drizzleclient_data_seek(res,0);      /* We want to read again */
2470
2292
  else
2471
2293
  {
2472
 
    drizzle_free_result(res);
 
2294
    drizzleclient_free_result(res);
2473
2295
    res= NULL;
2474
2296
  }
2475
2297
  return(NULL);
2482
2304
  DRIZZLE_RES *tableres;
2483
2305
  int result=0;
2484
2306
 
2485
 
  if (drizzle_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
 
2307
  if (drizzleclient_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
2486
2308
    return 1;
2487
 
  while ((row= drizzle_fetch_row(tableres)))
 
2309
  while ((row= drizzleclient_fetch_row(tableres)))
2488
2310
  {
2489
2311
    if (dump_all_tables_in_db(row[0]))
2490
2312
      result=1;
2535
2357
             "SHOW CREATE DATABASE IF NOT EXISTS %s",
2536
2358
             qdatabase);
2537
2359
 
2538
 
    if (drizzle_query(drizzle, qbuf) || !(dbinfo = drizzle_store_result(drizzle)))
 
2360
    if (drizzleclient_query(drizzle, qbuf) || !(dbinfo = drizzleclient_store_result(drizzle)))
2539
2361
    {
2540
2362
      /* Old server version, dump generic CREATE DATABASE */
2541
2363
      if (opt_drop_database)
2542
2364
        fprintf(md_result_file,
2543
 
                "\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
 
2365
                "\nDROP DATABASE IF EXISTS %s;\n",
2544
2366
                qdatabase);
2545
2367
      fprintf(md_result_file,
2546
 
              "\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n",
 
2368
              "\nCREATE DATABASE IF NOT EXISTS %s;\n",
2547
2369
              qdatabase);
2548
2370
    }
2549
2371
    else
2550
2372
    {
2551
2373
      if (opt_drop_database)
2552
2374
        fprintf(md_result_file,
2553
 
                "\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
 
2375
                "\nDROP DATABASE IF EXISTS %s;\n",
2554
2376
                qdatabase);
2555
 
      row = drizzle_fetch_row(dbinfo);
 
2377
      row = drizzleclient_fetch_row(dbinfo);
2556
2378
      if (row[1])
2557
2379
      {
2558
2380
        fprintf(md_result_file,"\n%s;\n",row[1]);
2559
2381
      }
2560
 
      drizzle_free_result(dbinfo);
 
2382
      drizzleclient_free_result(dbinfo);
2561
2383
    }
2562
2384
  }
2563
2385
  return(0);
2566
2388
 
2567
2389
static int init_dumping(char *database, int init_func(char*))
2568
2390
{
2569
 
  if (drizzle_get_server_version(drizzle) >= 50003 &&
 
2391
  if (drizzleclient_get_server_version(drizzle) >= 50003 &&
2570
2392
      !my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
2571
2393
    return 1;
2572
2394
 
2573
 
  if (drizzle_select_db(drizzle, database))
 
2395
  if (drizzleclient_select_db(drizzle, database))
2574
2396
  {
2575
 
    DB_error(drizzle, "when selecting the database");
 
2397
    DB_error(drizzle, _("when selecting the database"));
2576
2398
    return 1;                   /* If --force */
2577
2399
  }
2578
2400
  if (!path && !opt_xml)
2614
2436
static int dump_all_tables_in_db(char *database)
2615
2437
{
2616
2438
  char *table;
2617
 
  uint numrows;
 
2439
  uint32_t numrows;
2618
2440
  char table_buff[NAME_LEN*2+3];
2619
2441
  char hash_key[2*NAME_LEN+2];  /* "db.tablename" */
2620
2442
  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);
 
2443
 
 
2444
  afterdot= strcpy(hash_key, database) + strlen(database);
2625
2445
  *afterdot++= '.';
2626
2446
 
2627
2447
  if (init_dumping(database, init_dumping_tables))
2630
2450
    print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NULL);
2631
2451
  if (lock_tables)
2632
2452
  {
2633
 
    string query;
2634
 
    query= "LOCK TABLES ";
 
2453
    string query("LOCK TABLES ");
2635
2454
    for (numrows= 0 ; (table= getTableName(1)) ; )
2636
2455
    {
2637
 
      char *end= my_stpcpy(afterdot, table);
 
2456
      char *end= strcpy(afterdot, table) + strlen(table);
2638
2457
      if (include_table((unsigned char*) hash_key,end - hash_key))
2639
2458
      {
2640
2459
        numrows++;
2641
2460
        query.append( quote_name(table, table_buff, 1));
2642
 
        query.append( " READ /*!32311 LOCAL */,");
 
2461
        query.append( " READ LOCAL,");
2643
2462
      }
2644
2463
    }
2645
 
    if (numrows && drizzle_real_query(drizzle, query.c_str(), query.length()-1))
2646
 
      DB_error(drizzle, "when using LOCK TABLES");
 
2464
    if (numrows && drizzleclient_real_query(drizzle, query.c_str(), query.length()-1))
 
2465
      DB_error(drizzle, _("when using LOCK TABLES"));
2647
2466
            /* We shall continue here, if --force was given */
2648
2467
    query.clear();
2649
2468
  }
2650
2469
  if (flush_logs)
2651
2470
  {
2652
 
    if (drizzle_refresh(drizzle, REFRESH_LOG))
2653
 
      DB_error(drizzle, "when doing refresh");
 
2471
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
 
2472
      DB_error(drizzle, _("when doing refresh"));
2654
2473
           /* We shall continue here, if --force was given */
2655
2474
  }
2656
2475
  while ((table= getTableName(0)))
2657
2476
  {
2658
 
    char *end= my_stpcpy(afterdot, table);
 
2477
    char *end= strcpy(afterdot, table) + strlen(table);
2659
2478
    if (include_table((unsigned char*) hash_key, end - hash_key))
2660
2479
    {
2661
2480
      dump_table(table,database);
2669
2488
    check_io(md_result_file);
2670
2489
  }
2671
2490
  if (lock_tables)
2672
 
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2673
 
  if (flush_privileges && using_mysql_db == 0)
2674
 
  {
2675
 
    fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
2676
 
    fprintf(md_result_file,"\n/*! FLUSH PRIVILEGES */;\n");
2677
 
  }
 
2491
    drizzleclient_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
 
2492
 
2678
2493
  return(0);
2679
2494
} /* dump_all_tables_in_db */
2680
2495
 
2704
2519
  snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2705
2520
           quote_for_like(old_table_name, show_name_buff));
2706
2521
 
2707
 
  if (drizzle_query_with_error_report(drizzle, 0, query))
 
2522
  if (drizzleclient_query_with_error_report(drizzle, 0, query))
2708
2523
    return NULL;
2709
2524
 
2710
 
  if ((table_res= drizzle_store_result(drizzle)))
 
2525
  if ((table_res= drizzleclient_store_result(drizzle)))
2711
2526
  {
2712
 
    uint64_t num_rows= drizzle_num_rows(table_res);
 
2527
    uint64_t num_rows= drizzleclient_num_rows(table_res);
2713
2528
    if (num_rows > 0)
2714
2529
    {
2715
2530
      uint32_t *lengths;
2717
2532
        Return first row
2718
2533
        TODO: Return all matching rows
2719
2534
      */
2720
 
      row= drizzle_fetch_row(table_res);
2721
 
      lengths= drizzle_fetch_lengths(table_res);
 
2535
      row= drizzleclient_fetch_row(table_res);
 
2536
      lengths= drizzleclient_fetch_lengths(table_res);
2722
2537
      name= strmake_root(root, row[0], lengths[0]);
2723
2538
    }
2724
 
    drizzle_free_result(table_res);
 
2539
    drizzleclient_free_result(table_res);
2725
2540
  }
2726
2541
  return(name);
2727
2542
}
2730
2545
static int dump_selected_tables(char *db, char **table_names, int tables)
2731
2546
{
2732
2547
  char table_buff[NAME_LEN*2+3];
2733
 
  string lock_tables_query;
 
2548
  string lock_tables_query("LOCK TABLES ");
2734
2549
  MEM_ROOT root;
2735
2550
  char **dump_tables, **pos, **end;
2736
2551
 
2740
2555
 
2741
2556
  init_alloc_root(&root, 8192, 0);
2742
2557
  if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
2743
 
     die(EX_EOM, "alloc_root failure.");
 
2558
     die(EX_EOM, _("alloc_root failure."));
2744
2559
 
2745
 
  lock_tables_query= "LOCK TABLES ";
2746
2560
  for (; tables > 0 ; tables-- , table_names++)
2747
2561
  {
2748
2562
    /* the table name passed on commandline may be wrong case */
2752
2566
      if (lock_tables)
2753
2567
      {
2754
2568
        lock_tables_query.append( quote_name(*pos, table_buff, 1));
2755
 
        lock_tables_query.append( " READ /*!32311 LOCAL */,");
 
2569
        lock_tables_query.append( " READ LOCAL,");
2756
2570
      }
2757
2571
      pos++;
2758
2572
    }
2762
2576
      {
2763
2577
        free_root(&root, MYF(0));
2764
2578
      }
2765
 
      maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names);
 
2579
      maybe_die(EX_ILLEGAL_TABLE, _("Couldn't find table: \"%s\""), *table_names);
2766
2580
      /* We shall countinue here, if --force was given */
2767
2581
    }
2768
2582
  }
2770
2584
 
2771
2585
  if (lock_tables)
2772
2586
  {
2773
 
    if (drizzle_real_query(drizzle, lock_tables_query.c_str(),
 
2587
    if (drizzleclient_real_query(drizzle, lock_tables_query.c_str(),
2774
2588
                         lock_tables_query.length()-1))
2775
2589
    {
2776
2590
      if (!ignore_errors)
2777
2591
      {
2778
2592
        free_root(&root, MYF(0));
2779
2593
      }
2780
 
      DB_error(drizzle, "when doing LOCK TABLES");
 
2594
      DB_error(drizzle, _("when doing LOCK TABLES"));
2781
2595
       /* We shall countinue here, if --force was given */
2782
2596
    }
2783
2597
  }
2784
2598
  if (flush_logs)
2785
2599
  {
2786
 
    if (drizzle_refresh(drizzle, REFRESH_LOG))
 
2600
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
2787
2601
    {
2788
2602
      if (!ignore_errors)
2789
2603
        free_root(&root, MYF(0));
2790
 
      DB_error(drizzle, "when doing refresh");
 
2604
      DB_error(drizzle, _("when doing refresh"));
2791
2605
    }
2792
2606
     /* We shall countinue here, if --force was given */
2793
2607
  }
2807
2621
    check_io(md_result_file);
2808
2622
  }
2809
2623
  if (lock_tables)
2810
 
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
 
2624
    drizzleclient_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2811
2625
  return(0);
2812
2626
} /* dump_selected_tables */
2813
2627
 
2818
2632
  DRIZZLE_RES *master;
2819
2633
  const char *comment_prefix=
2820
2634
    (opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2821
 
  if (drizzle_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
 
2635
  if (drizzleclient_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
2822
2636
  {
2823
2637
    return 1;
2824
2638
  }
2825
2639
  else
2826
2640
  {
2827
 
    row= drizzle_fetch_row(master);
 
2641
    row= drizzleclient_fetch_row(master);
2828
2642
    if (row && row[0] && row[1])
2829
2643
    {
2830
2644
      /* SHOW MASTER STATUS reports file and position */
2840
2654
    else if (!ignore_errors)
2841
2655
    {
2842
2656
      /* SHOW MASTER STATUS reports nothing and --force is not enabled */
2843
 
      my_printf_error(0, "Error: Binlogging on server not active",
 
2657
      my_printf_error(0, _("Error: Binlogging on server not active"),
2844
2658
                      MYF(0));
2845
 
      drizzle_free_result(master);
 
2659
      drizzleclient_free_result(master);
2846
2660
      maybe_exit(EX_DRIZZLEERR);
2847
2661
      return 1;
2848
2662
    }
2849
 
    drizzle_free_result(master);
 
2663
    drizzleclient_free_result(master);
2850
2664
  }
2851
2665
  return 0;
2852
2666
}
2855
2669
{
2856
2670
  DRIZZLE_RES *slave;
2857
2671
  /* 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"))
 
2672
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2859
2673
    return(1);
2860
2674
  else
2861
2675
  {
2862
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
 
2676
    DRIZZLE_ROW row= drizzleclient_fetch_row(slave);
2863
2677
    if (row && row[11])
2864
2678
    {
2865
2679
      /* if SLAVE SQL is not running, we don't stop it */
2866
2680
      if (!strcmp(row[11],"No"))
2867
2681
      {
2868
 
        drizzle_free_result(slave);
 
2682
        drizzleclient_free_result(slave);
2869
2683
        /* Silently assume that they don't have the slave running */
2870
2684
        return(0);
2871
2685
      }
2872
2686
    }
2873
2687
  }
2874
 
  drizzle_free_result(slave);
 
2688
  drizzleclient_free_result(slave);
2875
2689
 
2876
2690
  /* now, stop slave if running */
2877
 
  if (drizzle_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
 
2691
  if (drizzleclient_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
2878
2692
    return(1);
2879
2693
 
2880
2694
  return(0);
2903
2717
  DRIZZLE_RES *slave;
2904
2718
  const char *comment_prefix=
2905
2719
    (opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2906
 
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
 
2720
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2907
2721
  {
2908
2722
    if (!ignore_errors)
2909
2723
    {
2910
2724
      /* SHOW SLAVE STATUS reports nothing and --force is not enabled */
2911
 
      my_printf_error(0, "Error: Slave not set up", MYF(0));
 
2725
      my_printf_error(0, _("Error: Slave not set up"), MYF(0));
2912
2726
    }
2913
2727
    return 1;
2914
2728
  }
2915
2729
  else
2916
2730
  {
2917
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
 
2731
    DRIZZLE_ROW row= drizzleclient_fetch_row(slave);
2918
2732
    if (row && row[9] && row[21])
2919
2733
    {
2920
2734
      /* SHOW MASTER STATUS reports file and position */
2937
2751
 
2938
2752
      check_io(md_result_file);
2939
2753
    }
2940
 
    drizzle_free_result(slave);
 
2754
    drizzleclient_free_result(slave);
2941
2755
  }
2942
2756
  return 0;
2943
2757
}
2946
2760
{
2947
2761
  DRIZZLE_RES *slave;
2948
2762
  /* 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"))
 
2763
  if (drizzleclient_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2950
2764
    return(1);
2951
2765
  else
2952
2766
  {
2953
 
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
 
2767
    DRIZZLE_ROW row= drizzleclient_fetch_row(slave);
2954
2768
    if (row && row[11])
2955
2769
    {
2956
2770
      /* if SLAVE SQL is not running, we don't start it */
2957
2771
      if (!strcmp(row[11],"Yes"))
2958
2772
      {
2959
 
        drizzle_free_result(slave);
 
2773
        drizzleclient_free_result(slave);
2960
2774
        /* Silently assume that they don't have the slave running */
2961
2775
        return(0);
2962
2776
      }
2963
2777
    }
2964
2778
  }
2965
 
  drizzle_free_result(slave);
 
2779
  drizzleclient_free_result(slave);
2966
2780
 
2967
2781
  /* now, start slave if stopped */
2968
 
  if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
 
2782
  if (drizzleclient_query_with_error_report(drizzle_con, 0, "START SLAVE"))
2969
2783
  {
2970
 
    my_printf_error(0, "Error: Unable to start slave", MYF(0));
 
2784
    my_printf_error(0, _("Error: Unable to start slave"), MYF(0));
2971
2785
    return 1;
2972
2786
  }
2973
2787
  return(0);
2986
2800
    update starts between the two FLUSHes, we have that bad stall.
2987
2801
  */
2988
2802
  return
2989
 
    ( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
2990
 
      drizzle_query_with_error_report(drizzle_con, 0,
 
2803
    ( drizzleclient_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
 
2804
      drizzleclient_query_with_error_report(drizzle_con, 0,
2991
2805
                                    "FLUSH TABLES WITH READ LOCK") );
2992
2806
}
2993
2807
 
2994
2808
 
2995
2809
static int do_unlock_tables(DRIZZLE *drizzle_con)
2996
2810
{
2997
 
  return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
 
2811
  return drizzleclient_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
2998
2812
}
2999
2813
 
3000
2814
static int get_bin_log_name(DRIZZLE *drizzle_con,
3001
 
                            char* buff_log_name, uint buff_len)
 
2815
                            char* buff_log_name, uint32_t buff_len)
3002
2816
{
3003
2817
  DRIZZLE_RES *res;
3004
2818
  DRIZZLE_ROW row;
3005
2819
 
3006
 
  if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
3007
 
      !(res= drizzle_store_result(drizzle)))
 
2820
  if (drizzleclient_query(drizzle_con, "SHOW MASTER STATUS") ||
 
2821
      !(res= drizzleclient_store_result(drizzle)))
3008
2822
    return 1;
3009
2823
 
3010
 
  if (!(row= drizzle_fetch_row(res)))
 
2824
  if (!(row= drizzleclient_fetch_row(res)))
3011
2825
  {
3012
 
    drizzle_free_result(res);
 
2826
    drizzleclient_free_result(res);
3013
2827
    return 1;
3014
2828
  }
3015
2829
  /*
3016
2830
    Only one row is returned, and the first column is the name of the
3017
2831
    active log.
3018
2832
  */
3019
 
  strmake(buff_log_name, row[0], buff_len - 1);
 
2833
  strncpy(buff_log_name, row[0], buff_len - 1);
3020
2834
 
3021
 
  drizzle_free_result(res);
 
2835
  drizzleclient_free_result(res);
3022
2836
  return 0;
3023
2837
}
3024
2838
 
3028
2842
  string str= "PURGE BINARY LOGS TO '";
3029
2843
  str.append(log_name);
3030
2844
  str.append("'");
3031
 
  err = drizzle_query_with_error_report(drizzle_con, 0, str.c_str());
 
2845
  err = drizzleclient_query_with_error_report(drizzle_con, 0, str.c_str());
3032
2846
  return err;
3033
2847
}
3034
2848
 
3035
2849
 
3036
2850
static int start_transaction(DRIZZLE *drizzle_con)
3037
2851
{
3038
 
  /*
3039
 
    We use BEGIN for old servers. --single-transaction --master-data will fail
3040
 
    on old servers, but that's ok as it was already silently broken (it didn't
3041
 
    do a consistent read, so better tell people frankly, with the error).
3042
 
 
3043
 
    We want the first consistent read to be used for all tables to dump so we
3044
 
    need the REPEATABLE READ level (not anything lower, for example READ
3045
 
    COMMITTED would give one new consistent read per dumped table).
3046
 
  */
3047
 
  if ((drizzle_get_server_version(drizzle_con) < 40100) && opt_master_data)
3048
 
  {
3049
 
    fprintf(stderr, "-- %s: the combination of --single-transaction and "
3050
 
            "--master-data requires a DRIZZLE server version of at least 4.1 "
3051
 
            "(current server's version is %s). %s\n",
3052
 
            ignore_errors ? "Warning" : "Error",
3053
 
            drizzle_con->server_version ? drizzle_con->server_version : "unknown",
3054
 
            ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3055
 
    if (!ignore_errors)
3056
 
      exit(EX_DRIZZLEERR);
3057
 
  }
3058
 
 
3059
 
  return (drizzle_query_with_error_report(drizzle_con, 0,
 
2852
  return (drizzleclient_query_with_error_report(drizzle_con, 0,
3060
2853
                                        "SET SESSION TRANSACTION ISOLATION "
3061
2854
                                        "LEVEL REPEATABLE READ") ||
3062
 
          drizzle_query_with_error_report(drizzle_con, 0,
 
2855
          drizzleclient_query_with_error_report(drizzle_con, 0,
3063
2856
                                        "START TRANSACTION "
3064
 
                                        "/*!40100 WITH CONSISTENT SNAPSHOT */"));
 
2857
                                        "WITH CONSISTENT SNAPSHOT"));
3065
2858
}
3066
2859
 
3067
2860
 
3068
 
static uint32_t find_set(TYPELIB *lib, const char *x, uint length,
3069
 
                      char **err_pos, uint *err_len)
 
2861
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
 
2862
                      char **err_pos, uint32_t *err_len)
3070
2863
{
3071
2864
  const char *end= x + length;
3072
2865
  uint32_t found= 0;
3073
 
  uint find;
 
2866
  uint32_t find;
3074
2867
  char buff[255];
3075
2868
 
3076
2869
  *err_pos= 0;                  /* No error yet */
3088
2881
 
3089
2882
      for (; pos != end && *pos != ','; pos++) ;
3090
2883
      var_len= (uint32_t) (pos - start);
3091
 
      strmake(buff, start, min((uint32_t)sizeof(buff), var_len));
 
2884
      strncpy(buff, start, min((uint32_t)sizeof(buff), var_len));
3092
2885
      find= find_type(buff, lib, var_len);
3093
2886
      if (!find)
3094
2887
      {
3096
2889
        *err_len= var_len;
3097
2890
      }
3098
2891
      else
3099
 
        found|= ((int64_t) 1 << (find - 1));
 
2892
        found|= (uint32_t)((int64_t) 1 << (find - 1));
3100
2893
      if (pos == end)
3101
2894
        break;
3102
2895
      start= pos + 1;
3112
2905
                        int string_value)
3113
2906
{
3114
2907
  DRIZZLE_FIELD   *field;
3115
 
  drizzle_field_seek(result, 0);
 
2908
  drizzleclient_field_seek(result, 0);
3116
2909
 
3117
 
  for ( ; (field= drizzle_fetch_field(result)) ; row++)
 
2910
  for ( ; (field= drizzleclient_fetch_field(result)) ; row++)
3118
2911
  {
3119
2912
    if (!strcmp(field->name,name))
3120
2913
    {
3123
2916
        fputc(' ',file);
3124
2917
        fputs(prefix, file);
3125
2918
        if (string_value)
3126
 
          unescape(file,row[0],(uint) strlen(row[0]));
 
2919
          unescape(file,row[0],(uint32_t) strlen(row[0]));
3127
2920
        else
3128
2921
          fputs(row[0], file);
3129
2922
        check_io(file);
3134
2927
  return;                                       /* This shouldn't happen */
3135
2928
} /* print_value */
3136
2929
 
 
2930
/**
 
2931
 * Fetches a row from a result based on a field name
 
2932
 * Returns const char* of the data in that row or NULL if not found
 
2933
 */
 
2934
 
 
2935
static const char* fetch_named_row(DRIZZLE_RES *result, DRIZZLE_ROW row, const char *name)
 
2936
{
 
2937
  DRIZZLE_FIELD   *field;
 
2938
  drizzleclient_field_seek(result, 0);
 
2939
  for ( ; (field= drizzleclient_fetch_field(result)) ; row++)
 
2940
  {
 
2941
    if (!strcmp(field->name,name))
 
2942
    {
 
2943
      if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */
 
2944
      {
 
2945
        drizzleclient_field_seek(result, 0);
 
2946
        return row[0];
 
2947
      }
 
2948
    }
 
2949
  }
 
2950
  drizzleclient_field_seek(result, 0);
 
2951
  return NULL;
 
2952
}
 
2953
 
3137
2954
 
3138
2955
/*
3139
2956
  SYNOPSIS
3163
2980
{
3164
2981
  char result= IGNORE_NONE;
3165
2982
  char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
 
2983
  const char *number_of_rows= NULL;
3166
2984
  DRIZZLE_RES *res= NULL;
3167
2985
  DRIZZLE_ROW row;
3168
2986
 
3169
 
 
3170
2987
  /* Check memory for quote_for_like() */
3171
2988
  assert(2*sizeof(table_name) < sizeof(show_name_buff));
3172
2989
  snprintf(buff, sizeof(buff), "show table status like %s",
3173
2990
           quote_for_like(table_name, show_name_buff));
3174
 
  if (drizzle_query_with_error_report(drizzle, &res, buff))
 
2991
  if (drizzleclient_query_with_error_report(drizzle, &res, buff))
3175
2992
  {
3176
 
    if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
 
2993
    if (drizzleclient_errno(drizzle) != ER_PARSE_ERROR)
3177
2994
    {                                   /* If old DRIZZLE version */
3178
 
      verbose_msg("-- Warning: Couldn't get status information for "
3179
 
                  "table %s (%s)\n", table_name, drizzle_error(drizzle));
 
2995
      verbose_msg(_("-- Warning: Couldn't get status information for "
 
2996
                  "table %s (%s)\n"), table_name, drizzleclient_error(drizzle));
3180
2997
      return(result);                       /* assume table is ok */
3181
2998
    }
3182
2999
  }
3183
 
  if (!(row= drizzle_fetch_row(res)))
 
3000
  if (!(row= drizzleclient_fetch_row(res)))
3184
3001
  {
3185
3002
    fprintf(stderr,
3186
 
            "Error: Couldn't read status information for table %s (%s)\n",
3187
 
            table_name, drizzle_error(drizzle));
3188
 
    drizzle_free_result(res);
 
3003
            _("Error: Couldn't read status information for table %s (%s)\n"),
 
3004
            table_name, drizzleclient_error(drizzle));
 
3005
    drizzleclient_free_result(res);
3189
3006
    return(result);                         /* assume table is ok */
3190
3007
  }
3191
 
  if (!(row[1]))
3192
 
    strmake(table_type, "VIEW", NAME_LEN-1);
3193
3008
  else
3194
3009
  {
3195
 
    /*
3196
 
      If the table type matches any of these, we do support delayed inserts.
3197
 
      Note: we do not want to skip dumping this table if if is not one of
3198
 
      these types, but we do want to use delayed inserts in the dump if
3199
 
      the table type is _NOT_ one of these types
 
3010
    if ((number_of_rows= fetch_named_row(res, row, "Rows")) != NULL)
 
3011
    {
 
3012
      total_rows= strtoul(number_of_rows, NULL, 10);
 
3013
    }
 
3014
  }
 
3015
  /*
 
3016
    If the table type matches any of these, we do support delayed inserts.
 
3017
    Note: we do not want to skip dumping this table if if is not one of
 
3018
    these types, but we do want to use delayed inserts in the dump if
 
3019
    the table type is _NOT_ one of these types
3200
3020
    */
3201
 
    strmake(table_type, row[1], NAME_LEN-1);
 
3021
  {
 
3022
    strncpy(table_type, row[1], NAME_LEN-1);
3202
3023
    if (opt_delayed)
3203
3024
    {
3204
3025
      if (strcmp(table_type,"MyISAM") &&
3205
 
          strcmp(table_type,"ISAM") &&
3206
3026
          strcmp(table_type,"ARCHIVE") &&
3207
3027
          strcmp(table_type,"HEAP") &&
3208
3028
          strcmp(table_type,"MEMORY"))
3209
3029
        result= IGNORE_INSERT_DELAYED;
3210
3030
    }
3211
 
 
3212
 
    /*
3213
 
      If these two types, we do want to skip dumping the table
3214
 
    */
3215
 
    if (!opt_no_data &&
3216
 
        (!my_strcasecmp(&my_charset_utf8_general_ci, table_type, "MRG_MyISAM") ||
3217
 
         !strcmp(table_type,"MRG_ISAM")))
3218
 
      result= IGNORE_DATA;
3219
3031
  }
3220
 
  drizzle_free_result(res);
 
3032
  drizzleclient_free_result(res);
3221
3033
  return(result);
3222
3034
}
3223
3035
 
3246
3058
  DRIZZLE_ROW  row;
3247
3059
  /* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3248
3060
  char show_keys_buff[15 + NAME_LEN * 2 + 3];
3249
 
  uint result_length= 0;
 
3061
  uint32_t result_length= 0;
3250
3062
  char *result= 0;
3251
3063
  char buff[NAME_LEN * 2 + 3];
3252
3064
  char *quoted_field;
3253
3065
 
3254
3066
  snprintf(show_keys_buff, sizeof(show_keys_buff),
3255
3067
           "SHOW KEYS FROM %s", table_name);
3256
 
  if (drizzle_query(drizzle, show_keys_buff) ||
3257
 
      !(res= drizzle_store_result(drizzle)))
 
3068
  if (drizzleclient_query(drizzle, show_keys_buff) ||
 
3069
      !(res= drizzleclient_store_result(drizzle)))
3258
3070
  {
3259
 
    fprintf(stderr, "Warning: Couldn't read keys from table %s;"
3260
 
            " records are NOT sorted (%s)\n",
3261
 
            table_name, drizzle_error(drizzle));
 
3071
    fprintf(stderr, _("Warning: Couldn't read keys from table %s;"
 
3072
            " records are NOT sorted (%s)\n"),
 
3073
            table_name, drizzleclient_error(drizzle));
3262
3074
    /* Don't exit, because it's better to print out unsorted records */
3263
3075
    goto cleanup;
3264
3076
  }
3269
3081
   * row, and UNIQUE keys come before others.  So we only need to check
3270
3082
   * the first key, not all keys.
3271
3083
   */
3272
 
  if ((row= drizzle_fetch_row(res)) && atoi(row[1]) == 0)
 
3084
  if ((row= drizzleclient_fetch_row(res)) && atoi(row[1]) == 0)
3273
3085
  {
3274
3086
    /* Key is unique */
3275
3087
    do
3276
3088
    {
3277
3089
      quoted_field= quote_name(row[4], buff, 0);
3278
3090
      result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3279
 
    } while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1);
 
3091
    } while ((row= drizzleclient_fetch_row(res)) && atoi(row[3]) > 1);
3280
3092
  }
3281
3093
 
3282
3094
  /* Build the ORDER BY clause result */
3284
3096
  {
3285
3097
    char *end;
3286
3098
    /* result (terminating \0 is already in result_length) */
3287
 
    result= (char *)my_malloc(result_length + 10, MYF(MY_WME));
 
3099
    result= (char *)malloc(result_length + 10);
3288
3100
    if (!result)
3289
3101
    {
3290
 
      fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n");
 
3102
      fprintf(stderr, _("Error: Not enough memory to store ORDER BY clause\n"));
3291
3103
      goto cleanup;
3292
3104
    }
3293
 
    drizzle_data_seek(res, 0);
3294
 
    row= drizzle_fetch_row(res);
 
3105
    drizzleclient_data_seek(res, 0);
 
3106
    row= drizzleclient_fetch_row(res);
3295
3107
    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)
 
3108
    end= strcpy(result, quoted_field) + strlen(quoted_field);
 
3109
    while ((row= drizzleclient_fetch_row(res)) && atoi(row[3]) > 1)
3298
3110
    {
3299
3111
      quoted_field= quote_name(row[4], buff, 0);
3300
 
      end= strxmov(end, ",", quoted_field, NULL);
 
3112
      end+= sprintf(end,",%s",quoted_field);
3301
3113
    }
3302
3114
  }
3303
3115
 
3304
3116
cleanup:
3305
3117
  if (res)
3306
 
    drizzle_free_result(res);
 
3118
    drizzleclient_free_result(res);
3307
3119
 
3308
3120
  return result;
3309
3121
}
3313
3125
{
3314
3126
  char bin_log_name[FN_REFLEN];
3315
3127
  int exit_code;
3316
 
  MY_INIT("mysqldump");
 
3128
  MY_INIT("drizzledump");
3317
3129
 
3318
3130
  compatible_mode_normal_str[0]= 0;
3319
3131
  default_charset= (char *)drizzle_universal_client_charset;
3326
3138
    exit(exit_code);
3327
3139
  }
3328
3140
 
3329
 
  if (log_error_file)
3330
 
  {
3331
 
    if(!(stderror_file= freopen(log_error_file, "a+", stderr)))
3332
 
    {
3333
 
      free_resources();
3334
 
      exit(EX_DRIZZLEERR);
3335
 
    }
3336
 
  }
3337
 
 
3338
3141
  if (connect_to_db(current_host, current_user, opt_password))
3339
3142
  {
3340
3143
    free_resources();
3353
3156
      goto err;
3354
3157
  if (opt_delete_master_logs)
3355
3158
  {
3356
 
    if (drizzle_refresh(drizzle, REFRESH_LOG) ||
 
3159
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")) ||
3357
3160
        get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
3358
3161
      goto err;
3359
3162
    flush_logs= 0;
3360
3163
  }
3361
3164
  if (opt_lock_all_tables || opt_master_data)
3362
3165
  {
3363
 
    if (flush_logs && drizzle_refresh(drizzle, REFRESH_LOG))
 
3166
    if (drizzleclient_real_query(drizzle, "FLUSH LOGS", strlen("FLUSH LOGS")))
3364
3167
      goto err;
3365
3168
    flush_logs= 0; /* not anymore; that would not be sensible */
3366
3169
  }