]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Won't generate "CREATE TYPE" / "DROP TYPE" if
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 25 Jun 2010 17:11:06 +0000 (13:11 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 25 Jun 2010 17:11:06 +0000 (13:11 -0400)
using types.Enum on a PG version prior to 8.3 -
the supports_native_enum flag is fully
honored.  [ticket:1836]

CHANGES
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/test_postgresql.py

diff --git a/CHANGES b/CHANGES
index b138210a74a49ef0b642471f63eb518ad276a629..9c983e1c8898c202a0d8a5cae8970bfbd85acaa3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -89,7 +89,12 @@ CHANGES
     Ultimately this will have to detect the value of 
     "standard_conforming_strings" for full behavior.  
     [ticket:1400]
-  
+
+  - Won't generate "CREATE TYPE" / "DROP TYPE" if
+    using types.Enum on a PG version prior to 8.3 - 
+    the supports_native_enum flag is fully
+    honored.  [ticket:1836]
+    
 - mysql
   - MySQL dialect doesn't emit CAST() for MySQL version 
     detected < 4.0.2.  This allows the unicode
index 8275aa1e7d37a12111e9216d6cf638708ed62a1e..1a7f670a1e4e3d4008299a50a9b29a56dab93fc5 100644 (file)
@@ -260,10 +260,16 @@ PGArray = ARRAY
 class ENUM(sqltypes.Enum):
 
     def create(self, bind=None, checkfirst=True):
+        if not bind.dialect.supports_native_enum:
+            return
+            
         if not checkfirst or not bind.dialect.has_type(bind, self.name, schema=self.schema):
             bind.execute(CreateEnumType(self))
 
     def drop(self, bind=None, checkfirst=True):
+        if not bind.dialect.supports_native_enum:
+            return
+
         if not checkfirst or bind.dialect.has_type(bind, self.name, schema=self.schema):
             bind.execute(DropEnumType(self))
         
index 14814bc20f45e0ffab3ac2b756c684a874ffb7ec..d947ad4c44a02f12a76ed064a71a8f2eaedfdf9a 100644 (file)
@@ -349,6 +349,50 @@ class EnumTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL):
             
         finally:
             metadata.drop_all()
+    
+    def test_non_native_type(self):
+        metadata = MetaData()
+        t1 = Table('foo', metadata,
+            Column('bar', Enum('one', 'two', 'three', name='myenum', native_enum=False))
+        )
+        
+        def go():
+            t1.create(testing.db)
+        
+        try:
+            self.assert_sql(testing.db, go, [], with_sequences=[
+                (
+                    "CREATE TABLE foo (\tbar VARCHAR(5), \t"
+                    "CONSTRAINT myenum CHECK (bar IN ('one', 'two', 'three')))",
+                    {}
+                )]
+            )
+        finally:
+            metadata.drop_all(testing.db)
+        
+    def test_non_native_dialect(self):
+        engine = engines.testing_engine()
+        engine.connect()
+        engine.dialect.supports_native_enum = False
+        
+        metadata = MetaData()
+        t1 = Table('foo', metadata,
+            Column('bar', Enum('one', 'two', 'three', name='myenum'))
+        )
+        
+        def go():
+            t1.create(engine)
+        
+        try:
+            self.assert_sql(engine, go, [], with_sequences=[
+                (
+                    "CREATE TABLE foo (\tbar VARCHAR(5), \t"
+                    "CONSTRAINT myenum CHECK (bar IN ('one', 'two', 'three')))",
+                    {}
+                )]
+            )
+        finally:
+            metadata.drop_all(engine)
         
     def test_standalone_enum(self):
         metadata = MetaData(testing.db)