diff options
author | unknown <brian@zim.(none)> | 2005-11-24 09:56:40 -0800 |
---|---|---|
committer | unknown <brian@zim.(none)> | 2005-11-24 09:56:40 -0800 |
commit | b0b86ec10bd885744a9e968784e564fdbe2373ea (patch) | |
tree | 8f75754c4a3d76cf6e524d860fe5dd2ded08ff46 /client | |
parent | 817ee181c34d53caf2179a978c35c685437fb756 (diff) | |
download | mariadb-git-b0b86ec10bd885744a9e968784e564fdbe2373ea.tar.gz |
Its funny, I am reading through the forums and someone asks "Can I please have a REPLACE INTO, instead an INSERT INTO?" and I remember how often I have used a sed script to modify MySQL dumps to have exactly that.
So, use --replace and instead of getting INSERT INTO you will INSTEAD get REPLACE INTO. Buyer beward, REPLACE is a MySQL SQL, so you will not end up with a dump that can be used for other databases.
Though I hear you could just use a sed line to modify it back :)
client/client_priv.h:
New option for --replace
client/mysqldump.c:
Added option for REPLACE INTO instead of INSERT INTO
mysql-test/r/mysqldump.result:
Updated REsultes for replace into
mysql-test/t/mysqldump.test:
Added new test for --replace
Diffstat (limited to 'client')
-rw-r--r-- | client/client_priv.h | 3 | ||||
-rw-r--r-- | client/mysqldump.c | 14 |
2 files changed, 14 insertions, 3 deletions
diff --git a/client/client_priv.h b/client/client_priv.h index a9d5364df49..7d836189e2e 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -51,5 +51,6 @@ enum options_client #endif OPT_TRIGGERS, OPT_IGNORE_TABLE,OPT_INSERT_IGNORE,OPT_SHOW_WARNINGS,OPT_DROP_DATABASE, - OPT_TZ_UTC, OPT_AUTO_CLOSE + OPT_TZ_UTC, OPT_AUTO_CLOSE, + OPT_MYSQL_REPLACE_INTO }; diff --git a/client/mysqldump.c b/client/mysqldump.c index b92b971ea4f..4b4497802d8 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -92,6 +92,7 @@ static my_bool verbose=0,tFlag=0,dFlag=0,quick= 1, extended_insert= 1, opt_single_transaction=0, opt_comments= 0, opt_compact= 0, opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0, opt_complete_insert= 0, opt_drop_database= 0, + opt_replace_into= 0, opt_dump_triggers= 0, opt_routines=0, opt_tz_utc=1; static ulong opt_max_allowed_packet, opt_net_buffer_length; static MYSQL mysql_connection,*sock=0; @@ -339,6 +340,9 @@ static struct my_option my_long_options[] = {"quote-names",'Q', "Quote table and column names with backticks (`).", (gptr*) &opt_quoted, (gptr*) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, + {"replace-names", OPT_MYSQL_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.", + (gptr*) &opt_replace_into, (gptr*) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, + 0, 0}, {"result-file", 'r', "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).", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -1515,7 +1519,10 @@ static uint get_table_structure(char *table, char *db, char *table_type, */ if (write_data) { - dynstr_append_mem(&insert_pat, "INSERT ", 7); + if (opt_replace_into) + dynstr_append_mem(&insert_pat, "REPLACE ", 8); + else + dynstr_append_mem(&insert_pat, "INSERT ", 7); dynstr_append(&insert_pat, insert_option); dynstr_append_mem(&insert_pat, "INTO ", 5); dynstr_append(&insert_pat, opt_quoted_table); @@ -1592,7 +1599,10 @@ static uint get_table_structure(char *table, char *db, char *table_type, if (write_data) { - dynstr_append_mem(&insert_pat, "INSERT ", 7); + if (opt_replace_into) + dynstr_append_mem(&insert_pat, "REPLACE ", 8); + else + dynstr_append_mem(&insert_pat, "INSERT ", 7); dynstr_append(&insert_pat, insert_option); dynstr_append_mem(&insert_pat, "INTO ", 5); dynstr_append(&insert_pat, result_table); |