Merge lp:~dshrews/drizzle/bug643630 into lp:~drizzle-trunk/drizzle/development

Proposed by David Shrewsbury
Status: Merged
Approved by: Brian Aker
Approved revision: 1787
Merged at revision: 1789
Proposed branch: lp:~dshrews/drizzle/bug643630
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 121 lines (+56/-5)
4 files modified
drizzled/message/statement_transform.cc (+29/-5)
plugin/transaction_log/tests/r/embedded_quotes.result (+10/-0)
plugin/transaction_log/tests/t/embedded_quotes-master.opt (+1/-0)
plugin/transaction_log/tests/t/embedded_quotes.test (+16/-0)
To merge this branch: bzr merge lp:~dshrews/drizzle/bug643630
Reviewer Review Type Date Requested Status
Drizzle Merge Team Pending
Review via email: mp+36392@code.launchpad.net

Description of the change

Properly escape embedded quotes in column values when transforming GPB messages into SQL. Adds a test case for this too.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'drizzled/message/statement_transform.cc'
2--- drizzled/message/statement_transform.cc 2010-09-20 17:39:56 +0000
3+++ drizzled/message/statement_transform.cc 2010-09-22 21:59:41 +0000
4@@ -51,6 +51,20 @@
5 namespace message
6 {
7
8+static void escapeEmbeddedQuotes(string &s, const char quote='\'')
9+{
10+ string::iterator it;
11+
12+ for (it= s.begin(); it != s.end(); ++it)
13+ {
14+ if (*it == quote)
15+ {
16+ it= s.insert(it, quote);
17+ ++it; // advance back to the quote
18+ }
19+ }
20+}
21+
22 /* Incredibly similar to append_unescaped() in table.cc, but for std::string */
23 static void append_escaped_string(std::string *res, const std::string &input, const char quote='\'')
24 {
25@@ -408,7 +422,9 @@
26 }
27 else
28 {
29- destination.append(record.insert_value(x));
30+ string tmp(record.insert_value(x));
31+ escapeEmbeddedQuotes(tmp);
32+ destination.append(tmp);
33 }
34 }
35
36@@ -472,7 +488,9 @@
37 }
38 else
39 {
40- destination.append(data.record(x).insert_value(y));
41+ string tmp(data.record(x).insert_value(y));
42+ escapeEmbeddedQuotes(tmp);
43+ destination.append(tmp);
44 }
45
46 if (should_quote_field_value)
47@@ -567,7 +585,9 @@
48 }
49 else
50 {
51- destination.append(record.after_value(x));
52+ string tmp(record.after_value(x));
53+ escapeEmbeddedQuotes(tmp);
54+ destination.append(tmp);
55 }
56 }
57
58@@ -690,7 +710,9 @@
59 }
60 else
61 {
62- destination.append(record.key_value(x));
63+ string tmp(record.key_value(x));
64+ escapeEmbeddedQuotes(tmp);
65+ destination.append(tmp);
66 }
67
68 if (should_quote_field_value)
69@@ -759,7 +781,9 @@
70 }
71 else
72 {
73- destination.append(data.record(x).key_value(y));
74+ string tmp(data.record(x).key_value(y));
75+ escapeEmbeddedQuotes(tmp);
76+ destination.append(tmp);
77 }
78
79 if (should_quote_field_value)
80
81=== added file 'plugin/transaction_log/tests/r/embedded_quotes.result'
82--- plugin/transaction_log/tests/r/embedded_quotes.result 1970-01-01 00:00:00 +0000
83+++ plugin/transaction_log/tests/r/embedded_quotes.result 2010-09-22 21:59:41 +0000
84@@ -0,0 +1,10 @@
85+CREATE TABLE t (a INT NOT NULL PRIMARY KEY, b VARCHAR(10));
86+INSERT INTO t VALUES (1, "don't");
87+START TRANSACTION;
88+CREATE TABLE `test`.`t` ( `a` INT NOT NULL, `b` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL, PRIMARY KEY (`a`) ) ENGINE=InnoDB COLLATE = utf8_general_ci;
89+COMMIT;
90+START TRANSACTION;
91+INSERT INTO `test`.`t` (`a`,`b`) VALUES (1,'don''t');
92+COMMIT;
93+DROP TABLE t;
94+SET GLOBAL transaction_log_truncate_debug= true;
95
96=== added file 'plugin/transaction_log/tests/t/embedded_quotes-master.opt'
97--- plugin/transaction_log/tests/t/embedded_quotes-master.opt 1970-01-01 00:00:00 +0000
98+++ plugin/transaction_log/tests/t/embedded_quotes-master.opt 2010-09-22 21:59:41 +0000
99@@ -0,0 +1,1 @@
100+--transaction-log.enable
101
102=== added file 'plugin/transaction_log/tests/t/embedded_quotes.test'
103--- plugin/transaction_log/tests/t/embedded_quotes.test 1970-01-01 00:00:00 +0000
104+++ plugin/transaction_log/tests/t/embedded_quotes.test 2010-09-22 21:59:41 +0000
105@@ -0,0 +1,16 @@
106+#
107+# Tests for properly escaping embedded quotes when reading from the transaction log
108+#
109+
110+CREATE TABLE t (a INT NOT NULL PRIMARY KEY, b VARCHAR(10));
111+
112+INSERT INTO t VALUES (1, "don't");
113+
114+# Read in the transaction.log.
115+
116+--exec ../drizzled/message/transaction_reader var/master-data/transaction.log
117+
118+DROP TABLE t;
119+
120+# Truncate the log file to reset for the next test
121+--source ../plugin/transaction_log/tests/t/truncate_log.inc