~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Brian Aker
  • Date: 2010-10-27 23:31:42 UTC
  • mto: (1887.2.1 merge)
  • mto: This revision was merged to the branch mainline in revision 1888.
  • Revision ID: brian@tangent.org-20101027233142-lmo86qafuoz1xmk2
Move table_share over into definition and fix header.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 
57
57
#define EX_USAGE 1
58
58
#define EX_DRIZZLEERR 2
 
59
#define EX_CONSCHECK 3
 
60
#define EX_EOM 4
59
61
#define EX_EOF 5 /* ferror for output file was got */
60
 
 
 
62
#define EX_ILLEGAL_TABLE 6
 
63
#define EX_TABLE_STATUS 7
 
64
 
 
65
/* index into 'show fields from table' */
 
66
 
 
67
#define SHOW_FIELDNAME  0
 
68
#define SHOW_TYPE  1
 
69
#define SHOW_NULL  2
 
70
#define SHOW_DEFAULT  4
 
71
#define SHOW_EXTRA  5
 
72
 
 
73
/* Size of buffer for dump's select query */
 
74
#define QUERY_LENGTH 1536
 
75
 
 
76
/* ignore table flags */
 
77
#define IGNORE_NONE 0x00 /* no ignore */
 
78
#define IGNORE_DATA 0x01 /* don't dump data for this table */
 
79
#define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */
 
80
 
 
81
bool opt_alltspcs= false;
 
82
bool opt_complete_insert= false;
61
83
bool  verbose= false;
62
84
static bool use_drizzle_protocol= false;
63
85
bool ignore_errors= false;
81
103
bool extended_insert= true;
82
104
bool opt_replace_into= false;
83
105
bool opt_drop= true; 
84
 
bool opt_data_is_mangled= false;
85
106
uint32_t show_progress_size= 0;
86
107
static string insert_pat;
87
108
static uint32_t opt_drizzle_port= 0;
118
139
  opt_protocol,
119
140
  where;
120
141
 
 
142
//static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
 
143
 
121
144
boost::unordered_set<string> ignore_table;
122
145
 
123
146
void maybe_exit(int error);
177
200
      opt_destination_port, opt_destination_user, opt_destination_password,
178
201
      false);
179
202
  }
180
 
  catch (std::exception&)
 
203
  catch (...)
181
204
  {
182
205
    cerr << "Could not connect to destination database server" << endl;
183
206
    maybe_exit(EX_DRIZZLEERR);
202
225
      DrizzleDumpDatabase *database= *i;
203
226
      sout << *database;
204
227
    }
205
 
    catch (std::exception&)
 
228
    catch (...)
206
229
    {
207
 
      std::cout << _("Error inserting into destination database") << std::endl;
 
230
      std::cout << _("Error inserting into destnation database") << std::endl;
208
231
      if (not ignore_errors)
209
232
        maybe_exit(EX_DRIZZLEERR);
210
233
    }
241
264
    cout << "-- Host: " << current_host << "    Database: " << db_name << endl;
242
265
    cout << "-- ------------------------------------------------------" << endl;
243
266
    cout << "-- Server version\t" << db_connection->getServerVersion();
244
 
    if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND)
 
267
    if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
245
268
      cout << " (MySQL server)";
246
 
    else if (db_connection->getServerType() == ServerDetect::SERVER_DRIZZLE_FOUND)
 
269
    else if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_DRIZZLE_FOUND)
247
270
      cout << " (Drizzle server)";
248
271
    cout << endl << endl;
249
272
  }
334
357
  if (ignore_errors)
335
358
    return;
336
359
  delete db_connection;
337
 
  delete destination_connection;
 
360
  if (destination_connection)
 
361
    delete destination_connection;
338
362
  free_resources();
339
363
  exit(error);
340
364
}
351
375
    std::cerr << _("-- Retrieving database structures...") << std::endl;
352
376
 
353
377
  /* Blocking the MySQL privilege tables too because we can't import them due to bug#646187 */
354
 
  if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND)
 
378
  if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
355
379
    query= "SELECT SCHEMA_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME NOT IN ('information_schema', 'performance_schema', 'mysql')";
356
380
  else
357
381
    query= "SELECT SCHEMA_NAME, DEFAULT_COLLATION_NAME FROM DATA_DICTIONARY.SCHEMAS WHERE SCHEMA_NAME NOT IN ('information_schema','data_dictionary')";
360
384
  while ((row= drizzle_row_next(tableres)))
361
385
  {
362
386
    std::string database_name(row[0]);
363
 
    if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND)
 
387
    if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
364
388
      database= new DrizzleDumpDatabaseMySQL(database_name, db_connection);
365
389
    else
366
390
      database= new DrizzleDumpDatabaseDrizzle(database_name, db_connection);
383
407
  for (vector<string>::const_iterator it= db_names.begin(); it != db_names.end(); ++it)
384
408
  {
385
409
    temp= *it;
386
 
    if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND)
 
410
    if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
387
411
      database= new DrizzleDumpDatabaseMySQL(temp, db_connection);
388
412
    else
389
413
      database= new DrizzleDumpDatabaseDrizzle(temp, db_connection);
396
420
{
397
421
  DrizzleDumpDatabase *database;
398
422
 
399
 
  if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND)
 
423
  if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
400
424
    database= new DrizzleDumpDatabaseMySQL(db, db_connection);
401
425
  else
402
426
    database= new DrizzleDumpDatabaseDrizzle(db, db_connection);
449
473
{
450
474
  int exit_code;
451
475
 
452
 
#if defined(ENABLE_NLS)
453
 
# if defined(HAVE_LOCALE_H)
454
 
  setlocale(LC_ALL, "");
455
 
# endif
456
 
  bindtextdomain("drizzle7", LOCALEDIR);
457
 
  textdomain("drizzle7");
458
 
#endif
459
 
 
460
 
  po::options_description commandline_options(_("Options used only in command line"));
 
476
  po::options_description commandline_options(N_("Options used only in command line"));
461
477
  commandline_options.add_options()
462
478
  ("all-databases,A", po::value<bool>(&opt_alldbs)->default_value(false)->zero_tokens(),
463
 
  _("Dump all the databases. This will be same as --databases with all databases selected."))
 
479
  N_("Dump all the databases. This will be same as --databases with all databases selected."))
 
480
  ("all-tablespaces,Y", po::value<bool>(&opt_alltspcs)->default_value(false)->zero_tokens(),
 
481
  N_("Dump all the tablespaces."))
 
482
  ("complete-insert,c", po::value<bool>(&opt_complete_insert)->default_value(false)->zero_tokens(),
 
483
  N_("Use complete insert statements."))
464
484
  ("flush-logs,F", po::value<bool>(&flush_logs)->default_value(false)->zero_tokens(),
465
 
  _("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"))
 
485
  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"))
466
486
  ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
467
 
  _("Continue even if we get an sql-error."))
468
 
  ("help,?", _("Display this help message and exit."))
 
487
  N_("Continue even if we get an sql-error."))
 
488
  ("help,?", N_("Display this help message and exit."))
469
489
  ("lock-all-tables,x", po::value<bool>(&opt_lock_all_tables)->default_value(false)->zero_tokens(),
470
 
  _("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 off."))
 
490
  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 off."))
471
491
  ("single-transaction", po::value<bool>(&opt_single_transaction)->default_value(false)->zero_tokens(),
472
 
  _("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."))
 
492
  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."))
473
493
  ("skip-opt", 
474
 
  _("Disable --opt. Disables --add-drop-table, --add-locks, --create-options, ---extended-insert and --disable-keys."))    
475
 
  ("tables", _("Overrides option --databases (-B)."))
 
494
  N_("Disable --opt. Disables --add-drop-table, --add-locks, --create-options, ---extended-insert and --disable-keys."))    
 
495
  ("tables", N_("Overrides option --databases (-B)."))
476
496
  ("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(10000),
477
 
  _("Number of rows before each output progress report (requires --verbose)."))
 
497
  N_("Number of rows before each output progress report (requires --verbose)."))
478
498
  ("verbose,v", po::value<bool>(&verbose)->default_value(false)->zero_tokens(),
479
 
  _("Print info about the various stages."))
480
 
  ("version,V", _("Output version information and exit."))
481
 
  ("skip-comments", _("Turn off Comments"))
482
 
  ("skip-create", _("Turn off create-options"))
483
 
  ("skip-extended-insert", _("Turn off extended-insert"))
484
 
  ("skip-dump-date", _( "Turn off dump date at the end of the output"))
485
 
  ("no-defaults", _("Do not read from the configuration files"))
 
499
  N_("Print info about the various stages."))
 
500
  ("version,V", N_("Output version information and exit."))
 
501
  ("skip-comments", N_("Turn off Comments"))
 
502
  ("skip-create", N_("Turn off create-options"))
 
503
  ("skip-extended-insert", N_("Turn off extended-insert"))
 
504
  ("skip-dump-date",N_( "Turn off dump date at the end of the output"))
 
505
  ("no-defaults", N_("Do not read from the configuration files"))
486
506
  ;
487
507
 
488
 
  po::options_description dump_options(_("Options specific to the drizzle client"));
 
508
  po::options_description dump_options(N_("Options specific to the drizzle client"));
489
509
  dump_options.add_options()
490
510
  ("add-drop-database", po::value<bool>(&opt_drop_database)->default_value(false)->zero_tokens(),
491
 
  _("Add a 'DROP DATABASE' before each create."))
492
 
  ("skip-drop-table", _("Do not add a 'drop table' before each create."))
 
511
  N_("Add a 'DROP DATABASE' before each create."))
 
512
  ("skip-drop-table", N_("Do not add a 'drop table' before each create."))
493
513
  ("compact", po::value<bool>(&opt_compact)->default_value(false)->zero_tokens(),
494
 
  _("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"))
 
514
  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"))
495
515
  ("databases,B", po::value<bool>(&opt_databases)->default_value(false)->zero_tokens(),
496
 
  _("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."))
 
516
  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."))
497
517
  ("skip-disable-keys,K",
498
 
  _("'ALTER TABLE tb_name DISABLE KEYS;' and 'ALTER TABLE tb_name ENABLE KEYS;' will not be put in the output."))
 
518
  N_("'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will not be put in the output."))
499
519
  ("ignore-table", po::value<string>(),
500
 
  _("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"))
 
520
  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"))
501
521
  ("insert-ignore", po::value<bool>(&opt_ignore)->default_value(false)->zero_tokens(),
502
 
  _("Insert rows with INSERT IGNORE."))
 
522
  N_("Insert rows with INSERT IGNORE."))
503
523
  ("no-autocommit", po::value<bool>(&opt_autocommit)->default_value(false)->zero_tokens(),
504
 
  _("Wrap a table's data in START TRANSACTION/COMMIT statements."))
 
524
  N_("Wrap a table's data in START TRANSACTION/COMMIT statements."))
505
525
  ("no-create-db,n", po::value<bool>(&opt_create_db)->default_value(false)->zero_tokens(),
506
 
  _("'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."))
 
526
  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."))
507
527
  ("no-data,d", po::value<bool>(&opt_no_data)->default_value(false)->zero_tokens(),
508
 
  _("No row information."))
 
528
  N_("No row information."))
509
529
  ("replace", po::value<bool>(&opt_replace_into)->default_value(false)->zero_tokens(),
510
 
  _("Use REPLACE INTO instead of INSERT INTO."))
 
530
  N_("Use REPLACE INTO instead of INSERT INTO."))
511
531
  ("destination-type", po::value<string>()->default_value("stdout"),
512
 
  _("Where to send output to (stdout|database"))
 
532
  N_("Where to send output to (stdout|database"))
513
533
  ("destination-host", po::value<string>(&opt_destination_host)->default_value("localhost"),
514
 
  _("Hostname for destination db server (requires --destination-type=database)"))
 
534
  N_("Hostname for destination db server (requires --destination-type=database)"))
515
535
  ("destination-port", po::value<uint16_t>(&opt_destination_port)->default_value(4427),
516
 
  _("Port number for destination db server (requires --destination-type=database)"))
 
536
  N_("Port number for destination db server (requires --destination-type=database)"))
517
537
  ("destination-user", po::value<string>(&opt_destination_user),
518
 
  _("User name for destination db server (resquires --destination-type=database)"))
 
538
  N_("User name for destination db server (resquires --destination-type=database)"))
519
539
  ("destination-password", po::value<string>(&opt_destination_password),
520
 
  _("Password for destination db server (requires --destination-type=database)"))
 
540
  N_("Password for destination db server (requires --destination-type=database)"))
521
541
  ("destination-database", po::value<string>(&opt_destination_database),
522
 
  _("The database in the destination db server (requires --destination-type=database, not for use with --all-databases)"))
523
 
  ("my-data-is-mangled", po::value<bool>(&opt_data_is_mangled)->default_value(false)->zero_tokens(),
524
 
  _("Do not make a UTF8 connection to MySQL, use if you have UTF8 data in a non-UTF8 table"))
 
542
  N_("The database in the destination db server (requires --destination-type=database, not for use with --all-databases)"))
525
543
  ;
526
544
 
527
 
  po::options_description client_options(_("Options specific to the client"));
 
545
  po::options_description client_options(N_("Options specific to the client"));
528
546
  client_options.add_options()
529
547
  ("host,h", po::value<string>(&current_host)->default_value("localhost"),
530
 
  _("Connect to host."))
 
548
  N_("Connect to host."))
531
549
  ("password,P", po::value<string>(&password)->default_value(PASSWORD_SENTINEL),
532
 
  _("Password to use when connecting to server. If password is not given it's solicited on the tty."))
 
550
  N_("Password to use when connecting to server. If password is not given it's solicited on the tty."))
533
551
  ("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),
534
 
  _("Port number to use for connection."))
 
552
  N_("Port number to use for connection."))
535
553
  ("user,u", po::value<string>(&current_user)->default_value(""),
536
 
  _("User for login if not current user."))
 
554
  N_("User for login if not current user."))
537
555
  ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
538
 
  _("The protocol of connection (mysql or drizzle)."))
 
556
  N_("The protocol of connection (mysql or drizzle)."))
539
557
  ;
540
558
 
541
 
  po::options_description hidden_options(_("Hidden Options"));
 
559
  po::options_description hidden_options(N_("Hidden Options"));
542
560
  hidden_options.add_options()
543
 
  ("database-used", po::value<vector<string> >(), _("Used to select the database"))
544
 
  ("Table-used", po::value<vector<string> >(), _("Used to select the tables"))
 
561
  ("database-used", po::value<vector<string> >(), N_("Used to select the database"))
 
562
  ("Table-used", po::value<vector<string> >(), N_("Used to select the tables"))
545
563
  ;
546
564
 
547
 
  po::options_description all_options(_("Allowed Options + Hidden Options"));
 
565
  po::options_description all_options(N_("Allowed Options + Hidden Options"));
548
566
  all_options.add(commandline_options).add(dump_options).add(client_options).add(hidden_options);
549
567
 
550
 
  po::options_description long_options(_("Allowed Options"));
 
568
  po::options_description long_options(N_("Allowed Options"));
551
569
  long_options.add(commandline_options).add(dump_options).add(client_options);
552
570
 
553
571
  std::string system_config_dir_dump(SYSCONFDIR); 
558
576
 
559
577
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
560
578
 
561
 
  if (user_config_dir.compare(0, 2, "~/") == 0)
562
 
  {
563
 
    char *homedir;
564
 
    homedir= getenv("HOME");
565
 
    if (homedir != NULL)
566
 
      user_config_dir.replace(0, 1, homedir);
567
 
  }
568
 
 
569
579
  po::positional_options_description p;
570
580
  p.add("database-used", 1);
571
581
  p.add("Table-used",-1);
737
747
    db_connection = new DrizzleDumpConnection(current_host, opt_drizzle_port,
738
748
      current_user, opt_password, use_drizzle_protocol);
739
749
  }
740
 
  catch (std::exception&)
 
750
  catch (...)
741
751
  {
742
752
    maybe_exit(EX_DRIZZLEERR);
743
753
  }
744
754
 
745
 
  if ((db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND) and (not opt_data_is_mangled))
 
755
  if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
746
756
    db_connection->queryNoResult("SET NAMES 'utf8'");
747
757
 
748
758
  if (vm.count("destination-type"))
784
794
    dump_selected_tables(database_used, vm["Table-used"].as< vector<string> >());
785
795
  }
786
796
 
787
 
  if (vm.count("Table-used") and opt_databases)
 
797
  if (vm.count("Table-used") && opt_databases)
788
798
  {
 
799
/*
 
800
 * This is not valid!
789
801
    vector<string> database_used= vm["database-used"].as< vector<string> >();
790
802
    vector<string> table_used= vm["Table-used"].as< vector<string> >();
791
803
 
795
807
    {
796
808
      database_used.insert(database_used.end(), *it);
797
809
    }
798
 
 
799
810
    dump_databases(database_used);
800
 
    dump_all_tables();
 
811
    dump_tables();
 
812
*/
801
813
  }
802
 
 
 
814
  
803
815
  if (vm.count("database-used") && ! vm.count("Table-used"))
804
816
  {
805
817
    dump_databases(vm["database-used"].as< vector<string> >());
806
818
    dump_all_tables();
807
819
  }
808
 
 
809
820
  if (opt_destination == DESTINATION_STDOUT)
810
821
    generate_dump();
811
822
  else
827
838
  */
828
839
err:
829
840
  delete db_connection;
830
 
  delete destination_connection;
 
841
  if (destination_connection)
 
842
    delete destination_connection;
831
843
  if (path.empty())
832
844
    write_footer(md_result_file);
833
845
  free_resources();