~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Andrew Hutchings
  • Date: 2010-09-23 20:32:31 UTC
  • mto: (1792.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1793.
  • Revision ID: andrew@linuxjedi.co.uk-20100923203231-9bpfjwm0fih91ize
Fix various bugs

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
static bool  verbose= false;
 
81
bool  verbose= false;
82
82
static bool use_drizzle_protocol= false;
83
83
static bool quick= true;
84
84
static bool ignore_errors= false;
88
88
static bool opt_delayed= false; 
89
89
static bool create_options= true; 
90
90
static bool opt_quoted= false;
91
 
static bool opt_databases= false; 
92
 
static bool opt_alldbs= false; 
 
91
bool opt_databases= false; 
 
92
bool opt_alldbs= false; 
93
93
static bool opt_lock_all_tables= false;
94
94
static bool opt_set_charset= false; 
95
95
static bool opt_dump_date= true;
156
156
 
157
157
static void maybe_exit(int error);
158
158
static void die(int error, const char* reason, ...);
159
 
static void write_header(FILE *sql_file, char *db_name);
 
159
static void write_header(char *db_name);
160
160
static int dump_selected_tables(const string &db, const vector<string> &table_names);
161
161
static int dump_databases(const vector<string> &db_names);
162
162
static int dump_all_databases(void);
178
178
void generate_dump(void)
179
179
{
180
180
  std::vector<DrizzleDumpDatabase*>::iterator i;
 
181
  if (opt_set_charset)
 
182
    cout << endl << "SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;" << endl;
 
183
 
 
184
  if (path.empty())
 
185
  {
 
186
    cout << endl << "SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;"
 
187
      << endl << "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;" << endl;
 
188
  }
181
189
  for (i= database_store.begin(); i != database_store.end(); ++i)
182
190
  {
183
191
    DrizzleDumpDatabase *database= *i;
184
192
    cout << *database;
185
193
  }
 
194
 
 
195
  if (path.empty())
 
196
  {
 
197
    cout << "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;"
 
198
      << endl << "SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;" << endl;
 
199
  }
 
200
  if (opt_set_charset)
 
201
    cout << "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;" << endl;
186
202
}
187
203
 
188
204
void generate_dump_db(void)
194
210
    false);
195
211
  sbuf.setConnection(destination_connection);
196
212
  std::ostream sout(&sbuf);
 
213
  if (opt_set_charset)
 
214
    sout << "SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;" << endl;
 
215
 
 
216
  if (path.empty())
 
217
  {
 
218
    sout << "SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;" << endl;
 
219
    sout << "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;" << endl;
 
220
  }
 
221
 
197
222
  for (i= database_store.begin(); i != database_store.end(); ++i)
198
223
  {
199
224
    DrizzleDumpDatabase *database= *i;
200
225
    sout << *database;
201
226
  }
 
227
 
 
228
  if (path.empty())
 
229
  {
 
230
    sout << "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;" << endl;
 
231
    sout << "SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;" << endl;
 
232
  }
 
233
  if (opt_set_charset)
 
234
    sout << "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;" << endl;
202
235
}
203
236
 
204
237
/*
215
248
    die(EX_EOF, _("Got errno %d on write"), errno);
216
249
}
217
250
 
218
 
static void write_header(FILE *sql_file, char *db_name)
 
251
static void write_header(char *db_name)
219
252
{
220
 
  if (! opt_compact)
221
 
  { 
222
 
    if (opt_comments)
223
 
    {
224
 
      fprintf(sql_file,
225
 
              "-- drizzledump %s libdrizzle %s, for %s-%s (%s)\n--\n",
226
 
              VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
227
 
      fprintf(sql_file, "-- Host: %s    Database: %s\n",
228
 
              ! current_host.empty() ? current_host.c_str() : "localhost", db_name ? db_name :
229
 
              "");
230
 
      fputs("-- ------------------------------------------------------\n",
231
 
            sql_file);
232
 
      fprintf(sql_file, "-- Server version\t%s",
233
 
              db_connection->getServerVersion());
234
 
      if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
235
 
        fprintf(sql_file, " (MySQL server)");
236
 
      else if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_DRIZZLE_FOUND)
237
 
        fprintf(sql_file, " (Drizzle server)");
238
 
    }
239
 
    if (opt_set_charset)
240
 
      fprintf(sql_file,
241
 
              "\nSET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;\n");
242
 
 
243
 
    if (path.empty())
244
 
    {
245
 
      fprintf(md_result_file,"\nSET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;\nSET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\n");
246
 
    }
247
 
    check_io(sql_file);
 
253
  if ((not opt_compact) and (opt_comments))
 
254
  {
 
255
    cout << "-- drizzledump " << VERSION << " libdrizzle "
 
256
      << drizzle_version() << ", for " << HOST_VENDOR << "-" << HOST_OS
 
257
      << " (" << HOST_CPU << ")" << endl << "--" << endl;
 
258
    cout << "-- Host: " << current_host << "    Database: " << db_name << endl;
 
259
    cout << "-- ------------------------------------------------------" << endl;
 
260
    cout << "-- Server version\t" << db_connection->getServerVersion();
 
261
    if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
 
262
      cout << " (MySQL server)";
 
263
    else if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_DRIZZLE_FOUND)
 
264
      cout << " (Drizzle server)";
 
265
    cout << endl << endl;
248
266
  }
249
267
} /* write_header */
250
268
 
253
271
{
254
272
  if (! opt_compact)
255
273
  {
256
 
    if (path.empty())
257
 
    {
258
 
      fprintf(md_result_file,"SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;\nSET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;\n");
259
 
    }
260
 
    if (opt_set_charset)
261
 
      fprintf(sql_file, "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;\n");
262
274
    if (opt_comments)
263
275
    {
264
276
      if (opt_dump_date)
353
365
  if (ignore_errors)
354
366
    return;
355
367
  delete db_connection;
 
368
  if (destination_connection)
 
369
    delete destination_connection;
356
370
  free_resources();
357
371
  exit(error);
358
372
}
365
379
  std::string query;
366
380
  DrizzleDumpDatabase *database;
367
381
 
 
382
  if (verbose)
 
383
    std::cerr << _("-- Retrieving database structures...") << std::endl;
 
384
 
368
385
  /* Blocking the MySQL privilege tables too because we can't import them due to bug#646187 */
369
386
  if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
370
387
    query= "SELECT SCHEMA_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME NOT IN ('information_schema', 'performance_schema', 'mysql')";
410
427
static int dump_selected_tables(const string &db, const vector<string> &table_names)
411
428
{
412
429
  DrizzleDumpDatabase *database;
413
 
  DrizzleDumpTable *table;
414
430
 
415
431
  if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
416
432
    database= new DrizzleDumpDatabaseMySQL(db, db_connection);
417
433
  else
418
434
    database= new DrizzleDumpDatabaseDrizzle(db, db_connection);
419
435
 
 
436
  database->populateTables(table_names);
 
437
 
420
438
  database_store.push_back(database); 
421
439
 
422
 
  for (vector<string>::const_iterator it= table_names.begin(); it != table_names.end(); ++it)
423
 
  {
424
 
    string temp= *it;
425
 
    if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
426
 
      table= new DrizzleDumpTableMySQL(temp, db_connection);
427
 
    else
428
 
      table= new DrizzleDumpTableDrizzle(temp, db_connection);
429
 
    database->tables.push_back(table);
430
 
  }
431
 
  database_store.push_back(database);
432
 
 
433
440
  return 0;
434
441
} /* dump_selected_tables */
435
442
 
790
797
  if (path.empty() && vm.count("database-used"))
791
798
  {
792
799
    string database_used= *vm["database-used"].as< vector<string> >().begin();
793
 
    write_header(md_result_file, (char *)database_used.c_str());
 
800
    write_header((char *)database_used.c_str());
794
801
  }
795
802
 
796
803
  if ((opt_lock_all_tables) && do_flush_tables_read_lock())
858
865
  */
859
866
err:
860
867
  delete db_connection;
 
868
  if (destination_connection)
 
869
    delete destination_connection;
861
870
  if (path.empty())
862
871
    write_footer(md_result_file);
863
872
  free_resources();