~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Andrew Hutchings
  • Date: 2010-09-08 19:03:09 UTC
  • mfrom: (1750 staging)
  • mto: (1750.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1751.
  • Revision ID: andrew@linuxjedi.co.uk-20100908190309-mya1nu7xvo1fpvk8
Merge trunk into branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright 2000-2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
 
2
 * Copyright (C) 2010 Vijay Samuel
2
3
 
3
4
  This program is free software; you can redistribute it and/or modify
4
5
  it under the terms of the GNU General Public License as published by
77
78
 
78
79
static void add_load_option(string &str, const char *option,
79
80
                            const string &option_value);
80
 
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
81
 
                         char **err_pos, uint32_t *err_len);
82
81
 
83
82
static void field_escape(string &in, const string &from);
84
83
static bool  verbose= false;
85
84
static bool opt_no_create_info;
86
85
static bool opt_no_data= false;
87
 
static bool opt_mysql= false;
 
86
static bool use_drizzle_protocol= false;
88
87
static bool quick= true;
89
88
static bool extended_insert= true;
90
89
static bool ignore_errors= false;
113
112
static bool opt_complete_insert= false;
114
113
static bool opt_drop_database;
115
114
static bool opt_replace_into= false;
116
 
static bool opt_routines= false;
117
115
static bool opt_alltspcs= false;
118
116
static uint32_t show_progress_size= 0;
119
117
static uint64_t total_rows= 0;
121
119
static drizzle_con_st dcon;
122
120
static string insert_pat;
123
121
static char *order_by= NULL;
124
 
static char *err_ptr= NULL;
125
 
static char compatible_mode_normal_str[255];
126
 
static uint32_t opt_compatible_mode= 0;
127
122
static uint32_t opt_drizzle_port= 0;
128
123
static int first_error= 0;
129
124
static string extended_row;
130
125
FILE *md_result_file= 0;
131
126
FILE *stderror_file= 0;
132
127
 
 
128
const string progname= "drizzledump";
 
129
 
133
130
string password,
134
 
  opt_compatible_mode_str,
135
131
  enclosed,
136
132
  escaped,
137
133
  current_host,
141
137
  lines_terminated,
142
138
  current_user,
143
139
  opt_password,
 
140
  opt_protocol,
144
141
  where;
145
142
 
146
143
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
147
144
 
148
 
static const char *compatible_mode_names[]=
149
 
{
150
 
  "MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
151
 
  "MAXDB", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS",
152
 
  "ANSI",
153
 
  NULL
154
 
};
155
 
static TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
156
 
  "", compatible_mode_names, NULL};
157
 
 
158
145
boost::unordered_set<string> ignore_table;
159
146
 
160
147
static void maybe_exit(int error);
293
280
                ! fields_terminated.empty()))
294
281
  {
295
282
    fprintf(stderr,
296
 
            _("%s: You must use option --tab with --fields-...\n"), internal::my_progname);
 
283
            _("%s: You must use option --tab with --fields-...\n"), progname.c_str());
297
284
    return(EX_USAGE);
298
285
  }
299
286
 
300
287
  if (opt_single_transaction && opt_lock_all_tables)
301
288
  {
302
289
    fprintf(stderr, _("%s: You can't use --single-transaction and "
303
 
                      "--lock-all-tables at the same time.\n"), internal::my_progname);
 
290
                      "--lock-all-tables at the same time.\n"), progname.c_str());
304
291
    return(EX_USAGE);
305
292
  }
306
293
  if (! enclosed.empty() && ! opt_enclosed.empty())
307
294
  {
308
 
    fprintf(stderr, _("%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n"), internal::my_progname);
 
295
    fprintf(stderr, _("%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n"), progname.c_str());
309
296
    return(EX_USAGE);
310
297
  }
311
298
  if ((opt_databases || opt_alldbs) && ! path.empty())
312
299
  {
313
300
    fprintf(stderr,
314
301
            _("%s: --databases or --all-databases can't be used with --tab.\n"),
315
 
            internal::my_progname);
 
302
            progname.c_str());
316
303
    return(EX_USAGE);
317
304
  }
318
305
 
365
352
  vsnprintf(buffer, sizeof(buffer), fmt_reason, args);
366
353
  va_end(args);
367
354
 
368
 
  fprintf(stderr, "%s: %s\n", internal::my_progname, buffer);
 
355
  fprintf(stderr, "%s: %s\n", progname.c_str(), buffer);
369
356
  fflush(stderr);
370
357
 
371
358
  ignore_errors= 0; /* force the exit */
399
386
  vsnprintf(buffer, sizeof(buffer), fmt_reason, args);
400
387
  va_end(args);
401
388
 
402
 
  fprintf(stderr, "%s: %s\n", internal::my_progname, buffer);
 
389
  fprintf(stderr, "%s: %s\n", progname.c_str(), buffer);
403
390
  fflush(stderr);
404
391
 
405
392
  maybe_exit(error_num);
515
502
{
516
503
  drizzle_return_t ret;
517
504
 
518
 
  verbose_msg(_("-- Connecting to %s...\n"), ! host.empty() ? (char *)host.c_str() : "localhost");
 
505
  verbose_msg(_("-- Connecting to %s, using protocol %s...\n"), ! host.empty() ? (char *)host.c_str() : "localhost", opt_protocol.c_str());
519
506
  drizzle_create(&drizzle);
520
507
  drizzle_con_create(&drizzle, &dcon);
521
508
  drizzle_con_set_tcp(&dcon, (char *)host.c_str(), opt_drizzle_port);
522
509
  drizzle_con_set_auth(&dcon, (char *)user.c_str(), (char *)passwd.c_str());
523
 
  if (opt_mysql)
524
 
    drizzle_con_add_options(&dcon, DRIZZLE_CON_MYSQL);
 
510
  drizzle_con_add_options(&dcon, use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
525
511
  ret= drizzle_con_connect(&dcon);
526
512
  if (ret != DRIZZLE_RETURN_OK)
527
513
  {
1022
1008
  else
1023
1009
  {
1024
1010
    verbose_msg(_("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n"),
1025
 
                internal::my_progname, drizzle_con_error(&dcon));
 
1011
                progname.c_str(), drizzle_con_error(&dcon));
1026
1012
 
1027
1013
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1028
1014
             result_table);
1129
1115
      if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1130
1116
      {
1131
1117
        fprintf(stderr, _("%s: Can't get keys for table %s\n"),
1132
 
                internal::my_progname, result_table);
 
1118
                progname.c_str(), result_table);
1133
1119
        if (! path.empty())
1134
1120
          fclose(sql_file);
1135
1121
        return false;
1493
1479
    if (drizzle_result_column_count(&result) != num_fields)
1494
1480
    {
1495
1481
      fprintf(stderr,_("%s: Error in field count for table: %s !  Aborting.\n"),
1496
 
              internal::my_progname, result_table);
 
1482
              progname.c_str(), result_table);
1497
1483
      error= EX_CONSCHECK;
1498
1484
      drizzle_result_free(&result);
1499
1485
      goto err;
1537
1523
        {
1538
1524
          fprintf(stderr,
1539
1525
                  _("%s: Error reading rows for table: %s (%d:%s) ! Aborting.\n"),
1540
 
                  internal::my_progname, result_table, ret, drizzle_con_error(&dcon));
 
1526
                  progname.c_str(), result_table, ret, drizzle_con_error(&dcon));
1541
1527
          drizzle_result_free(&result);
1542
1528
          goto err;
1543
1529
        }
2162
2148
}
2163
2149
 
2164
2150
 
2165
 
static uint32_t find_set(TYPELIB *lib, const char *x, uint32_t length,
2166
 
                         char **err_pos, uint32_t *err_len)
2167
 
{
2168
 
  const char *end= x + length;
2169
 
  uint32_t found= 0;
2170
 
  uint32_t find;
2171
 
  char buff[255];
2172
 
 
2173
 
  *err_pos= 0;                  /* No error yet */
2174
 
  while (end > x && my_isspace(charset_info, end[-1]))
2175
 
    end--;
2176
 
 
2177
 
  *err_len= 0;
2178
 
  if (x != end)
2179
 
  {
2180
 
    const char *start= x;
2181
 
    for (;;)
2182
 
    {
2183
 
      const char *pos= start;
2184
 
      uint32_t var_len;
2185
 
 
2186
 
      for (; pos != end && *pos != ','; pos++) ;
2187
 
      var_len= (uint32_t) (pos - start);
2188
 
      strncpy(buff, start, min((uint32_t)sizeof(buff), var_len+1));
2189
 
      find= find_type(buff, lib, var_len);
2190
 
      if (!find)
2191
 
      {
2192
 
        *err_pos= (char*) start;
2193
 
        *err_len= var_len;
2194
 
      }
2195
 
      else
2196
 
        found|= (uint32_t)((int64_t) 1 << (find - 1));
2197
 
      if (pos == end)
2198
 
        break;
2199
 
      start= pos + 1;
2200
 
    }
2201
 
  }
2202
 
  return found;
2203
 
}
2204
 
 
2205
 
 
2206
2151
/* Print a value with a prefix on file */
2207
2152
static void print_value(FILE *file, drizzle_result_st  *result, drizzle_row_t row,
2208
2153
                        const char *prefix, const char *name,
2446
2391
try
2447
2392
{
2448
2393
  int exit_code;
2449
 
  MY_INIT("drizzledump");
2450
2394
  drizzle_result_st result;
2451
2395
 
2452
 
  po::options_description commandline_options("Options used only in command line");
 
2396
  po::options_description commandline_options(N_("Options used only in command line"));
2453
2397
  commandline_options.add_options()
2454
2398
  ("all-databases,A", po::value<bool>(&opt_alldbs)->default_value(false)->zero_tokens(),
2455
 
  "Dump all the databases. This will be same as --databases with all databases selected.")
 
2399
  N_("Dump all the databases. This will be same as --databases with all databases selected."))
2456
2400
  ("all-tablespaces,Y", po::value<bool>(&opt_alltspcs)->default_value(false)->zero_tokens(),
2457
 
  "Dump all the tablespaces.")
 
2401
  N_("Dump all the tablespaces."))
2458
2402
  ("complete-insert,c", po::value<bool>(&opt_complete_insert)->default_value(false)->zero_tokens(),
2459
 
  "Use complete insert statements.")
 
2403
  N_("Use complete insert statements."))
2460
2404
  ("compress,C", po::value<bool>(&opt_compress)->default_value(false)->zero_tokens(),
2461
 
  "Use compression in server/client protocol.")
 
2405
  N_("Use compression in server/client protocol."))
2462
2406
  ("flush-logs,F", po::value<bool>(&flush_logs)->default_value(false)->zero_tokens(),
2463
 
  "Flush logs file in server before starting dump. Note that if you dump many databases at once (using the option --databases= or --all-databases), the logs will be flushed for each database dumped. The exception is when using --lock-all-tables in this case the logs will be flushed only once, corresponding to the moment all tables are locked. So if you want your dump and the log flush to happen at the same exact moment you should use --lock-all-tables or --flush-logs")
 
2407
  N_("Flush logs file in server before starting dump. Note that if you dump many databases at once (using the option --databases= or --all-databases), the logs will be flushed for each database dumped. The exception is when using --lock-all-tables in this case the logs will be flushed only once, corresponding to the moment all tables are locked. So if you want your dump and the log flush to happen at the same exact moment you should use --lock-all-tables or --flush-logs"))
2464
2408
  ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
2465
 
  "Continue even if we get an sql-error.")
2466
 
  ("help,?", "Display this help message and exit.")
 
2409
  N_("Continue even if we get an sql-error."))
 
2410
  ("help,?", N_("Display this help message and exit."))
2467
2411
  ("lock-all-tables,x", po::value<bool>(&opt_lock_all_tables)->default_value(false)->zero_tokens(),
2468
 
  "Locks all tables across all databases. This is achieved by taking a global read lock for the duration of the whole dump. Automatically turns --single-transaction and --lock-tables off.")
 
2412
  N_("Locks all tables across all databases. This is achieved by taking a global read lock for the duration of the whole dump. Automatically turns --single-transaction and --lock-tables off."))
2469
2413
  ("order-by-primary", po::value<bool>(&opt_order_by_primary)->default_value(false)->zero_tokens(),
2470
 
  "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.")
2471
 
  ("routines,R", po::value<bool>(&opt_routines)->default_value(false)->zero_tokens(),
2472
 
  "Dump stored routines (functions and procedures).")
 
2414
  N_("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."))
2473
2415
  ("single-transaction", po::value<bool>(&opt_single_transaction)->default_value(false)->zero_tokens(),
2474
 
  "Creates a consistent snapshot by dumping all tables in a single transaction. Works ONLY for tables stored in storage engines which support multiversioning (currently only InnoDB does); the dump is NOT guaranteed to be consistent for other storage engines. While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents), no other connection should use the following statements: ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not isolated from them. Option automatically turns off --lock-tables.")
2475
 
  ("opt", "Same as --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. Enabled by default, disable with --skip-opt.") 
 
2416
  N_("Creates a consistent snapshot by dumping all tables in a single transaction. Works ONLY for tables stored in storage engines which support multiversioning (currently only InnoDB does); the dump is NOT guaranteed to be consistent for other storage engines. While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents), no other connection should use the following statements: ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not isolated from them. Option automatically turns off --lock-tables."))
 
2417
  ("opt", N_("Same as --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. Enabled by default, disable with --skip-opt.")) 
2476
2418
  ("skip-opt", 
2477
 
  "Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.")    
2478
 
  ("tables", "Overrides option --databases (-B).")
 
2419
  N_("Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys."))    
 
2420
  ("tables", N_("Overrides option --databases (-B)."))
2479
2421
  ("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(10000),
2480
2422
  N_("Number of rows before each output progress report (requires --verbose)."))
2481
2423
  ("verbose,v", po::value<bool>(&verbose)->default_value(false)->zero_tokens(),
2482
 
  "Print info about the various stages.")
2483
 
  ("version,V", "Output version information and exit.")
2484
 
  ("xml,X", "Dump a database as well formed XML.")
2485
 
  ("skip-comments", "Turn off Comments")
2486
 
  ("skip-create", "Turn off create-options")
2487
 
  ("skip-extended-insert", "Turn off extended-insert") 
2488
 
  ("skip-dump-date", "Turn off dump-date")
2489
 
  ("no-defaults", "Do not read from the configuration files")
 
2424
  N_("Print info about the various stages."))
 
2425
  ("version,V", N_("Output version information and exit."))
 
2426
  ("xml,X", N_("Dump a database as well formed XML."))
 
2427
  ("skip-comments", N_("Turn off Comments"))
 
2428
  ("skip-create", N_("Turn off create-options"))
 
2429
  ("skip-extended-insert", N_("Turn off extended-insert"))
 
2430
  ("skip-dump-date",N_( "Turn off dump-date"))
 
2431
  ("no-defaults", N_("Do not read from the configuration files"))
2490
2432
  ;
2491
2433
 
2492
 
  po::options_description dump_options("Options specific to the drizzle client");
 
2434
  po::options_description dump_options(N_("Options specific to the drizzle client"));
2493
2435
  dump_options.add_options()
2494
2436
  ("add-drop-database", po::value<bool>(&opt_drop_database)->default_value(false)->zero_tokens(),
2495
 
  "Add a 'DROP DATABASE' before each create.")
 
2437
  N_("Add a 'DROP DATABASE' before each create."))
2496
2438
  ("add-drop-table", po::value<bool>(&opt_drop)->default_value(true)->zero_tokens(),
2497
 
  "Add a 'drop table' before each create.")
 
2439
  N_("Add a 'drop table' before each create."))
2498
2440
  ("allow-keywords", po::value<bool>(&opt_keywords)->default_value(false)->zero_tokens(),
2499
 
  "Allow creation of column names that are keywords.")
 
2441
  N_("Allow creation of column names that are keywords."))
2500
2442
  ("comments,i", po::value<bool>(&opt_comments)->default_value(true)->zero_tokens(),
2501
 
  "Write additional information.")
2502
 
  ("compatible", po::value<string>(&opt_compatible_mode_str)->default_value(""),
2503
 
  "Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires DRIZZLE server version 4.1.0 or higher. This option is ignored with earlier server versions.")
 
2443
  N_("Write additional information."))
2504
2444
  ("compact", po::value<bool>(&opt_compact)->default_value(false)->zero_tokens(),
2505
 
  "Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs.  Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks")
 
2445
  N_("Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs.  Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks"))
2506
2446
  ("create-options", po::value<bool>(&create_options)->default_value(true)->zero_tokens(),
2507
 
  "Include all DRIZZLE specific create options.")
 
2447
  N_("Include all DRIZZLE specific create options."))
2508
2448
  ("dump-date", po::value<bool>(&opt_dump_date)->default_value(true)->zero_tokens(),
2509
 
  "Put a dump date to the end of the output.")
 
2449
  N_("Put a dump date to the end of the output."))
2510
2450
  ("databases,B", po::value<bool>(&opt_databases)->default_value(false)->zero_tokens(),
2511
 
  "To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output.")
 
2451
  N_("To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output."))
2512
2452
  ("delayed-insert", po::value<bool>(&opt_delayed)->default_value(false)->zero_tokens(),
2513
 
  "Insert rows with INSERT DELAYED; ")
 
2453
  N_("Insert rows with INSERT DELAYED;"))
2514
2454
  ("disable-keys,K", po::value<bool>(&opt_disable_keys)->default_value(true)->zero_tokens(),
2515
 
  "'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output.")
 
2455
  N_("'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output."))
2516
2456
  ("extended-insert,e", po::value<bool>(&extended_insert)->default_value(true)->zero_tokens(),
2517
 
  "Allows utilization of the new, much faster INSERT syntax.")
 
2457
  N_("Allows utilization of the new, much faster INSERT syntax."))
2518
2458
  ("fields-terminated-by", po::value<string>(&fields_terminated)->default_value(""),
2519
 
  "Fields in the textfile are terminated by ...")
 
2459
  N_("Fields in the textfile are terminated by ..."))
2520
2460
  ("fields-enclosed-by", po::value<string>(&enclosed)->default_value(""),
2521
 
  "Fields in the importfile are enclosed by ...")
 
2461
  N_("Fields in the importfile are enclosed by ..."))
2522
2462
  ("fields-optionally-enclosed-by", po::value<string>(&opt_enclosed)->default_value(""),
2523
 
  "Fields in the i.file are opt. enclosed by ...")
 
2463
  N_("Fields in the i.file are opt. enclosed by ..."))
2524
2464
  ("fields-escaped-by", po::value<string>(&escaped)->default_value(""),
2525
 
  "Fields in the i.file are escaped by ...")
 
2465
  N_("Fields in the i.file are escaped by ..."))
2526
2466
  ("hex-blob", po::value<bool>(&opt_hex_blob)->default_value(false)->zero_tokens(),
2527
2467
  "Dump binary strings (BINARY, VARBINARY, BLOB) in hexadecimal format.")
2528
2468
  ("ignore-table", po::value<string>(),
2529
 
  "Do not dump the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table.  Each table must be specified with both database and table names, e.g. --ignore-table=database.table")
 
2469
  N_("Do not dump the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table.  Each table must be specified with both database and table names, e.g. --ignore-table=database.table"))
2530
2470
  ("insert-ignore", po::value<bool>(&opt_ignore)->default_value(false)->zero_tokens(),
2531
 
  "Insert rows with INSERT IGNORE.")
 
2471
  N_("Insert rows with INSERT IGNORE."))
2532
2472
  ("lines-terminated-by", po::value<string>(&lines_terminated)->default_value(""),
2533
 
  "Lines in the i.file are terminated by ...")
 
2473
  N_("Lines in the i.file are terminated by ..."))
2534
2474
  ("no-autocommit", po::value<bool>(&opt_autocommit)->default_value(false)->zero_tokens(),
2535
 
  "Wrap tables with autocommit/commit statements.")
 
2475
  N_("Wrap tables with autocommit/commit statements."))
2536
2476
  ("no-create-db,n", po::value<bool>(&opt_create_db)->default_value(false)->zero_tokens(),
2537
 
  "'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.}.")
 
2477
  N_("'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."))
2538
2478
  ("no-create-info,t", po::value<bool>(&opt_no_create_info)->default_value(false)->zero_tokens(),
2539
 
  "Don't write table creation info.")
 
2479
  N_("Don't write table creation info."))
2540
2480
  ("no-data,d", po::value<bool>(&opt_no_data)->default_value(false)->zero_tokens(),
2541
 
  "No row information.")
2542
 
  ("no-set-names,N", "Deprecated. Use --skip-set-charset instead.")
 
2481
  N_("No row information."))
 
2482
  ("no-set-names,N", N_("Deprecated. Use --skip-set-charset instead."))
2543
2483
  ("set-charset", po::value<bool>(&opt_set_charset)->default_value(false)->zero_tokens(),
2544
 
  "Enable set-name")
 
2484
  N_("Enable set-name"))
2545
2485
  ("quick,q", po::value<bool>(&quick)->default_value(true)->zero_tokens(),
2546
 
  "Don't buffer query, dump directly to stdout.")
 
2486
  N_("Don't buffer query, dump directly to stdout."))
2547
2487
  ("quote-names,Q", po::value<bool>(&opt_quoted)->default_value(true)->zero_tokens(),
2548
 
  "Quote table and column names with backticks (`).")
 
2488
  N_("Quote table and column names with backticks (`)."))
2549
2489
  ("replace", po::value<bool>(&opt_replace_into)->default_value(false)->zero_tokens(),
2550
 
  "Use REPLACE INTO instead of INSERT INTO.")
 
2490
  N_("Use REPLACE INTO instead of INSERT INTO."))
2551
2491
  ("result-file,r", po::value<string>(),
2552
 
  "Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\r\\n' (carriage return + line feed).")  
 
2492
  N_("Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\r\\n' (carriage return + line feed)."))
2553
2493
  ("tab,T", po::value<string>(&path)->default_value(""),
2554
 
  "Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if drizzledump is run on the same machine as the drizzled daemon.")
 
2494
  N_("Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if drizzledump is run on the same machine as the drizzled daemon."))
2555
2495
  ("where,w", po::value<string>(&where)->default_value(""),
2556
 
  "Dump only selected records; QUOTES mandatory!")
 
2496
  N_("Dump only selected records; QUOTES mandatory!"))
2557
2497
  ;
2558
2498
 
2559
 
  po::options_description client_options("Options specific to the client");
 
2499
  po::options_description client_options(N_("Options specific to the client"));
2560
2500
  client_options.add_options()
2561
2501
  ("host,h", po::value<string>(&current_host)->default_value("localhost"),
2562
 
  "Connect to host.")
2563
 
  ("mysql,m", po::value<bool>(&opt_mysql)->default_value(true)->zero_tokens(),
2564
 
  N_("Use MySQL Protocol."))
 
2502
  N_("Connect to host."))
2565
2503
  ("password,P", po::value<string>(&password)->default_value(PASSWORD_SENTINEL),
2566
 
  "Password to use when connecting to server. If password is not given it's solicited on the tty.")
 
2504
  N_("Password to use when connecting to server. If password is not given it's solicited on the tty."))
2567
2505
  ("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),
2568
 
  "Port number to use for connection.")
 
2506
  N_("Port number to use for connection."))
2569
2507
  ("user,u", po::value<string>(&current_user)->default_value(""),
2570
 
  "User for login if not current user.")
2571
 
  ("protocol",po::value<string>(),
2572
 
  "The protocol of connection (tcp,socket,pipe,memory).")
 
2508
  N_("User for login if not current user."))
 
2509
  ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
 
2510
  N_("The protocol of connection (mysql or drizzle)."))
2573
2511
  ;
2574
2512
 
2575
 
  po::options_description hidden_options("Hidden Options");
 
2513
  po::options_description hidden_options(N_("Hidden Options"));
2576
2514
  hidden_options.add_options()
2577
 
  ("database-used", po::value<vector<string> >(), "Used to select the database")
2578
 
  ("Table-used", po::value<vector<string> >(), "Used to select the tables")
 
2515
  ("database-used", po::value<vector<string> >(), N_("Used to select the database"))
 
2516
  ("Table-used", po::value<vector<string> >(), N_("Used to select the tables"))
2579
2517
  ;
2580
2518
 
2581
 
  po::options_description all_options("Allowed Options + Hidden Options");
 
2519
  po::options_description all_options(N_("Allowed Options + Hidden Options"));
2582
2520
  all_options.add(commandline_options).add(dump_options).add(client_options).add(hidden_options);
2583
2521
 
2584
 
  po::options_description long_options("Allowed Options");
 
2522
  po::options_description long_options(N_("Allowed Options"));
2585
2523
  long_options.add(commandline_options).add(dump_options).add(client_options);
2586
2524
 
2587
2525
  std::string system_config_dir_dump(SYSCONFDIR); 
2596
2534
  p.add("database-used", 1);
2597
2535
  p.add("Table-used",-1);
2598
2536
 
2599
 
  compatible_mode_normal_str[0]= 0;
2600
 
  
2601
2537
  md_result_file= stdout;
2602
2538
 
2603
2539
  po::variables_map vm;
2629
2565
  po::notify(vm);  
2630
2566
  
2631
2567
  if ((not vm.count("database-used") && not vm.count("Table-used") 
2632
 
    && not opt_alldbs && path.empty())  || (vm.count("help")))
 
2568
    && not opt_alldbs && path.empty())
 
2569
    || (vm.count("help")) || vm.count("version"))
2633
2570
  {
2634
 
    printf(_("%s  Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), internal::my_progname,
2635
 
      VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
 
2571
    printf(_("Drizzledump %s build %s, for %s-%s (%s)\n"),
 
2572
      drizzle_version(), VERSION, HOST_VENDOR, HOST_OS, HOST_CPU);
 
2573
    if (vm.count("version"))
 
2574
      exit(0);
2636
2575
    puts("");
2637
2576
    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"));
2638
2577
    puts(_("Dumps definitions and data from a Drizzle database server"));
2639
 
    printf(_("Usage: %s [OPTIONS] database [tables]\n"), internal::my_progname);
 
2578
    printf(_("Usage: %s [OPTIONS] database [tables]\n"), progname.c_str());
2640
2579
    printf(_("OR     %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
2641
 
          internal::my_progname);
2642
 
    printf(_("OR     %s [OPTIONS] --all-databases [OPTIONS]\n"), internal::my_progname);
 
2580
          progname.c_str());
 
2581
    printf(_("OR     %s [OPTIONS] --all-databases [OPTIONS]\n"), progname.c_str());
2643
2582
    cout << long_options;
2644
2583
    if (vm.count("help"))
2645
2584
      exit(0);
2647
2586
      exit(1);
2648
2587
  }
2649
2588
 
 
2589
  if (vm.count("protocol"))
 
2590
  {
 
2591
    std::transform(opt_protocol.begin(), opt_protocol.end(),
 
2592
      opt_protocol.begin(), ::tolower);
 
2593
 
 
2594
    if (not opt_protocol.compare("mysql"))
 
2595
      use_drizzle_protocol=false;
 
2596
    else if (not opt_protocol.compare("drizzle"))
 
2597
      use_drizzle_protocol=true;
 
2598
    else
 
2599
    {
 
2600
      cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
 
2601
      exit(-1);
 
2602
    }
 
2603
  }
 
2604
 
2650
2605
  if (vm.count("port"))
2651
2606
  {
2652
2607
    /* If the port number is > 65535 it is not a valid port
2707
2662
    }
2708
2663
  }
2709
2664
 
2710
 
  if (vm.count("version"))
2711
 
  {
2712
 
     printf(_("%s  Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), internal::my_progname,
2713
 
       VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
2714
 
  }
2715
 
 
2716
2665
  if (vm.count("xml"))
2717
2666
  { 
2718
2667
    opt_xml= 1;
2773
2722
    opt_dump_date= false; 
2774
2723
  } 
2775
2724
 
2776
 
  if (! opt_compatible_mode_str.empty())
2777
 
  {
2778
 
    char buff[255];
2779
 
    char *end= compatible_mode_normal_str;
2780
 
    uint32_t i;
2781
 
    uint32_t mode;
2782
 
    uint32_t error_len;
2783
 
 
2784
 
    opt_quoted= 1;
2785
 
    opt_set_charset= 0;
2786
 
    opt_compatible_mode= find_set(&compatible_mode_typelib,
2787
 
                                            opt_compatible_mode_str.c_str(), opt_compatible_mode_str.length(),
2788
 
                                            &err_ptr, &error_len);
2789
 
    if (error_len)
2790
 
    {
2791
 
      strncpy(buff, err_ptr, min((uint32_t)sizeof(buff), error_len+1));
2792
 
      fprintf(stderr, _("Invalid mode to --compatible: %s\n"), buff);
2793
 
      exit(EXIT_ARGUMENT_INVALID);
2794
 
    }
2795
 
    mode= opt_compatible_mode;
2796
 
    for (i= 0, mode= opt_compatible_mode; mode; mode>>= 1, i++)
2797
 
    {
2798
 
      if (mode & 1)
2799
 
      {
2800
 
        uint32_t len = strlen(compatible_mode_names[i]);
2801
 
        end= strcpy(end, compatible_mode_names[i]) + len;
2802
 
        end= strcpy(end, ",")+1;
2803
 
      }
2804
 
    }
2805
 
    if (end!=compatible_mode_normal_str)
2806
 
      end[-1]= 0;
2807
 
  }
2808
 
 
2809
 
 
2810
2725
  exit_code= get_options();
2811
2726
  if (exit_code)
2812
2727
  {