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 */
81
static 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;
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)
180
180
std::vector<DrizzleDumpDatabase*>::iterator i;
182
cout << endl << "SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;" << endl;
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;
181
189
for (i= database_store.begin(); i != database_store.end(); ++i)
183
191
DrizzleDumpDatabase *database= *i;
184
192
cout << *database;
197
cout << "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;"
198
<< endl << "SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;" << endl;
201
cout << "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;" << endl;
188
204
void generate_dump_db(void)
195
211
sbuf.setConnection(destination_connection);
196
212
std::ostream sout(&sbuf);
214
sout << "SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;" << endl;
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;
197
222
for (i= database_store.begin(); i != database_store.end(); ++i)
199
224
DrizzleDumpDatabase *database= *i;
200
225
sout << *database;
230
sout << "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;" << endl;
231
sout << "SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;" << endl;
234
sout << "SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;" << endl;
215
248
die(EX_EOF, _("Got errno %d on write"), errno);
218
static void write_header(FILE *sql_file, char *db_name)
251
static void write_header(char *db_name)
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 :
230
fputs("-- ------------------------------------------------------\n",
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)");
241
"\nSET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;\n");
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");
253
if ((not opt_compact) and (opt_comments))
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;
249
267
} /* write_header */
365
379
std::string query;
366
380
DrizzleDumpDatabase *database;
383
std::cerr << _("-- Retrieving database structures...") << std::endl;
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)
412
429
DrizzleDumpDatabase *database;
413
DrizzleDumpTable *table;
415
431
if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
416
432
database= new DrizzleDumpDatabaseMySQL(db, db_connection);
418
434
database= new DrizzleDumpDatabaseDrizzle(db, db_connection);
436
database->populateTables(table_names);
420
438
database_store.push_back(database);
422
for (vector<string>::const_iterator it= table_names.begin(); it != table_names.end(); ++it)
425
if (db_connection->getServerType() == DrizzleDumpConnection::SERVER_MYSQL_FOUND)
426
table= new DrizzleDumpTableMySQL(temp, db_connection);
428
table= new DrizzleDumpTableDrizzle(temp, db_connection);
429
database->tables.push_back(table);
431
database_store.push_back(database);
434
441
} /* dump_selected_tables */
790
797
if (path.empty() && vm.count("database-used"))
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());
796
803
if ((opt_lock_all_tables) && do_flush_tables_read_lock())