83
82
opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0,
84
83
opt_complete_insert= 0, opt_drop_database= 0,
85
84
opt_replace_into= 0,
85
opt_routines=0, opt_tz_utc=1,
87
86
opt_slave_apply= 0,
88
87
opt_include_master_host_port= 0,
116
115
FILE *md_result_file= 0;
117
116
FILE *stderror_file=0;
118
static uint opt_protocol= DRIZZLE_PROTOCOL_TCP;
120
121
Constant for detection of default value of default_charset.
121
122
If default_charset is equal to drizzle_universal_client_charset, then
122
123
it is the default value which assigned at the very beginning of main().
124
125
static const char *drizzle_universal_client_charset=
125
DRIZZLE_UNIVERSAL_CLIENT_CHARSET;
126
MYSQL_UNIVERSAL_CLIENT_CHARSET;
126
127
static char *default_charset;
127
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
128
static const CHARSET_INFO *charset_info= &my_charset_latin1;
128
129
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
129
130
/* have we seen any VIEWs during table scanning? */
130
131
bool seen_views= 0;
133
134
"MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
134
135
"MAXDB", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS",
138
139
#define MASK_ANSI_QUOTES \
379
380
{"routines", 'R', "Dump stored routines (functions and procedures).",
380
381
(char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
381
382
NO_ARG, 0, 0, 0, 0, 0, 0},
383
{"set-charset", OPT_SET_CHARSET,
384
"Add 'SET NAMES default_character_set' to the output.",
385
(char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
382
387
{"set-variable", 'O',
383
388
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
384
389
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
410
415
(char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
411
416
{"tables", OPT_TABLES, "Overrides option --databases (-B).",
412
417
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
418
{"tz-utc", OPT_TZ_UTC,
419
"SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones.",
420
(char**) &opt_tz_utc, (char**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
413
421
#ifndef DONT_ALLOW_USER_CHANGE
414
422
{"user", 'u', "User for login if not current user.",
415
423
(char**) ¤t_user, (char**) ¤t_user, 0, GET_STR, REQUIRED_ARG,
505
513
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
506
514
puts("Dumping definition and data DRIZZLE database or table");
507
515
short_usage_sub();
508
print_defaults("drizzle",load_default_groups);
516
print_defaults("my",load_default_groups);
509
517
my_print_help(my_long_options);
510
518
my_print_variables(my_long_options);
551
559
if (opt_set_charset)
552
560
fprintf(sql_file,
561
"\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;"
562
"\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;"
553
563
"\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"
554
564
"\n/*!40101 SET NAMES %s */;\n",default_charset);
568
fprintf(sql_file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
569
fprintf(sql_file, "/*!40103 SET TIME_ZONE='+00:00' */;\n");
558
574
fprintf(md_result_file,"\
581
600
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n");
583
602
if (opt_set_charset)
584
fprintf(sql_file, "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
604
"/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n"
605
"/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n"
606
"/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
608
"/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
609
fputs("\n", sql_file);
585
610
if (opt_comments)
587
612
if (opt_dump_date)
602
627
static void free_table_ent(char *key)
629
my_free(key, MYF(0));
608
static unsigned char* get_table_key(const char *entry, size_t *length,
633
static uchar* get_table_key(const char *entry, size_t *length,
609
634
bool not_used __attribute__((unused)))
611
636
*length= strlen(entry);
612
return (unsigned char*) entry;
637
return (uchar*) entry;
697
722
fprintf(stderr, "Illegal use of option --ignore-table=<database>.<table>\n");
700
if (my_hash_insert(&ignore_table, (unsigned char*)my_strdup(argument, MYF(0))))
725
if (my_hash_insert(&ignore_table, (uchar*)my_strdup(argument, MYF(0))))
717
742
&err_ptr, &error_len);
720
strmake(buff, err_ptr, min((uint32_t)sizeof(buff), error_len));
745
strmake(buff, err_ptr, min(sizeof(buff), error_len));
721
746
fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
729
end= my_stpcpy(end, compatible_mode_names[i]);
730
end= my_stpcpy(end, ",");
754
end= stpcpy(end, compatible_mode_names[i]);
755
end= stpcpy(end, ",");
733
758
if (end!=compatible_mode_normal_str)
737
762
been reset yet by --default-character-set=xxx.
739
764
if (default_charset == drizzle_universal_client_charset)
740
default_charset= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
765
default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
753
778
opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
755
780
md_result_file= stdout;
756
load_defaults("drizzle",load_default_groups,argc,argv);
781
load_defaults("my",load_default_groups,argc,argv);
757
782
defaults_argv= *argv;
759
784
if (hash_init(&ignore_table, charset_info, 16, 0, 0,
763
788
/* Don't copy internal log tables */
764
789
if (my_hash_insert(&ignore_table,
765
(unsigned char*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
766
my_hash_insert(&ignore_table,
767
(unsigned char*) my_strdup("mysql.schema", MYF(MY_WME))) ||
768
my_hash_insert(&ignore_table,
769
(unsigned char*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
770
my_hash_insert(&ignore_table,
771
(unsigned char*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
772
my_hash_insert(&ignore_table,
773
(unsigned char*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
774
my_hash_insert(&ignore_table,
775
(unsigned char*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
790
(uchar*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
791
my_hash_insert(&ignore_table,
792
(uchar*) my_strdup("mysql.schema", MYF(MY_WME))) ||
793
my_hash_insert(&ignore_table,
794
(uchar*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
795
my_hash_insert(&ignore_table,
796
(uchar*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
797
my_hash_insert(&ignore_table,
798
(uchar*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
799
my_hash_insert(&ignore_table,
800
(uchar*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
778
803
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
998
1023
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
999
convert_dirname(tmp_path,path,NULL);
1024
convert_dirname(tmp_path,path,NullS);
1000
1025
res= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4),
1001
1026
O_WRONLY, MYF(MY_WME));
1008
1033
if (md_result_file && md_result_file != stdout)
1009
1034
my_fclose(md_result_file, MYF(0));
1035
my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
1011
1036
if (hash_inited(&ignore_table))
1012
1037
hash_free(&ignore_table);
1013
1038
if (defaults_argv)
1036
1061
static int connect_to_db(char *host, char *user,char *passwd)
1063
char buff[20+FN_REFLEN];
1038
1066
verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1039
1067
drizzle_create(&drizzle_connection);
1040
1068
if (opt_compress)
1041
drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NULL);
1069
drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NullS);
1071
drizzle_options(&drizzle_connection,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
1072
drizzle_options(&drizzle_connection, DRIZZLE_SET_CHARSET_NAME, default_charset);
1042
1073
if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
1043
1074
NULL,opt_drizzle_port, NULL,
1046
1077
DB_error(&drizzle_connection, "when trying to connect");
1080
if (drizzle_get_server_version(&drizzle_connection) < 40100)
1082
/* Don't dump SET NAMES with a pre-4.1 server (bug#7997). */
1085
/* Don't switch charsets for 4.1 and earlier. (bug#34192). */
1086
server_supports_switching_charsets= false;
1089
set time_zone to UTC to allow dumping date types between servers with
1090
different time zone settings
1094
snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
1095
if (drizzle_query_with_error_report(drizzle, 0, buff))
1051
1099
} /* connect_to_db */
1068
1116
if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1069
1117
die(EX_DRIZZLEERR, "Couldn't allocate memory");
1071
drizzle_escape_string(tmp, pos, length);
1119
drizzle_real_escape_string(&drizzle_connection, tmp, pos, length);
1072
1120
fputc('\'', file);
1073
1121
fputs(tmp, file);
1074
1122
fputc('\'', file);
1075
1123
check_io(file);
1124
my_free(tmp, MYF(MY_WME));
1078
1126
} /* unescape */
1216
1264
print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name,
1217
..., attribute_name_n, attribute_value_n, NULL)
1265
..., attribute_name_n, attribute_value_n, NullS)
1218
1266
xml_file - output file
1219
1267
sbeg - line beginning
1220
1268
line_end - line ending
1252
1300
va_start(arg_list, first_attribute_name);
1253
1301
attribute_name= first_attribute_name;
1254
while (attribute_name != NULL)
1302
while (attribute_name != NullS)
1256
1304
attribute_value= va_arg(arg_list, char *);
1257
assert(attribute_value != NULL);
1305
assert(attribute_value != NullS);
1259
1307
fputc(' ', xml_file);
1260
1308
fputs(attribute_name, xml_file);
1369
1417
/* sakaik got the idea to to provide blob's in hex notation. */
1370
1418
const char *ptr= str, *end= ptr + len;
1371
1419
for (; ptr < end ; ptr++)
1372
fprintf(output_file, "%02X", *((unsigned char *)ptr));
1420
fprintf(output_file, "%02X", *((uchar *)ptr));
1373
1421
check_io(output_file);
1520
1568
if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1521
1569
fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1571
my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1576
my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1530
1578
if (drizzle_num_rows(result))
1562
1612
fprintf(sql_file, ",\n %s %s",
1563
1613
quote_name(row[0], name_buff, 0), row[1]);
1565
fprintf(sql_file, "\n) */;\n");
1617
"SET character_set_client = @saved_cs_client;\n");
1566
1619
check_io(sql_file);
1578
1631
row= drizzle_fetch_row(result);
1580
fprintf(sql_file, "%s;\n", row[1]);
1634
"SET @saved_cs_client = @@character_set_client;\n"
1635
"SET character_set_client = utf8;\n"
1637
"SET character_set_client = @saved_cs_client;\n",
1582
1640
check_io(sql_file);
1583
1641
drizzle_free_result(result);
1661
1719
fprintf(sql_file, "CREATE TABLE %s (\n", result_table);
1663
1721
print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table,
1665
1723
check_io(sql_file);
2008
2066
discarding SHOW CREATE EVENT statements generation. The myslq.event
2009
2067
table data should be skipped too.
2011
if (!opt_events && !my_strcasecmp(&my_charset_utf8_general_ci, db, "mysql") &&
2012
!my_strcasecmp(&my_charset_utf8_general_ci, table, "event"))
2069
if (!opt_events && !my_strcasecmp(&my_charset_latin1, db, "mysql") &&
2070
!my_strcasecmp(&my_charset_latin1, table, "event"))
2014
2072
verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2031
2089
Convert the path to native os format
2032
2090
and resolve to the full filepath.
2034
convert_dirname(tmp_path,path,NULL);
2092
convert_dirname(tmp_path,path,NullS);
2035
2093
my_load_path(tmp_path, tmp_path, NULL);
2036
2094
fn_format(filename, table, tmp_path, ".txt", MYF(MY_UNPACK_FILENAME));
2159
2217
init_length=(uint) insert_pat.length()+4;
2161
2219
print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
2163
2221
if (opt_autocommit)
2165
2223
fprintf(md_result_file, "set autocommit=0;\n");
2236
2294
extended_row.append("'");
2237
drizzle_escape_string(tmp_str,
2295
drizzle_real_escape_string(&drizzle_connection,
2239
2298
extended_row.append(tmp_str);
2240
2299
extended_row.append("'");
2278
2337
/* Define xsi:type="xs:hexBinary" for hex encoded data */
2279
2338
print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2280
field->name, "xsi:type=", "xs:hexBinary", NULL);
2339
field->name, "xsi:type=", "xs:hexBinary", NullS);
2281
2340
print_blob_as_hex(md_result_file, row[i], length);
2285
2344
print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2345
field->name, NullS);
2287
2346
print_quoted_xml(md_result_file, row[i], length);
2289
2348
fputs("</field>\n", md_result_file);
2305
2364
print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2365
field->name, NullS);
2307
2366
fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
2308
2367
md_result_file);
2309
2368
fputs("</field>\n", md_result_file);
2527
2586
static int init_dumping(char *database, int init_func(char*))
2529
2588
if (drizzle_get_server_version(drizzle) >= 50003 &&
2530
!my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
2589
!my_strcasecmp(&my_charset_latin1, database, "information_schema"))
2533
2592
if (drizzle_select_db(drizzle, database))
2566
2625
/* Return 1 if we should copy the table */
2568
static bool include_table(const unsigned char *hash_key, size_t len)
2627
static bool include_table(const uchar *hash_key, size_t len)
2570
2629
return !hash_search(&ignore_table, hash_key, len);
2578
2637
char table_buff[NAME_LEN*2+3];
2579
2638
char hash_key[2*NAME_LEN+2]; /* "db.tablename" */
2580
2639
char *afterdot;
2581
int using_mysql_db= my_strcasecmp(&my_charset_utf8_general_ci, database, "mysql");
2584
afterdot= my_stpcpy(hash_key, database);
2640
int using_mysql_db= my_strcasecmp(&my_charset_latin1, database, "mysql");
2643
afterdot= stpcpy(hash_key, database);
2585
2644
*afterdot++= '.';
2587
2646
if (init_dumping(database, init_dumping_tables))
2590
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NULL);
2649
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
2591
2650
if (lock_tables)
2594
2653
query= "LOCK TABLES ";
2595
2654
for (numrows= 0 ; (table= getTableName(1)) ; )
2597
char *end= my_stpcpy(afterdot, table);
2598
if (include_table((unsigned char*) hash_key,end - hash_key))
2656
char *end= stpcpy(afterdot, table);
2657
if (include_table((uchar*) hash_key,end - hash_key))
2601
2660
query.append( quote_name(table, table_buff, 1));
2616
2675
while ((table= getTableName(0)))
2618
char *end= my_stpcpy(afterdot, table);
2619
if (include_table((unsigned char*) hash_key, end - hash_key))
2677
char *end= stpcpy(afterdot, table);
2678
if (include_table((uchar*) hash_key, end - hash_key))
2621
2680
dump_table(table,database);
2681
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2629
2688
check_io(md_result_file);
2631
2690
if (lock_tables)
2632
drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2691
VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2633
2692
if (flush_privileges && using_mysql_db == 0)
2635
2694
fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
2665
2724
quote_for_like(old_table_name, show_name_buff));
2667
2726
if (drizzle_query_with_error_report(drizzle, 0, query))
2670
2729
if ((table_res= drizzle_store_result(drizzle)))
2752
2811
/* We shall countinue here, if --force was given */
2755
print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
2814
print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS);
2757
2816
/* Dump each selected table */
2758
2817
for (pos= dump_tables; pos < end; pos++)
2759
2818
dump_table(*pos, db);
2761
2820
free_root(&root, MYF(0));
2821
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2767
2826
check_io(md_result_file);
2769
2828
if (lock_tables)
2770
drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
2829
VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2772
2831
} /* dump_selected_tables */
3049
3108
for (; pos != end && *pos != ','; pos++) ;
3050
3109
var_len= (uint32_t) (pos - start);
3051
strmake(buff, start, min((uint32_t)sizeof(buff), var_len));
3110
strmake(buff, start, min(sizeof(buff), var_len));
3052
3111
find= find_type(buff, lib, var_len);
3173
3232
If these two types, we do want to skip dumping the table
3175
3234
if (!opt_no_data &&
3176
(!my_strcasecmp(&my_charset_utf8_general_ci, table_type, "MRG_MyISAM") ||
3235
(!my_strcasecmp(&my_charset_latin1, table_type, "MRG_MyISAM") ||
3177
3236
!strcmp(table_type,"MRG_ISAM")))
3178
3237
result= IGNORE_DATA;
3253
3312
drizzle_data_seek(res, 0);
3254
3313
row= drizzle_fetch_row(res);
3255
3314
quoted_field= quote_name(row[4], buff, 0);
3256
end= my_stpcpy(result, quoted_field);
3315
end= stpcpy(result, quoted_field);
3257
3316
while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1)
3259
3318
quoted_field= quote_name(row[4], buff, 0);
3260
end= strxmov(end, ",", quoted_field, NULL);
3319
end= strxmov(end, ",", quoted_field, NullS);