Percent sign formatting of ddl strings breaks for modulo operations on columns that start with f, d, etc.
Issue #3098
closed
The following code does not compile because there is a % f in it (from the modulo operation on the table foo) and the visit_ddl function in compiler.py uses python's percent sign formatting syntax.
from sqlalchemy import Table, MetaData, Column, Integer, DDL
from sqlalchemy import create_engine, event
ECHO = False
engine = create_engine('sqlite:///memory', echo=ECHO)
ddl = DDL(
'''CREATE TRIGGER foo AFTER INSERT ON bar
BEGIN
INSERT INTO bar SELECT * FROM foo WHERE 2 % foo.id = 0;
END;
'''
)
md = MetaData()
Foo = Table('foo', md, Column('id', Integer))
Bar = Table('bar', md, Column('id', Integer))
event.listen(Foo, 'after_create', ddl.execute_if(dialect='sqlite'))
Foo.metadata.create_all(engine)
Comments (6)
-
reporter -
repo owner - changed status to closed
please escape percent signs as %% - see http://docs.sqlalchemy.org/en/rel_0_9/core/ddl.html?highlight=ddl#sqlalchemy.schema.DDL.params.statement. thanks!
-
reporter It'd be helpful if this error was caught before being raised and printed a message to the command line to the effect of "your DDL statement may have percent signs in it. If this is the case and they are not escaped, please escape them as %%" before it raised the error definitively.
-
repo owner percent signs are allowed because there are supported replacement tokens in the DDL string.
-
repo owner - changed milestone to 0.9.8
-
repo owner - changed milestone to 0.9.7
- Log in to comment
For now, my workaround is that I'm creating a function mod that I'm sending to the sqlite backend, so as soon as this is fixed, I'll replace the mod function with the % sign operator.