]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added support for reflecting the INTERVAL YEAR TO MONTH
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 1 Nov 2009 22:43:45 +0000 (22:43 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 1 Nov 2009 22:43:45 +0000 (22:43 +0000)
and INTERVAL DAY TO SECOND syntaxes of the INTERVAL
type.  [ticket:460]

CHANGES
lib/sqlalchemy/databases/postgres.py
lib/sqlalchemy/test/testing.py
test/dialect/test_postgres.py

diff --git a/CHANGES b/CHANGES
index 55ffae23ac8c38177c890c59a9729af58b818fd8..9e79d063b909fdfa4baa16f1a1683a1edfe493bc 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -47,6 +47,10 @@ CHANGES
       This is postgresql.DOUBLE_PRECISION in 0.6.
       [ticket:1085]
     
+    - Added support for reflecting the INTERVAL YEAR TO MONTH
+      and INTERVAL DAY TO SECOND syntaxes of the INTERVAL 
+      type.  [ticket:460]
+      
     - Corrected the "has_sequence" query to take current schema,
       or explicit sequence-stated schema, into account.
       [ticket:1576]
index be9148835d360ad4d71968f4da6214ca89b54c8e..f380bcb28ff68879972eaf4d3ee9d38179bcdda3 100644 (file)
@@ -310,6 +310,8 @@ ischema_names = {
     'bytea' : PGBinary,
     'boolean' : PGBoolean,
     'interval':PGInterval,
+    'interval year to month':PGInterval,
+    'interval day to second':PGInterval,
 }
 
 # TODO: filter out 'FOR UPDATE' statements
@@ -543,10 +545,10 @@ class PGDialect(default.DefaultDialect):
                 else:
                     numericprec, numericscale = charlen.split(',')
                 charlen = False
-            if attype == 'double precision':
+            elif attype == 'double precision':
                 numericprec, numericscale = (True, False)
                 charlen = False
-            if attype == 'integer':
+            elif attype == 'integer':
                 numericprec, numericscale = (32, 0)
                 charlen = False
 
index cfa892f54959d64d3dec0efab91c1e86f62cfcb4..1211e6e9ce8ac269b06af71257b7073d194c264a 100644 (file)
@@ -574,7 +574,8 @@ class ComparesTables(object):
             eq_(c.primary_key, reflected_c.primary_key)
             eq_(c.nullable, reflected_c.nullable)
             if strict_types:
-                assert type(reflected_c.type) is type(c.type), "Type '%s' doesn't correspond to type '%s'" % (reflected_c.type, c.type)
+                assert type(reflected_c.type) is type(c.type), \
+                    "Type '%s' doesn't correspond to type '%s'" % (reflected_c.type, c.type)
             else:
                 assert len(
                     set(type(reflected_c.type).__mro__).difference(base_mro).intersection(
index 340132192d18039308fcfc1f1746839511ab5fc2..fb915665a79fce29f551f0b9f266d4f12daaa8fc 100644 (file)
@@ -934,6 +934,16 @@ class SpecialTypesTest(TestBase, ComparesTables):
     def setup_class(cls):
         global metadata, table
         metadata = MetaData(testing.db)
+
+        # create these types so that we can issue
+        # special SQL92 INTERVAL syntax
+        class y2m(postgres.PGInterval):
+            def get_col_spec(self):
+                return "INTERVAL YEAR TO MONTH"
+
+        class d2s(postgres.PGInterval):
+            def get_col_spec(self):
+                return "INTERVAL DAY TO SECOND"
         
         table = Table('sometable', metadata,
             Column('id', postgres.PGUuid, primary_key=True),
@@ -941,10 +951,18 @@ class SpecialTypesTest(TestBase, ComparesTables):
             Column('addr', postgres.PGInet),
             Column('addr2', postgres.PGMacAddr),
             Column('addr3', postgres.PGCidr),
-            Column('doubleprec', postgres.PGDoublePrecision)
+            Column('doubleprec', postgres.PGDoublePrecision),
+            Column('plain_interval', postgres.PGInterval),
+            Column('year_interval', y2m()),
+            Column('month_interval', d2s()),
         )
         
         metadata.create_all()
+
+        # cheat so that the "strict type check"
+        # works
+        table.c.year_interval.type = postgres.PGInterval()
+        table.c.month_interval.type = postgres.PGInterval()
     
     @classmethod
     def teardown_class(cls):
@@ -955,7 +973,6 @@ class SpecialTypesTest(TestBase, ComparesTables):
         t = Table('sometable', m, autoload=True)
         
         self.assert_tables_equal(table, t, strict_types=True)
-        
 
 class MatchTest(TestBase, AssertsCompiledSQL):
     __only_on__ = 'postgres'