], nonpart_options):
arg = opts[opt]
if opt in _reflection._options_of_type_string:
- arg = "'%s'" % arg.replace("\\", "\\\\").replace("'", "''")
+
+ arg = self.sql_compiler.render_literal_value(
+ arg, sqltypes.String())
if opt in ('DATA_DIRECTORY', 'INDEX_DIRECTORY',
'DEFAULT_CHARACTER_SET', 'CHARACTER_SET',
], part_options):
arg = opts[opt]
if opt in _reflection._options_of_type_string:
- arg = "'%s'" % arg.replace("\\", "\\\\").replace("'", "''")
+ arg = self.sql_compiler.render_literal_value(
+ arg, sqltypes.String())
opt = opt.replace('_', ' ')
joiner = ' '
def literal_processor(self, dialect):
def process(value):
value = value.replace("'", "''")
+
+ if dialect.identifier_preparer._double_percents:
+ value = value.replace('%', '%%')
+
return "'%s'" % value
return process
)
Table('comment_test', metadata,
Column('id', sa.Integer, primary_key=True, comment='id comment'),
- Column('data', sa.String(20), comment='data comment'),
+ Column('data', sa.String(20), comment='data % comment'),
+ Column(
+ 'd2', sa.String(20),
+ comment=r"""Comment types type speedily ' " \ '' Fun!"""),
schema=schema,
- comment='the test table comment')
+ comment=r"""the test % ' " \ table comment""")
if testing.requires.index_reflection.enabled:
cls.define_index(metadata, users)
eq_(
insp.get_table_comment("comment_test", schema=schema),
- {"text": "the test table comment"}
+ {"text": r"""the test % ' " \ table comment"""}
)
eq_(
],
[
{'comment': 'id comment', 'name': 'id'},
- {'comment': 'data comment', 'name': 'data'}
+ {'comment': 'data % comment', 'name': 'data'},
+ {'comment': r"""Comment types type speedily ' " \ '' Fun!""",
+ 'name': 'd2'}
]
)
data = r'backslash one \ backslash two \\ end'
self._literal_round_trip(Text, [data], [data])
+ def test_literal_percentsigns(self):
+ data = r'percent % signs %% percent'
+ self._literal_round_trip(Text, [data], [data])
+
class StringTest(_LiteralRoundTripFixture, fixtures.TestBase):
__backend__ = True
'mysql_def', MetaData(testing.db),
Column('c1', Integer()),
mysql_engine='MEMORY',
- mysql_comment=comment,
+ comment=comment,
mysql_default_charset='utf8',
mysql_auto_increment='5',
mysql_avg_row_length='3',
def_table.drop()
assert def_table.kwargs['mysql_engine'] == 'MEMORY'
- assert def_table.kwargs['mysql_comment'] == comment
+ assert def_table.comment == comment
assert def_table.kwargs['mysql_default_charset'] == 'utf8'
assert def_table.kwargs['mysql_auto_increment'] == '5'
assert def_table.kwargs['mysql_avg_row_length'] == '3'
assert def_table.kwargs['mysql_connection'] == 'fish'
assert reflected.kwargs['mysql_engine'] == 'MEMORY'
+
+ assert reflected.comment == comment
assert reflected.kwargs['mysql_comment'] == comment
assert reflected.kwargs['mysql_default charset'] == 'utf8'
assert reflected.kwargs['mysql_avg_row_length'] == '3'
assert_raises_message, expect_warnings, assert_warnings
from sqlalchemy import text, select, Integer, String, Float, \
bindparam, and_, func, literal_column, exc, MetaData, Table, Column,\
- asc, func, desc, union
+ asc, func, desc, union, literal
from sqlalchemy.types import NullType
from sqlalchemy.sql import table, column, util as sql_util
from sqlalchemy import util
dialect="mysql"
)
+ def test_percent_signs_literal_binds(self):
+ stmt = select([literal("percent % signs %%")])
+ self.assert_compile(
+ stmt,
+ "SELECT 'percent % signs %%' AS anon_1",
+ dialect="sqlite",
+ literal_binds=True
+ )
+
+ self.assert_compile(
+ stmt,
+ "SELECT 'percent %% signs %%%%' AS anon_1",
+ dialect="mysql",
+ literal_binds=True
+ )
+
+
class AsFromTest(fixtures.TestBase, AssertsCompiledSQL):
__dialect__ = 'default'