]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix #1429: take into account possible spurious spaces around the DEFAULT keyword
authorLele Gaifax <lele@metapensiero.it>
Fri, 7 Aug 2009 12:16:15 +0000 (12:16 +0000)
committerLele Gaifax <lele@metapensiero.it>
Fri, 7 Aug 2009 12:16:15 +0000 (12:16 +0000)
lib/sqlalchemy/dialects/firebird/base.py
test/dialect/test_firebird.py

index e9d0c0319e9016ca0993d92cc784d838ff601b75..020977ff5f2152824dd076fcae6f5b7487fb8a49 100644 (file)
@@ -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,
index 2dc6af91b76ae7c4c8246e63f6632b845a0fbcd1..2c427fd2e043a495764710a8b677b327f44be3be 100644 (file)
@@ -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)
-