~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: patrick crews
  • Date: 2010-09-29 15:15:19 UTC
  • mfrom: (1099.4.188 drizzle)
  • Revision ID: gleebix@gmail.com-20100929151519-6mrmzd1ciw2p9nws
Tags: 2010.09.1802
Update translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
  You should have received a copy of the GNU General Public License
15
15
  along with this program; if not, write to the Free Software
16
 
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
16
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
17
17
 
18
18
/* drizzledump.cc  - Dump a tables contents and format to an ASCII file
19
19
 
78
78
#define IGNORE_DATA 0x01 /* don't dump data for this table */
79
79
#define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */
80
80
 
81
 
bool opt_alltspcs= false;
82
 
bool opt_complete_insert= false;
83
81
bool  verbose= false;
84
82
static bool use_drizzle_protocol= false;
85
 
bool ignore_errors= false;
 
83
static bool quick= true;
 
84
static bool ignore_errors= false;
86
85
static bool flush_logs= false;
 
86
static bool opt_keywords= false;
 
87
static bool opt_compress= false;
 
88
static bool opt_delayed= false; 
87
89
static bool create_options= true; 
88
90
static bool opt_quoted= false;
89
91
bool opt_databases= false; 
90
92
bool opt_alldbs= false; 
91
93
static bool opt_lock_all_tables= false;
 
94
static bool opt_set_charset= false; 
92
95
static bool opt_dump_date= true;
93
 
bool opt_autocommit= false; 
 
96
static bool opt_autocommit= false; 
94
97
static bool opt_single_transaction= false; 
95
98
static bool opt_comments;
96
99
static bool opt_compact;
 
100
static bool opt_order_by_primary=false; 
97
101
bool opt_ignore= false;
98
 
bool opt_drop_database;
 
102
static bool opt_complete_insert= false;
 
103
static bool opt_drop_database;
 
104
static bool opt_alltspcs= false;
99
105
bool opt_no_create_info;
100
106
bool opt_no_data= false;
101
107
bool opt_create_db= false;
103
109
bool extended_insert= true;
104
110
bool opt_replace_into= false;
105
111
bool opt_drop= true; 
106
 
bool opt_data_is_mangled= false;
107
112
uint32_t show_progress_size= 0;
 
113
//static uint64_t total_rows= 0;
108
114
static string insert_pat;
 
115
//static char *order_by= NULL;
109
116
static uint32_t opt_drizzle_port= 0;
110
117
static int first_error= 0;
111
118
static string extended_row;
134
141
  enclosed,
135
142
  escaped,
136
143
  current_host,
 
144
  opt_enclosed,
 
145
  fields_terminated,
137
146
  path,
 
147
  lines_terminated,
138
148
  current_user,
139
149
  opt_password,
140
150
  opt_protocol,
141
151
  where;
142
152
 
 
153
//static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
 
154
 
143
155
boost::unordered_set<string> ignore_table;
144
156
 
145
157
void maybe_exit(int error);
158
170
  std::vector<DrizzleDumpDatabase*>::iterator i;
159
171
  for (i= database_store.begin(); i != database_store.end(); ++i)
160
172
  {
161
 
    if ((not (*i)->populateTables()) && (not ignore_errors))
 
173
    if (not (*i)->populateTables())
162
174
      maybe_exit(EX_DRIZZLEERR);
163
175
  }
164
176
}
166
178
void generate_dump(void)
167
179
{
168
180
  std::vector<DrizzleDumpDatabase*>::iterator i;
 
181
  if (opt_set_charset)
 
182
    cout << endl << "SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;" << endl;
169
183
 
170
184
  if (path.empty())
171
185
  {
172
186
    cout << endl << "SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;"
173
187
      << endl << "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;" << endl;
174
188
  }
175
 
 
176
 
  if (opt_autocommit)
177
 
    cout << "SET AUTOCOMMIT=0;" << endl;
178
 
 
179
189
  for (i= database_store.begin(); i != database_store.end(); ++i)
180
190
  {
181
191
    DrizzleDumpDatabase *database= *i;
187
197
    cout << "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;"
188
198
      << endl << "SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;" << endl;
189
199
  }
 
200
  if (opt_set_charset)
 
201
    cout << "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;" << endl;
190
202
}
191
203
 
192
204
void generate_dump_db(void)
193
205
{
194
206
  std::vector<DrizzleDumpDatabase*>::iterator i;
195
207
  DrizzleStringBuf sbuf(1024);
196
 
  try
197
 
  {
198
 
    destination_connection= new DrizzleDumpConnection(opt_destination_host,
199
 
      opt_destination_port, opt_destination_user, opt_destination_password,
200
 
      false);
201
 
  }
202
 
  catch (std::exception&)
203
 
  {
204
 
    cerr << "Could not connect to destination database server" << endl;
205
 
    maybe_exit(EX_DRIZZLEERR);
206
 
  }
 
208
  destination_connection= new DrizzleDumpConnection(opt_destination_host,
 
209
    opt_destination_port, opt_destination_user, opt_destination_password,
 
210
    false);
207
211
  sbuf.setConnection(destination_connection);
208
212
  std::ostream sout(&sbuf);
209
 
  sout.exceptions(ios_base::badbit);
 
213
  if (opt_set_charset)
 
214
    sout << "SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;" << endl;
210
215
 
211
216
  if (path.empty())
212
217
  {
214
219
    sout << "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;" << endl;
215
220
  }
216
221
 
217
 
  if (opt_autocommit)
218
 
    cout << "SET AUTOCOMMIT=0;" << endl;
219
 
 
220
222
  for (i= database_store.begin(); i != database_store.end(); ++i)
221
223
  {
222
 
    try
223
 
    {
224
 
      DrizzleDumpDatabase *database= *i;
225
 
      sout << *database;
226
 
    }
227
 
    catch (std::exception&)
228
 
    {
229
 
      std::cout << _("Error inserting into destination database") << std::endl;
230
 
      if (not ignore_errors)
231
 
        maybe_exit(EX_DRIZZLEERR);
232
 
    }
 
224
    DrizzleDumpDatabase *database= *i;
 
225
    sout << *database;
233
226
  }
234
227
 
235
228
  if (path.empty())
237
230
    sout << "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;" << endl;
238
231
    sout << "SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;" << endl;
239
232
  }
 
233
  if (opt_set_charset)
 
234
    sout << "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;" << endl;
240
235
}
241
236
 
242
237
/*
293
288
 
294
289
static int get_options(void)
295
290
{
 
291
 
 
292
  if (path.empty() && (! enclosed.empty() || ! opt_enclosed.empty() || ! escaped.empty() || ! lines_terminated.empty() ||
 
293
                ! fields_terminated.empty()))
 
294
  {
 
295
    fprintf(stderr,
 
296
            _("%s: You must use option --tab with --fields-...\n"), progname.c_str());
 
297
    return(EX_USAGE);
 
298
  }
 
299
 
296
300
  if (opt_single_transaction && opt_lock_all_tables)
297
301
  {
298
302
    fprintf(stderr, _("%s: You can't use --single-transaction and "
299
303
                      "--lock-all-tables at the same time.\n"), progname.c_str());
300
304
    return(EX_USAGE);
301
305
  }
 
306
  if (! enclosed.empty() && ! opt_enclosed.empty())
 
307
  {
 
308
    fprintf(stderr, _("%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n"), progname.c_str());
 
309
    return(EX_USAGE);
 
310
  }
302
311
  if ((opt_databases || opt_alldbs) && ! path.empty())
303
312
  {
304
313
    fprintf(stderr,
356
365
  if (ignore_errors)
357
366
    return;
358
367
  delete db_connection;
359
 
  delete destination_connection;
 
368
  if (destination_connection)
 
369
    delete destination_connection;
360
370
  free_resources();
361
371
  exit(error);
362
372
}
426
436
  if (not database->populateTables(table_names))
427
437
  {
428
438
    delete database;
429
 
    if (not ignore_errors)
430
 
      maybe_exit(EX_DRIZZLEERR);
 
439
    maybe_exit(EX_DRIZZLEERR);
431
440
  }
432
441
 
433
442
  database_store.push_back(database); 
471
480
{
472
481
  int exit_code;
473
482
 
474
 
#if defined(ENABLE_NLS)
475
 
# if defined(HAVE_LOCALE_H)
476
 
  setlocale(LC_ALL, "");
477
 
# endif
478
 
  bindtextdomain("drizzle7", LOCALEDIR);
479
 
  textdomain("drizzle7");
480
 
#endif
481
 
 
482
 
  po::options_description commandline_options(_("Options used only in command line"));
 
483
  po::options_description commandline_options(N_("Options used only in command line"));
483
484
  commandline_options.add_options()
484
485
  ("all-databases,A", po::value<bool>(&opt_alldbs)->default_value(false)->zero_tokens(),
485
 
  _("Dump all the databases. This will be same as --databases with all databases selected."))
 
486
  N_("Dump all the databases. This will be same as --databases with all databases selected."))
486
487
  ("all-tablespaces,Y", po::value<bool>(&opt_alltspcs)->default_value(false)->zero_tokens(),
487
 
  _("Dump all the tablespaces."))
 
488
  N_("Dump all the tablespaces."))
488
489
  ("complete-insert,c", po::value<bool>(&opt_complete_insert)->default_value(false)->zero_tokens(),
489
 
  _("Use complete insert statements."))
 
490
  N_("Use complete insert statements."))
 
491
  ("compress,C", po::value<bool>(&opt_compress)->default_value(false)->zero_tokens(),
 
492
  N_("Use compression in server/client protocol."))
490
493
  ("flush-logs,F", po::value<bool>(&flush_logs)->default_value(false)->zero_tokens(),
491
 
  _("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"))
 
494
  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"))
492
495
  ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
493
 
  _("Continue even if we get an sql-error."))
494
 
  ("help,?", _("Display this help message and exit."))
 
496
  N_("Continue even if we get an sql-error."))
 
497
  ("help,?", N_("Display this help message and exit."))
495
498
  ("lock-all-tables,x", po::value<bool>(&opt_lock_all_tables)->default_value(false)->zero_tokens(),
496
 
  _("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."))
 
499
  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."))
 
500
  ("order-by-primary", po::value<bool>(&opt_order_by_primary)->default_value(false)->zero_tokens(),
 
501
  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."))
497
502
  ("single-transaction", po::value<bool>(&opt_single_transaction)->default_value(false)->zero_tokens(),
498
 
  _("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."))
 
503
  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."))
 
504
  ("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.")) 
499
505
  ("skip-opt", 
500
 
  _("Disable --opt. Disables --add-drop-table, --add-locks, --create-options, ---extended-insert and --disable-keys."))    
501
 
  ("tables", _("Overrides option --databases (-B)."))
 
506
  N_("Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys."))    
 
507
  ("tables", N_("Overrides option --databases (-B)."))
502
508
  ("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(10000),
503
 
  _("Number of rows before each output progress report (requires --verbose)."))
 
509
  N_("Number of rows before each output progress report (requires --verbose)."))
504
510
  ("verbose,v", po::value<bool>(&verbose)->default_value(false)->zero_tokens(),
505
 
  _("Print info about the various stages."))
506
 
  ("version,V", _("Output version information and exit."))
507
 
  ("skip-comments", _("Turn off Comments"))
508
 
  ("skip-create", _("Turn off create-options"))
509
 
  ("skip-extended-insert", _("Turn off extended-insert"))
510
 
  ("skip-dump-date", _( "Turn off dump date at the end of the output"))
511
 
  ("no-defaults", _("Do not read from the configuration files"))
 
511
  N_("Print info about the various stages."))
 
512
  ("version,V", N_("Output version information and exit."))
 
513
  ("skip-comments", N_("Turn off Comments"))
 
514
  ("skip-create", N_("Turn off create-options"))
 
515
  ("skip-extended-insert", N_("Turn off extended-insert"))
 
516
  ("skip-dump-date",N_( "Turn off dump date at the end of the output"))
 
517
  ("no-defaults", N_("Do not read from the configuration files"))
512
518
  ;
513
519
 
514
 
  po::options_description dump_options(_("Options specific to the drizzle client"));
 
520
  po::options_description dump_options(N_("Options specific to the drizzle client"));
515
521
  dump_options.add_options()
516
522
  ("add-drop-database", po::value<bool>(&opt_drop_database)->default_value(false)->zero_tokens(),
517
 
  _("Add a 'DROP DATABASE' before each create."))
518
 
  ("skip-drop-table", _("Do not add a 'drop table' before each create."))
 
523
  N_("Add a 'DROP DATABASE' before each create."))
 
524
  ("skip-drop-table", N_("Do not add a 'drop table' before each create."))
 
525
  ("allow-keywords", po::value<bool>(&opt_keywords)->default_value(false)->zero_tokens(),
 
526
  N_("Allow creation of column names that are keywords."))
519
527
  ("compact", po::value<bool>(&opt_compact)->default_value(false)->zero_tokens(),
520
 
  _("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"))
 
528
  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"))
521
529
  ("databases,B", po::value<bool>(&opt_databases)->default_value(false)->zero_tokens(),
522
 
  _("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."))
 
530
  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."))
 
531
  ("delayed-insert", po::value<bool>(&opt_delayed)->default_value(false)->zero_tokens(),
 
532
  N_("Insert rows with INSERT DELAYED;"))
523
533
  ("skip-disable-keys,K",
524
 
  _("'ALTER TABLE tb_name DISABLE KEYS;' and 'ALTER TABLE tb_name ENABLE KEYS;' will not be put in the output."))
 
534
  N_("'ALTER TABLE tb_name DISABLE KEYS; and 'ALTER TABLE tb_name ENABLE KEYS; will not be put in the output."))
525
535
  ("ignore-table", po::value<string>(),
526
 
  _("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"))
 
536
  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"))
527
537
  ("insert-ignore", po::value<bool>(&opt_ignore)->default_value(false)->zero_tokens(),
528
 
  _("Insert rows with INSERT IGNORE."))
 
538
  N_("Insert rows with INSERT IGNORE."))
 
539
  ("lines-terminated-by", po::value<string>(&lines_terminated)->default_value(""),
 
540
  N_("Lines in the i.file are terminated by ..."))
529
541
  ("no-autocommit", po::value<bool>(&opt_autocommit)->default_value(false)->zero_tokens(),
530
 
  _("Wrap a table's data in START TRANSACTION/COMMIT statements."))
 
542
  N_("Wrap tables with autocommit/commit statements."))
531
543
  ("no-create-db,n", po::value<bool>(&opt_create_db)->default_value(false)->zero_tokens(),
532
 
  _("'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."))
 
544
  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."))
 
545
  ("no-create-info,t", po::value<bool>(&opt_no_create_info)->default_value(false)->zero_tokens(),
 
546
  N_("Don't write table creation info."))
533
547
  ("no-data,d", po::value<bool>(&opt_no_data)->default_value(false)->zero_tokens(),
534
 
  _("No row information."))
 
548
  N_("No row information."))
 
549
  ("no-set-names,N", N_("Deprecated. Use --skip-set-charset instead."))
 
550
  ("set-charset", po::value<bool>(&opt_set_charset)->default_value(false)->zero_tokens(),
 
551
  N_("Enable set-name"))
 
552
  ("slow", N_("Buffer query instead of dumping directly to stdout."))
535
553
  ("replace", po::value<bool>(&opt_replace_into)->default_value(false)->zero_tokens(),
536
 
  _("Use REPLACE INTO instead of INSERT INTO."))
 
554
  N_("Use REPLACE INTO instead of INSERT INTO."))
 
555
  ("result-file,r", po::value<string>(),
 
556
  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)."))
537
557
  ("destination-type", po::value<string>()->default_value("stdout"),
538
 
  _("Where to send output to (stdout|database"))
 
558
  N_("Where to send output to (stdout|database"))
539
559
  ("destination-host", po::value<string>(&opt_destination_host)->default_value("localhost"),
540
 
  _("Hostname for destination db server (requires --destination-type=database)"))
541
 
  ("destination-port", po::value<uint16_t>(&opt_destination_port)->default_value(4427),
542
 
  _("Port number for destination db server (requires --destination-type=database)"))
 
560
  N_("Hostname for destination db server (requires --destination=database)"))
 
561
  ("destination-port", po::value<uint16_t>(&opt_destination_port)->default_value(3306),
 
562
  N_("Port number for destination db server (requires --destination=database)"))
543
563
  ("destination-user", po::value<string>(&opt_destination_user),
544
 
  _("User name for destination db server (resquires --destination-type=database)"))
 
564
  N_("User name for destination db server (resquires --destination=database)"))
545
565
  ("destination-password", po::value<string>(&opt_destination_password),
546
 
  _("Password for destination db server (requires --destination-type=database)"))
 
566
  N_("Password for destination db server (requires --destination=database)"))
547
567
  ("destination-database", po::value<string>(&opt_destination_database),
548
 
  _("The database in the destination db server (requires --destination-type=database, not for use with --all-databases)"))
549
 
  ("my-data-is-mangled", po::value<bool>(&opt_data_is_mangled)->default_value(false)->zero_tokens(),
550
 
  _("Do not make a UTF8 connection to MySQL, use if you have UTF8 data in a non-UTF8 table"))
 
568
  N_("The database in the destination db server (requires --destination=database, not for use with --all-databases)"))
551
569
  ;
552
570
 
553
 
  po::options_description client_options(_("Options specific to the client"));
 
571
  po::options_description client_options(N_("Options specific to the client"));
554
572
  client_options.add_options()
555
573
  ("host,h", po::value<string>(&current_host)->default_value("localhost"),
556
 
  _("Connect to host."))
 
574
  N_("Connect to host."))
557
575
  ("password,P", po::value<string>(&password)->default_value(PASSWORD_SENTINEL),
558
 
  _("Password to use when connecting to server. If password is not given it's solicited on the tty."))
 
576
  N_("Password to use when connecting to server. If password is not given it's solicited on the tty."))
559
577
  ("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),
560
 
  _("Port number to use for connection."))
 
578
  N_("Port number to use for connection."))
561
579
  ("user,u", po::value<string>(&current_user)->default_value(""),
562
 
  _("User for login if not current user."))
 
580
  N_("User for login if not current user."))
563
581
  ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
564
 
  _("The protocol of connection (mysql or drizzle)."))
 
582
  N_("The protocol of connection (mysql or drizzle)."))
565
583
  ;
566
584
 
567
 
  po::options_description hidden_options(_("Hidden Options"));
 
585
  po::options_description hidden_options(N_("Hidden Options"));
568
586
  hidden_options.add_options()
569
 
  ("database-used", po::value<vector<string> >(), _("Used to select the database"))
570
 
  ("Table-used", po::value<vector<string> >(), _("Used to select the tables"))
 
587
  ("database-used", po::value<vector<string> >(), N_("Used to select the database"))
 
588
  ("Table-used", po::value<vector<string> >(), N_("Used to select the tables"))
571
589
  ;
572
590
 
573
 
  po::options_description all_options(_("Allowed Options + Hidden Options"));
 
591
  po::options_description all_options(N_("Allowed Options + Hidden Options"));
574
592
  all_options.add(commandline_options).add(dump_options).add(client_options).add(hidden_options);
575
593
 
576
 
  po::options_description long_options(_("Allowed Options"));
 
594
  po::options_description long_options(N_("Allowed Options"));
577
595
  long_options.add(commandline_options).add(dump_options).add(client_options);
578
596
 
579
597
  std::string system_config_dir_dump(SYSCONFDIR); 
584
602
 
585
603
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
586
604
 
587
 
  if (user_config_dir.compare(0, 2, "~/") == 0)
588
 
  {
589
 
    char *homedir;
590
 
    homedir= getenv("HOME");
591
 
    if (homedir != NULL)
592
 
      user_config_dir.replace(0, 1, homedir);
593
 
  }
594
 
 
595
605
  po::positional_options_description p;
596
606
  p.add("database-used", 1);
597
607
  p.add("Table-used",-1);
659
669
  extended_insert= (vm.count("skip-extended-insert")) ? false : true;
660
670
  opt_dump_date= (vm.count("skip-dump-date")) ? false : true;
661
671
  opt_disable_keys= (vm.count("skip-disable-keys")) ? false : true;
 
672
  quick= (vm.count("slow")) ? false : true;
662
673
  opt_quoted= (vm.count("skip-quote-names")) ? false : true;
663
674
 
664
675
  if (vm.count("protocol"))
709
720
      tty_password= true;
710
721
  }
711
722
 
 
723
  if (vm.count("result-file"))
 
724
  {
 
725
    if (!(md_result_file= fopen(vm["result-file"].as<string>().c_str(), "w")))
 
726
      exit(1);
 
727
  }
 
728
 
 
729
  if (vm.count("no-set-names"))
 
730
  {
 
731
    opt_set_charset= 0;
 
732
  }
 
733
 
712
734
  if (! path.empty())
713
735
  { 
714
736
    opt_disable_keys= 0;
716
738
 
717
739
  if (vm.count("skip-opt"))
718
740
  {
719
 
    extended_insert= opt_drop= create_options= 0;
720
 
    opt_disable_keys= 0;
 
741
    extended_insert= opt_drop= quick= create_options= 0;
 
742
    opt_disable_keys= opt_set_charset= 0;
721
743
  }
722
744
 
723
745
  if (opt_compact)
724
746
  { 
725
747
    opt_comments= opt_drop= opt_disable_keys= 0;
 
748
    opt_set_charset= 0;
726
749
  }
727
750
 
728
751
  if (vm.count("opt"))
729
752
  {
730
 
    extended_insert= opt_drop= create_options= 1;
731
 
    opt_disable_keys= 1;
 
753
    extended_insert= opt_drop= quick= create_options= 1;
 
754
    opt_disable_keys= opt_set_charset= 1;
732
755
  }
733
756
 
734
757
  if (vm.count("tables"))
758
781
    free_resources();
759
782
    exit(exit_code);
760
783
  }
761
 
  try
762
 
  {
763
 
    db_connection = new DrizzleDumpConnection(current_host, opt_drizzle_port,
764
 
      current_user, opt_password, use_drizzle_protocol);
765
 
  }
766
 
  catch (std::exception&)
767
 
  {
768
 
    maybe_exit(EX_DRIZZLEERR);
769
 
  }
770
 
 
771
 
  if ((db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND) and (not opt_data_is_mangled))
 
784
 
 
785
  db_connection = new DrizzleDumpConnection(current_host, opt_drizzle_port,
 
786
    current_user, opt_password, use_drizzle_protocol);
 
787
 
 
788
  if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
772
789
    db_connection->queryNoResult("SET NAMES 'utf8'");
773
790
 
774
791
  if (vm.count("destination-type"))
810
827
    dump_selected_tables(database_used, vm["Table-used"].as< vector<string> >());
811
828
  }
812
829
 
813
 
  if (vm.count("Table-used") and opt_databases)
 
830
  if (vm.count("Table-used") && opt_databases)
814
831
  {
 
832
/*
 
833
 * This is not valid!
815
834
    vector<string> database_used= vm["database-used"].as< vector<string> >();
816
835
    vector<string> table_used= vm["Table-used"].as< vector<string> >();
817
836
 
821
840
    {
822
841
      database_used.insert(database_used.end(), *it);
823
842
    }
824
 
 
825
843
    dump_databases(database_used);
826
 
    dump_all_tables();
 
844
    dump_tables();
 
845
*/
827
846
  }
828
 
 
 
847
  
829
848
  if (vm.count("database-used") && ! vm.count("Table-used"))
830
849
  {
831
850
    dump_databases(vm["database-used"].as< vector<string> >());
832
851
    dump_all_tables();
833
852
  }
834
 
 
835
853
  if (opt_destination == DESTINATION_STDOUT)
836
854
    generate_dump();
837
855
  else
853
871
  */
854
872
err:
855
873
  delete db_connection;
856
 
  delete destination_connection;
 
874
  if (destination_connection)
 
875
    delete destination_connection;
857
876
  if (path.empty())
858
877
    write_footer(md_result_file);
859
878
  free_resources();