connection.commit(True)
+def _substring(s, start, length=None):
+ "Helper function to handle Firebird 2 SUBSTRING builtin"
+
+ if length is None:
+ return "SUBSTRING(%s FROM %s)" % (s, start)
+ else:
+ return "SUBSTRING(%s FROM %s FOR %s)" % (s, start, length)
+
+
class FBCompiler(sql.compiler.DefaultCompiler):
"""Firebird specific idiosincrasies"""
else:
return self.process(alias.original, **kwargs)
+ functions = sql.compiler.DefaultCompiler.functions.copy()
+ functions['substring'] = _substring
+
def function_argspec(self, func):
if func.clauses:
return self.process(func.clause_expr)
t = Table('sometable', m, Column('col1', Integer), Column('col2', Integer))
self.assert_compile(select([func.max(t.c.col1)]), "SELECT max(sometable.col1) AS max_1 FROM sometable")
+ def test_substring(self):
+ self.assert_compile(func.substring('abc', 1, 2), "SUBSTRING(:substring_1 FROM :substring_2 FOR :substring_3)")
+ self.assert_compile(func.substring('abc', 1), "SUBSTRING(:substring_1 FROM :substring_2)")
class MiscFBTests(TestBase):