~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: pcrews
  • Date: 2011-05-24 17:36:24 UTC
  • mfrom: (1099.4.232 drizzle)
  • Revision ID: pcrews@lucid32-20110524173624-mwr1bvq6fa1r01ao
Updated translations + 2011.05.18 tarball tag

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
61
59
#define EX_EOF 5 /* ferror for output file was got */
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;
 
60
 
83
61
bool  verbose= false;
84
62
static bool use_drizzle_protocol= false;
85
63
bool ignore_errors= false;
263
241
    cout << "-- Host: " << current_host << "    Database: " << db_name << endl;
264
242
    cout << "-- ------------------------------------------------------" << endl;
265
243
    cout << "-- Server version\t" << db_connection->getServerVersion();
266
 
    if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
 
244
    if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND)
267
245
      cout << " (MySQL server)";
268
 
    else if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_DRIZZLE_FOUND)
 
246
    else if (db_connection->getServerType() == ServerDetect::SERVER_DRIZZLE_FOUND)
269
247
      cout << " (Drizzle server)";
270
248
    cout << endl << endl;
271
249
  }
 
250
 
272
251
} /* write_header */
273
252
 
274
253
 
373
352
    std::cerr << _("-- Retrieving database structures...") << std::endl;
374
353
 
375
354
  /* Blocking the MySQL privilege tables too because we can't import them due to bug#646187 */
376
 
  if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
 
355
  if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND)
377
356
    query= "SELECT SCHEMA_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME NOT IN ('information_schema', 'performance_schema', 'mysql')";
378
357
  else
379
358
    query= "SELECT SCHEMA_NAME, DEFAULT_COLLATION_NAME FROM DATA_DICTIONARY.SCHEMAS WHERE SCHEMA_NAME NOT IN ('information_schema','data_dictionary')";
382
361
  while ((row= drizzle_row_next(tableres)))
383
362
  {
384
363
    std::string database_name(row[0]);
385
 
    if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
 
364
    if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND)
386
365
      database= new DrizzleDumpDatabaseMySQL(database_name, db_connection);
387
366
    else
388
367
      database= new DrizzleDumpDatabaseDrizzle(database_name, db_connection);
405
384
  for (vector<string>::const_iterator it= db_names.begin(); it != db_names.end(); ++it)
406
385
  {
407
386
    temp= *it;
408
 
    if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
 
387
    if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND)
409
388
      database= new DrizzleDumpDatabaseMySQL(temp, db_connection);
410
389
    else
411
390
      database= new DrizzleDumpDatabaseDrizzle(temp, db_connection);
418
397
{
419
398
  DrizzleDumpDatabase *database;
420
399
 
421
 
  if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
 
400
  if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND)
422
401
    database= new DrizzleDumpDatabaseMySQL(db, db_connection);
423
402
  else
424
403
    database= new DrizzleDumpDatabaseDrizzle(db, db_connection);
452
431
  return 0;
453
432
}
454
433
 
455
 
static int do_unlock_tables()
456
 
{
457
 
  db_connection->queryNoResult("UNLOCK TABLES");
458
 
  return 0;
459
 
}
460
 
 
461
434
static int start_transaction()
462
435
{
463
436
  db_connection->queryNoResult("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ");
464
437
  db_connection->queryNoResult("START TRANSACTION WITH CONSISTENT SNAPSHOT");
 
438
 
 
439
  if (db_connection->getServerType() == ServerDetect::SERVER_DRIZZLE_FOUND)
 
440
  {
 
441
    drizzle_result_st *result;
 
442
    drizzle_row_t row;
 
443
    std::string query("SELECT COMMIT_ID, ID FROM DATA_DICTIONARY.SYS_REPLICATION_LOG WHERE COMMIT_ID=(SELECT MAX(COMMIT_ID) FROM DATA_DICTIONARY.SYS_REPLICATION_LOG)");
 
444
    result= db_connection->query(query);
 
445
    if ((row= drizzle_row_next(result)))
 
446
    {
 
447
      cout << "-- SYS_REPLICATION_LOG: COMMIT_ID = " << row[0] << ", ID = " << row[1] << endl << endl;
 
448
    }
 
449
    db_connection->freeResult(result);
 
450
  }
 
451
 
465
452
  return 0;
466
453
}
467
454
 
483
470
  commandline_options.add_options()
484
471
  ("all-databases,A", po::value<bool>(&opt_alldbs)->default_value(false)->zero_tokens(),
485
472
  _("Dump all the databases. This will be same as --databases with all databases selected."))
486
 
  ("all-tablespaces,Y", po::value<bool>(&opt_alltspcs)->default_value(false)->zero_tokens(),
487
 
  _("Dump all the tablespaces."))
488
 
  ("complete-insert,c", po::value<bool>(&opt_complete_insert)->default_value(false)->zero_tokens(),
489
 
  _("Use complete insert statements."))
490
473
  ("flush-logs,F", po::value<bool>(&flush_logs)->default_value(false)->zero_tokens(),
491
474
  _("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"))
492
475
  ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
550
533
  _("Do not make a UTF8 connection to MySQL, use if you have UTF8 data in a non-UTF8 table"))
551
534
  ;
552
535
 
 
536
  const char* unix_user= getlogin();
 
537
 
553
538
  po::options_description client_options(_("Options specific to the client"));
554
539
  client_options.add_options()
555
540
  ("host,h", po::value<string>(&current_host)->default_value("localhost"),
558
543
  _("Password to use when connecting to server. If password is not given it's solicited on the tty."))
559
544
  ("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),
560
545
  _("Port number to use for connection."))
561
 
  ("user,u", po::value<string>(&current_user)->default_value(""),
 
546
  ("user,u", po::value<string>(&current_user)->default_value((unix_user ? unix_user : "")),
562
547
  _("User for login if not current user."))
563
548
  ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
564
549
  _("The protocol of connection (mysql or drizzle)."))
654
639
 
655
640
  /* Inverted Booleans */
656
641
 
657
 
  opt_drop= (vm.count("skip-drop-table")) ? false : true;
658
 
  opt_comments= (vm.count("skip-comments")) ? false : true;
659
 
  extended_insert= (vm.count("skip-extended-insert")) ? false : true;
660
 
  opt_dump_date= (vm.count("skip-dump-date")) ? false : true;
661
 
  opt_disable_keys= (vm.count("skip-disable-keys")) ? false : true;
662
 
  opt_quoted= (vm.count("skip-quote-names")) ? false : true;
 
642
  opt_drop= not vm.count("skip-drop-table");
 
643
  opt_comments= not vm.count("skip-comments");
 
644
  extended_insert= not vm.count("skip-extended-insert");
 
645
  opt_dump_date= not vm.count("skip-dump-date");
 
646
  opt_disable_keys= not vm.count("skip-disable-keys");
 
647
  opt_quoted= not vm.count("skip-quote-names");
663
648
 
664
649
  if (vm.count("protocol"))
665
650
  {
690
675
    }
691
676
  }
692
677
 
693
 
  if(vm.count("password"))
 
678
  if (vm.count("password"))
694
679
  {
695
680
    if (!opt_password.empty())
696
681
      opt_password.erase();
768
753
    maybe_exit(EX_DRIZZLEERR);
769
754
  }
770
755
 
771
 
  if ((db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND) and (not opt_data_is_mangled))
 
756
  if ((db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND) and (not opt_data_is_mangled))
772
757
    db_connection->queryNoResult("SET NAMES 'utf8'");
773
758
 
774
759
  if (vm.count("destination-type"))
795
780
    goto err;
796
781
  if (opt_lock_all_tables)
797
782
    db_connection->queryNoResult("FLUSH LOGS");
798
 
  if (opt_single_transaction && do_unlock_tables()) /* unlock but no commit! */
799
 
    goto err;
800
783
 
801
784
  if (opt_alldbs)
802
785
  {
803
786
    dump_all_databases();
804
787
    dump_all_tables();
805
788
  }
806
 
  if (vm.count("database-used") && vm.count("Table-used") && ! opt_databases)
 
789
  if (vm.count("database-used") && vm.count("Table-used") && not opt_databases)
807
790
  {
808
791
    string database_used= *vm["database-used"].as< vector<string> >().begin();
809
792
    /* Only one database and selected table(s) */
810
793
    dump_selected_tables(database_used, vm["Table-used"].as< vector<string> >());
811
794
  }
812
795
 
813
 
  if (vm.count("Table-used") and opt_databases)
 
796
  if (vm.count("Table-used") && opt_databases)
814
797
  {
815
798
    vector<string> database_used= vm["database-used"].as< vector<string> >();
816
799
    vector<string> table_used= vm["Table-used"].as< vector<string> >();
826
809
    dump_all_tables();
827
810
  }
828
811
 
829
 
  if (vm.count("database-used") && ! vm.count("Table-used"))
 
812
  if (vm.count("database-used") && not vm.count("Table-used"))
830
813
  {
831
814
    dump_databases(vm["database-used"].as< vector<string> >());
832
815
    dump_all_tables();