From: Lele Gaifax Date: Fri, 7 Aug 2009 12:16:15 +0000 (+0000) Subject: Fix #1429: take into account possible spurious spaces around the DEFAULT keyword X-Git-Tag: rel_0_6beta1~356 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8aa2886c1a31c9a9950ad00345ac0cadcf78f7e2;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix #1429: take into account possible spurious spaces around the DEFAULT keyword --- diff --git a/lib/sqlalchemy/dialects/firebird/base.py b/lib/sqlalchemy/dialects/firebird/base.py index e9d0c0319e..020977ff5f 100644 --- a/lib/sqlalchemy/dialects/firebird/base.py +++ b/lib/sqlalchemy/dialects/firebird/base.py @@ -523,9 +523,14 @@ class FBDialect(default.DefaultDialect): # does it have a default value? defvalue = None if row['fdefault'] is not None: - # the value comes down as "DEFAULT 'value'" - assert row['fdefault'].upper().startswith('DEFAULT '), row - defvalue = row['fdefault'][8:] + # the value comes down as "DEFAULT 'value'": there may be + # more than one space around the "DEFAULT" keyword + defexpr = row['fdefault'].lstrip() + assert defexpr.startswith('DEFAULT '), "Unrecognized default value: %s" % defexpr + defvalue = defexpr[8:].strip() + if defvalue == 'NULL': + # Redundant + defvalue = None col_d = { 'name' : name, 'type' : coltype, diff --git a/test/dialect/test_firebird.py b/test/dialect/test_firebird.py index 2dc6af91b7..2c427fd2e0 100644 --- a/test/dialect/test_firebird.py +++ b/test/dialect/test_firebird.py @@ -29,7 +29,8 @@ class DomainReflectionTest(TestBase, AssertsExecutionResults): photo img_domain, d date, t time, - dt timestamp)''') + dt timestamp, + redundant str_domain DEFAULT NULL)''') con.execute('''ALTER TABLE testtable ADD CONSTRAINT testtable_pk PRIMARY KEY (question)''') con.execute('''CREATE TRIGGER testtable_autoid FOR testtable @@ -54,8 +55,9 @@ class DomainReflectionTest(TestBase, AssertsExecutionResults): metadata = MetaData(testing.db) table = Table('testtable', metadata, autoload=True) eq_(set(table.columns.keys()), - set(['question', 'answer', 'remark', 'photo', 'd', 't', 'dt']), - "Columns of reflected table didn't equal expected columns") + set(['question', 'answer', 'remark', + 'photo', 'd', 't', 'dt', 'redundant']), + "Columns of reflected table didn't equal expected columns") eq_(table.c.question.primary_key, True) eq_(table.c.question.sequence.name, 'gen_testtable_id') assert isinstance(table.c.question.type, Integer) @@ -65,6 +67,7 @@ class DomainReflectionTest(TestBase, AssertsExecutionResults): assert isinstance(table.c.remark.type, Text) eq_(table.c.remark.server_default.arg.text, "''") assert isinstance(table.c.photo.type, Binary) + assert table.c.redundant.server_default is None # The following assume a Dialect 3 database assert isinstance(table.c.d.type, Date) assert isinstance(table.c.t.type, Time) @@ -170,4 +173,3 @@ class MiscTest(TestBase): (text("select 'hello % world' from rdb$database"), "hello % world") ): eq_(testing.db.scalar(expr), result) -