]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- SQLite dialect no longer strips quotes
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 28 Jul 2011 15:53:18 +0000 (11:53 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 28 Jul 2011 15:53:18 +0000 (11:53 -0400)
    off of reflected default value, allowing
    a round trip CREATE TABLE to work.
    This is consistent with other dialects
    that also maintain the exact form of
    the default.  [ticket:2189]

CHANGES
lib/sqlalchemy/dialects/sqlite/base.py
test/dialect/test_sqlite.py

diff --git a/CHANGES b/CHANGES
index 7fa9ffd779b581e7b371ea2c195e970e3404a7f7..2c123a9d235f31a2cfbc54a91ae3c9b41c870d29 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -168,6 +168,14 @@ CHANGES
     "retryable" condition.  Only Oracle ORA-01033
     implemented for now.  [ticket:2201]
 
+- sqlite
+  - SQLite dialect no longer strips quotes
+    off of reflected default value, allowing
+    a round trip CREATE TABLE to work.  
+    This is consistent with other dialects
+    that also maintain the exact form of
+    the default.  [ticket:2189]
+
 - postgresql
   - Added new "postgresql_ops" argument to 
     Index, allows specification of PostgreSQL
index 331ab92d0af09e90a6bb8226312bd60041c7d9b6..577b9a3a026c796130243087dc776745ea576606 100644 (file)
@@ -630,17 +630,19 @@ class SQLiteDialect(default.DefaultDialect):
         else:
             pragma = "PRAGMA "
         qtable = quote(table_name)
-        c = _pragma_cursor(connection.execute("%stable_info(%s)" % (pragma, qtable)))
+        c = _pragma_cursor(
+                    connection.execute("%stable_info(%s)" % 
+                    (pragma, qtable)))
         found_table = False
         columns = []
         while True:
             row = c.fetchone()
             if row is None:
                 break
-            (name, type_, nullable, default, has_default, primary_key) = (row[1], row[2].upper(), not row[3], row[4], row[4] is not None, row[5])
+            (name, type_, nullable, default, has_default, primary_key) = \
+                (row[1], row[2].upper(), not row[3], 
+                row[4], row[4] is not None, row[5])
             name = re.sub(r'^\"|\"$', '', name)
-            if default:
-                default = re.sub(r"^\'|\'$", '', default)
             match = re.match(r'(\w+)(\(.*?\))?', type_)
             if match:
                 coltype = match.group(1)
index 400edc2cee4f73e5553702e88886b663918ffb78..f3422cf0e1d699101246e7f2432908ed712c7bed 100644 (file)
@@ -10,6 +10,7 @@ from sqlalchemy.dialects.sqlite import base as sqlite, \
 from sqlalchemy.engine.url import make_url
 from test.lib import *
 import os
+from sqlalchemy.schema import CreateTable
 
 class TestTypes(fixtures.TestBase, AssertsExecutionResults):
 
@@ -168,7 +169,7 @@ class TestTypes(fixtures.TestBase, AssertsExecutionResults):
         assert isinstance(t2.c.y.type, sqltypes.NullType)
 
 
-class TestDefaults(fixtures.TestBase, AssertsExecutionResults):
+class DefaultsTest(fixtures.TestBase, AssertsCompiledSQL):
 
     __only_on__ = 'sqlite'
 
@@ -206,7 +207,7 @@ class TestDefaults(fixtures.TestBase, AssertsExecutionResults):
 
         db = testing.db
         m = MetaData(db)
-        expected = ['my_default', '0']
+        expected = ["'my_default'", '0']
         table = \
             """CREATE TABLE r_defaults (
             data VARCHAR(40) DEFAULT 'my_default',
@@ -220,6 +221,30 @@ class TestDefaults(fixtures.TestBase, AssertsExecutionResults):
         finally:
             db.execute('DROP TABLE r_defaults')
 
+    def test_default_reflection_3(self):
+        db = testing.db
+        table = \
+            """CREATE TABLE r_defaults (
+            data VARCHAR(40) DEFAULT 'my_default',
+            val INTEGER NOT NULL DEFAULT 0
+            )"""
+        try:
+            db.execute(table)
+            m1 = MetaData(db)
+            t1 = Table('r_defaults', m1, autoload=True)
+            db.execute("DROP TABLE r_defaults")
+            t1.create()
+            m2 = MetaData(db)
+            t2 = Table('r_defaults', m2, autoload=True)
+            self.assert_compile(
+                CreateTable(t2), 
+                "CREATE TABLE r_defaults (data VARCHAR(40) "
+                "DEFAULT 'my_default', val INTEGER DEFAULT 0 "
+                "NOT NULL)"
+            )
+        finally:
+            db.execute("DROP TABLE r_defaults")
+
 
 class DialectTest(fixtures.TestBase, AssertsExecutionResults):