Skip to content

Commit 7246364

Browse files
committed
Bug#35208605: Mysqldump table with virtual column wrong syntax
The fact that some columns aren't printed in the INSERT statements generated by mysqldump wasn't taken into account when deciding on printing the commas for the INSERT VALUES list. Fixed by having a special flag if a column is already printed or not instead of deciding based on column index. Test cases added to cover all kinds of virtual columns. Change-Id: I55484c3a795a4ad18b24c0691b2def9a04306e7a
1 parent 4c72f60 commit 7246364

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

client/mysqldump.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,6 +3902,7 @@ static void dump_table(char *table, char *db) {
39023902
while ((row = mysql_fetch_row(res))) {
39033903
uint i;
39043904
ulong *lengths = mysql_fetch_lengths(res);
3905+
bool first_column = true;
39053906
rownr++;
39063907
if (!extended_insert && !opt_xml) {
39073908
fputs(insert_pat.str, md_result_file);
@@ -3940,9 +3941,10 @@ static void dump_table(char *table, char *db) {
39403941
? 1
39413942
: 0;
39423943
if (extended_insert && !opt_xml) {
3943-
if (i == 0)
3944+
if (first_column) {
39443945
dynstr_set_checked(&extended_row, "(");
3945-
else
3946+
first_column = false;
3947+
} else
39463948
dynstr_append_checked(&extended_row, ",");
39473949

39483950
if (row[i]) {

mysql-test/r/mysqldump_bugs.result

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,31 @@ CREATE TABLE `wl13292` (
202202
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
203203
/*!40101 SET character_set_client = @saved_cs_client */;
204204
DROP TABLE wl13292;
205+
#
206+
# Bug#35208605: Mysqldump table with virtual column wrong syntax
207+
#
208+
CREATE DATABASE b35208605;
209+
USE b35208605;
210+
CREATE TABLE x1 (c0 BLOB AS ('a') VIRTUAL, c1 INT);
211+
INSERT INTO x1(c1) VALUES (1);
212+
CREATE TABLE x2 (c1 INT, c0 BLOB AS ('a') VIRTUAL);
213+
INSERT INTO x2(c1) VALUES (1);
214+
CREATE TABLE x3 (c0 BLOB AS ('a') VIRTUAL INVISIBLE, c1 INT);
215+
INSERT INTO x3(c1) VALUES (1);
216+
CREATE TABLE x4 (c1 INT, c0 BLOB AS ('a') VIRTUAL INVISIBLE);
217+
INSERT INTO x4(c1) VALUES (1);
218+
CREATE TABLE x5 (c0 BLOB AS ('a') STORED, c1 INT);
219+
INSERT INTO x5(c1) VALUES (1);
220+
CREATE TABLE x6 (c1 INT, c0 BLOB AS ('a') STORED);
221+
INSERT INTO x6(c1) VALUES (1);
222+
CREATE TABLE x7 (c0 BLOB AS ('a') STORED INVISIBLE, c1 INT);
223+
INSERT INTO x7(c1) VALUES (1);
224+
CREATE TABLE x8 (c1 INT, c0 BLOB AS ('a') STORED INVISIBLE);
225+
INSERT INTO x8(c1) VALUES (1);
226+
# Test: all INSERTs must be valid SQL
227+
DROP TABLE x1,x2,x3,x4,x5,x6,x7,x8;
228+
# Test: Must apply OK
229+
DROP TABLE x1,x2,x3,x4,x5,x6,x7,x8;
230+
USE test;
231+
DROP DATABASE b35208605;
205232
# End of 8.0 tests

mysql-test/t/mysqldump_bugs.test

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,40 @@ CREATE TABLE wl13292(a INT PRIMARY KEY);
133133

134134
DROP TABLE wl13292;
135135

136+
--echo #
137+
--echo # Bug#35208605: Mysqldump table with virtual column wrong syntax
138+
--echo #
139+
140+
CREATE DATABASE b35208605;
141+
USE b35208605;
142+
CREATE TABLE x1 (c0 BLOB AS ('a') VIRTUAL, c1 INT);
143+
INSERT INTO x1(c1) VALUES (1);
144+
CREATE TABLE x2 (c1 INT, c0 BLOB AS ('a') VIRTUAL);
145+
INSERT INTO x2(c1) VALUES (1);
146+
CREATE TABLE x3 (c0 BLOB AS ('a') VIRTUAL INVISIBLE, c1 INT);
147+
INSERT INTO x3(c1) VALUES (1);
148+
CREATE TABLE x4 (c1 INT, c0 BLOB AS ('a') VIRTUAL INVISIBLE);
149+
INSERT INTO x4(c1) VALUES (1);
150+
CREATE TABLE x5 (c0 BLOB AS ('a') STORED, c1 INT);
151+
INSERT INTO x5(c1) VALUES (1);
152+
CREATE TABLE x6 (c1 INT, c0 BLOB AS ('a') STORED);
153+
INSERT INTO x6(c1) VALUES (1);
154+
CREATE TABLE x7 (c0 BLOB AS ('a') STORED INVISIBLE, c1 INT);
155+
INSERT INTO x7(c1) VALUES (1);
156+
CREATE TABLE x8 (c1 INT, c0 BLOB AS ('a') STORED INVISIBLE);
157+
INSERT INTO x8(c1) VALUES (1);
158+
159+
--echo # Test: all INSERTs must be valid SQL
160+
--exec $MYSQL_DUMP --skip-comments --compact --result-file=$MYSQLTEST_VARDIR/tmp/b35208605.sql b35208605 2>&1
161+
DROP TABLE x1,x2,x3,x4,x5,x6,x7,x8;
162+
--echo # Test: Must apply OK
163+
--exec $MYSQL b35208605 < $MYSQLTEST_VARDIR/tmp/b35208605.sql 2>&1
164+
165+
DROP TABLE x1,x2,x3,x4,x5,x6,x7,x8;
166+
USE test;
167+
DROP DATABASE b35208605;
168+
remove_file $MYSQLTEST_VARDIR/tmp/b35208605.sql;
169+
136170

137171
--echo # End of 8.0 tests
138172

0 commit comments

Comments
 (0)