Skip to content

Commit 366ee07

Browse files
committed
BUG24946076: Fix table comment SQL generation
This patch fixes the table comment SQL generation. Quotes were not added around the comment which gave rise to this error. Modifed tests to check this.
1 parent 226eb1c commit 366ee07

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/mysqlx/statement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ def _get_table_opts(self):
955955
if self._collation:
956956
options.append("DEFAULT COLLATE = {collation}")
957957
if self._comment:
958-
options.append("COMMENT = {comment}")
958+
options.append("COMMENT = '{comment}'")
959959

960960
table_opts = ",".join(options)
961961
return table_opts.format(inc=self._auto_inc, charset=self._charset,

tests/test_mysqlx_crud.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ def test_create_table(self):
256256
language = self.schema.create_table(table_a) \
257257
.add_column(mysqlx.ColumnDef('language_id', mysqlx.ColumnType.INT) \
258258
.primary().auto_increment().unsigned().not_null()) \
259-
.set_initial_auto_increment(12).execute()
259+
.set_initial_auto_increment(12) \
260+
.set_comment("Table Comment test").execute()
260261

261262
self.assertTrue(language.exists_in_database())
262263
self.assertEqual(12,
@@ -265,6 +266,12 @@ def test_create_table(self):
265266
'FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = "{0}" AND '
266267
'TABLE_NAME = "{1}"'.format(self.schema.name, table_a)) \
267268
.execute().fetch_all()[0][0])
269+
self.assertEqual("Table Comment test",
270+
self.node_session.sql(
271+
'SELECT TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES '
272+
'WHERE TABLE_SCHEMA = "{0}" '
273+
'AND TABLE_NAME = "{1}"'.format(self.schema.name, table_a)) \
274+
.execute().fetch_all()[0][0])
268275

269276
# Create table with index and foreign keys
270277
film = self.schema.create_table(table_b) \

0 commit comments

Comments
 (0)