Merge lp:~ochedru/mydumper/complete-insert into lp:mydumper/0.6

Proposed by ochedru
Status: Needs review
Proposed branch: lp:~ochedru/mydumper/complete-insert
Merge into: lp:mydumper/0.6
Diff against target: 71 lines (+30/-2)
2 files modified
docs/mydumper_usage.rst (+4/-0)
mydumper.c (+26/-2)
To merge this branch: bzr merge lp:~ochedru/mydumper/complete-insert
Reviewer Review Type Date Requested Status
Percona RDBA Pending
Review via email: mp+245199@code.launchpad.net

Description of the change

Added option --complete-insert

To post a comment you must log in.

Unmerged revisions

155. By ochedru <ochedru@mydeb>

Added option --complete-insert

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'docs/mydumper_usage.rst'
2--- docs/mydumper_usage.rst 2014-06-04 18:29:03 +0000
3+++ docs/mydumper_usage.rst 2014-12-19 14:56:44 +0000
4@@ -175,3 +175,7 @@
5 .. option:: --use-savepoints
6
7 Use savepoints to reduce metadata locking issues, needs SUPER privilege
8+
9+.. option:: --complete-insert
10+
11+ Use complete INSERT statements that include column names.
12
13=== modified file 'mydumper.c'
14--- mydumper.c 2014-10-27 14:49:27 +0000
15+++ mydumper.c 2014-12-19 14:56:44 +0000
16@@ -102,6 +102,7 @@
17 guint less_locking_threads = 0;
18 guint updated_since = 0;
19 guint trx_consistency_only = 0;
20+guint complete_insert = 0;
21
22 // For daemon mode, 0 or 1
23 guint dump_number= 0;
24@@ -144,6 +145,7 @@
25 { "lock-all-tables", 0, 0, G_OPTION_ARG_NONE, &lock_all_tables, "Use LOCK TABLE for all, instead of FTWRL", NULL},
26 { "updated-since", 'U', 0, G_OPTION_ARG_INT, &updated_since, "Use Update_time to dump only tables updated in the last U days", NULL},
27 { "trx-consistency-only", 0, 0, G_OPTION_ARG_NONE, &trx_consistency_only, "Transactional consistency only", NULL},
28+ { "complete-insert", 0, 0, G_OPTION_ARG_NONE, &complete_insert, "Use complete INSERT statements that include column names", NULL},
29 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
30 };
31
32@@ -1952,7 +1954,18 @@
33 return num_rows;
34 }
35 }
36- g_string_printf(statement, "INSERT INTO `%s` VALUES", table);
37+ if (complete_insert) {
38+ g_string_printf(statement, "INSERT INTO `%s`(", table);
39+ for (i = 0; i < num_fields; ++i) {
40+ if (i > 0) {
41+ g_string_append_c(statement, ',');
42+ }
43+ g_string_append_printf(statement, "`%s`", fields[i].name);
44+ }
45+ g_string_append(statement, ") VALUES");
46+ } else {
47+ g_string_printf(statement, "INSERT INTO `%s` VALUES", table);
48+ }
49 num_rows_st = 0;
50 }
51
52@@ -2031,7 +2044,18 @@
53 g_string_append(statement, statement_row->str);
54 }
55 else {
56- g_string_printf(statement, "INSERT INTO `%s` VALUES", table);
57+ if (complete_insert) {
58+ g_string_printf(statement, "INSERT INTO `%s`(", table);
59+ for (i = 0; i < num_fields; ++i) {
60+ if (i > 0) {
61+ g_string_append_c(statement, ',');
62+ }
63+ g_string_append_printf(statement, "`%s`", fields[i].name);
64+ }
65+ g_string_append(statement, ") VALUES");
66+ } else {
67+ g_string_printf(statement, "INSERT INTO `%s` VALUES", table);
68+ }
69 g_string_append(statement, statement_row->str);
70 }
71 }

Subscribers

People subscribed via source and target branches