]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added support for rendering and reflecting
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Mar 2010 22:10:53 +0000 (18:10 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Mar 2010 22:10:53 +0000 (18:10 -0400)
TIMESTAMP WITH TIME ZONE, i.e. TIMESTAMP(timezone=True).
[ticket:651]

- Oracle INTERVAL type can now be reflected.

CHANGES
lib/sqlalchemy/dialects/oracle/base.py
test/dialect/test_oracle.py

diff --git a/CHANGES b/CHANGES
index 36be2bc4684e38cc5bd95bbfde6e4ced32d5ee95..0d874278d6c318f4aa24d84a48bf9e56ab5d2dc3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -401,6 +401,12 @@ CHANGES
      which is more or less equivalent on that platform.
      [ticket:1712]
    
+   - Added support for rendering and reflecting 
+     TIMESTAMP WITH TIME ZONE, i.e. TIMESTAMP(timezone=True).
+     [ticket:651]
+     
+   - Oracle INTERVAL type can now be reflected.
+     
 - sqlite
    - Added "native_datetime=True" flag to create_engine().
      This will cause the DATE and TIMESTAMP types to skip 
index b270f38cf4e9de58a03965346728b86d962337eb..2af5bdd7d0c9e60f14bd8e0af8b75378681ae93f 100644 (file)
@@ -225,6 +225,8 @@ ischema_names = {
     'CLOB' : CLOB,
     'NCLOB' : NCLOB,
     'TIMESTAMP' : TIMESTAMP,
+    'TIMESTAMP WITH TIME ZONE' : TIMESTAMP,
+    'INTERVAL DAY TO SECOND' : INTERVAL,
     'RAW' : RAW,
     'FLOAT' : FLOAT,
     'DOUBLE PRECISION' : DOUBLE_PRECISION,
@@ -256,7 +258,13 @@ class OracleTypeCompiler(compiler.GenericTypeCompiler):
                 "(%d)" % type_.second_precision or
                 "",
         )
-            
+
+    def visit_TIMESTAMP(self, type_):
+        if type_.timezone:
+            return "TIMESTAMP WITH TIME ZONE"
+        else:
+            return "TIMESTAMP"
+
     def visit_DOUBLE_PRECISION(self, type_):
         return self._generate_numeric(type_, "DOUBLE PRECISION")
         
@@ -756,6 +764,8 @@ class OracleDialect(default.DefaultDialect):
                 coltype = NUMBER(precision, scale)
             elif coltype=='CHAR' or coltype=='VARCHAR2':
                 coltype = self.ischema_names.get(coltype)(length)
+            elif 'WITH TIME ZONE' in coltype: 
+                coltype = TIMESTAMP(timezone=True)
             else:
                 coltype = re.sub(r'\(\d+\)', '', coltype)
                 try:
index f7f349250ba1d05e115e571cd2ff37a9cb3056c5..35cfd77b76c458d9403d841c7ce346daec2bf758 100644 (file)
@@ -591,7 +591,31 @@ class TypesTest(TestBase, AssertsCompiledSQL):
         finally:
             t1.drop()
     
-    
+    def test_reflect_dates(self):
+        metadata = MetaData(testing.db)
+        Table(
+            "date_types", metadata,
+            Column('d1', DATE),
+            Column('d2', TIMESTAMP),
+            Column('d3', TIMESTAMP(timezone=True)),
+            Column('d4', oracle.INTERVAL(second_precision=5)),
+        )
+        metadata.create_all()
+        try:
+            m = MetaData(testing.db)
+            t1 = Table(
+                "date_types", m,
+                autoload=True)
+            assert isinstance(t1.c.d1.type, DATE)
+            assert isinstance(t1.c.d2.type, TIMESTAMP)
+            assert not t1.c.d2.type.timezone
+            assert isinstance(t1.c.d3.type, TIMESTAMP)
+            assert t1.c.d3.type.timezone
+            assert isinstance(t1.c.d4.type, oracle.INTERVAL)
+            
+        finally:
+            metadata.drop_all()
+        
     def test_reflect_raw(self):
         types_table = Table(
         'all_types', MetaData(testing.db),