~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Andrew Hutchings
  • Date: 2010-09-22 11:14:51 UTC
  • mto: (1792.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1793.
  • Revision ID: andrew@linuxjedi.co.uk-20100922111451-5ioyfxbyf0pvt81k
Make some command line options work again

Show diffs side-by-side

added added

removed removed

Lines of Context:
689
689
     << "-- Current Database: `" << obj.databaseName << "`" << endl
690
690
     << "--" << endl << endl;
691
691
 
692
 
  os << "CREATE DATABASE IF NOT EXISTS `" << obj.databaseName << "` COLLATE = " << obj.collate << ";" << endl << endl;
 
692
  /* Love that this variable is the opposite of its name */
 
693
  if (not opt_create_db)
 
694
  {
 
695
    os << "CREATE DATABASE IF NOT EXISTS `" << obj.databaseName
 
696
      << "` COLLATE = " << obj.collate << ";" << endl << endl;
 
697
  }
693
698
 
694
699
  os << "USE `" << obj.databaseName << "`;" << endl << endl;
695
700
 
698
703
  for (i= output_tables.begin(); i != output_tables.end(); ++i)
699
704
  {
700
705
    DrizzleDumpTable *table= *i;
701
 
    os << *table;
702
 
    DrizzleDumpData *data= new DrizzleDumpData(dcon, table);
703
 
    os << *data;
704
 
    delete data;
 
706
    if (not opt_no_create_info)
 
707
      os << *table;
 
708
    if (not opt_no_data)
 
709
    {
 
710
      DrizzleDumpData *data= new DrizzleDumpData(dcon, table);
 
711
      os << *data;
 
712
      delete data;
 
713
    }
705
714
  }
706
715
 
707
716
  return os;
751
760
{
752
761
  bool new_insert= true;
753
762
  bool first= true;
 
763
  uint64_t rownr= 0;
 
764
 
754
765
  drizzle_row_t row;
755
766
 
756
767
  if (drizzle_result_row_count(obj.result) < 1)
766
777
       << "-- Dumping data for table `" << obj.table->tableName << "`" << endl
767
778
       << "--" << endl << endl;
768
779
  }
 
780
  if (opt_disable_keys)
 
781
    os << "ALTER TABLE `" << obj.table->tableName << "` DISABLE KEYS;" << endl;
769
782
 
770
783
  streampos out_position= os.tellp();
771
784
 
772
785
  while((row= drizzle_row_next(obj.result)))
773
786
  {
 
787
    rownr++;
 
788
    if ((rownr % show_progress_size) == 0)
 
789
    {
 
790
      cerr << "-- %" << rownr << _(" rows dumped for table ") << obj.table->tableName << endl;
 
791
    }
 
792
 
774
793
    size_t* row_sizes= drizzle_row_field_sizes(obj.result);
775
794
    if (not first)
776
795
    {
834
853
      out_position= os.tellp();
835
854
    }
836
855
  }
837
 
  os << ");" << endl << endl;
 
856
  os << ");" << endl;
 
857
 
 
858
  if (opt_disable_keys)
 
859
    os << "ALTER TABLE `" << obj.table->tableName << "` ENABLE KEYS;" << endl;
 
860
 
 
861
  os << endl;
 
862
 
838
863
  return os;
839
864
}
840
865
 
916
941
     << "-- Table structure for table `" << obj.tableName << "`" << endl
917
942
     << "--" << endl << endl;
918
943
 
919
 
  os << "DROP TABLE IF EXISTS `" << obj.tableName <<  "`;" << endl;
 
944
  if (opt_drop)
 
945
    os << "DROP TABLE IF EXISTS `" << obj.tableName <<  "`;" << endl;
 
946
 
920
947
  os << "CREATE TABLE `" << obj.tableName << "` (" << endl;
921
948
  std::vector<DrizzleDumpField*>::iterator i;
922
949
  std::vector<DrizzleDumpField*> output_fields = obj.fields;
1474
1501
  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."))
1475
1502
  ("delayed-insert", po::value<bool>(&opt_delayed)->default_value(false)->zero_tokens(),
1476
1503
  N_("Insert rows with INSERT DELAYED;"))
1477
 
  ("enable-keys,K",
1478
 
  N_("'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will be put in the output."))
1479
 
  ("fields-terminated-by", po::value<string>(&fields_terminated)->default_value(""),
1480
 
  N_("Fields in the textfile are terminated by ..."))
1481
 
  ("fields-enclosed-by", po::value<string>(&enclosed)->default_value(""),
1482
 
  N_("Fields in the importfile are enclosed by ..."))
1483
 
  ("fields-optionally-enclosed-by", po::value<string>(&opt_enclosed)->default_value(""),
1484
 
  N_("Fields in the i.file are opt. enclosed by ..."))
1485
 
  ("fields-escaped-by", po::value<string>(&escaped)->default_value(""),
1486
 
  N_("Fields in the i.file are escaped by ..."))
 
1504
  ("skip-disable-keys,K",
 
1505
  N_("'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will not be put in the output."))
1487
1506
  ("hex-blob", po::value<bool>(&opt_hex_blob)->default_value(false)->zero_tokens(),
1488
1507
  "Dump binary strings (BINARY, VARBINARY, BLOB) in hexadecimal format.")
1489
1508
  ("ignore-table", po::value<string>(),
1504
1523
  ("set-charset", po::value<bool>(&opt_set_charset)->default_value(false)->zero_tokens(),
1505
1524
  N_("Enable set-name"))
1506
1525
  ("slow", N_("Buffer query instead of dumping directly to stdout."))
1507
 
  ("skip-quote-names",
1508
 
  N_("Do not quote table and column names with backticks (`)."))
1509
1526
  ("replace", po::value<bool>(&opt_replace_into)->default_value(false)->zero_tokens(),
1510
1527
  N_("Use REPLACE INTO instead of INSERT INTO."))
1511
1528
  ("result-file,r", po::value<string>(),
1512
1529
  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)."))
1513
 
  ("tab,T", po::value<string>(&path)->default_value(""),
1514
 
  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."))
1515
1530
  ("where,w", po::value<string>(&where)->default_value(""),
1516
1531
  N_("Dump only selected records; QUOTES mandatory!"))
1517
1532
  ;
1612
1627
  opt_comments= (vm.count("skip-comments")) ? false : true;
1613
1628
  extended_insert= (vm.count("skip-extended-insert")) ? false : true;
1614
1629
  opt_dump_date= (vm.count("skip-dump-date")) ? false : true;
1615
 
  opt_disable_keys= (vm.count("enable-keys")) ? false : true;
 
1630
  opt_disable_keys= (vm.count("skip-disable-keys")) ? false : true;
1616
1631
  quick= (vm.count("slow")) ? false : true;
1617
1632
  opt_quoted= (vm.count("skip-quote-names")) ? false : true;
1618
1633
 
1678
1693
  if (! path.empty())
1679
1694
  { 
1680
1695
    opt_disable_keys= 0;
1681
 
 
1682
 
    if (vm["tab"].as<string>().length() >= FN_REFLEN)
1683
 
    {
1684
 
      /*
1685
 
        This check is made because the some the file functions below
1686
 
        have FN_REFLEN sized stack allocated buffers and will cause
1687
 
        a crash even if the input destination buffer is large enough
1688
 
        to hold the output.
1689
 
      */
1690
 
      fprintf(stderr, _("Input filename too long: %s"), vm["tab"].as<string>().c_str());
1691
 
      exit(EXIT_ARGUMENT_INVALID);
1692
 
    }
1693
1696
  }
1694
1697
 
1695
1698
  if (vm.count("skip-opt"))