]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added support for reflecting the DOUBLE PRECISION type,
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Sep 2009 20:57:40 +0000 (20:57 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Sep 2009 20:57:40 +0000 (20:57 +0000)
via a new postgres.PGDoublePrecision object.
This is postgresql.DOUBLE_PRECISION in 0.6.
[ticket:1085]

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

diff --git a/CHANGES b/CHANGES
index e5bb8cd7b9c4007f5ebbe6437fbacc0b226576c9..9559f6a4ad9ce050b53c1588f2da5034589ec449 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -15,6 +15,12 @@ CHANGES
       subclass table to the query separately producing a 
       cartesian product.  An example is in the ticket
       description.  [ticket:1543]
+
+- postgresql
+    - Added support for reflecting the DOUBLE PRECISION type,
+      via a new postgres.PGDoublePrecision object.  
+      This is postgresql.DOUBLE_PRECISION in 0.6.
+      [ticket:1085]
       
 0.5.6
 =====
index 154d971e359eb2c3891f49780acc50ccb61f110d..03d0377a0ee410c5aad5338205a333c6b8d68860 100644 (file)
@@ -200,6 +200,10 @@ class PGBit(sqltypes.TypeEngine):
 class PGUuid(sqltypes.TypeEngine):
     def get_col_spec(self):
         return "UUID"
+
+class PGDoublePrecision(sqltypes.Float):
+    def get_col_spec(self):
+        return "DOUBLE PRECISION"
     
 class PGArray(sqltypes.MutableType, sqltypes.Concatenable, sqltypes.TypeEngine):
     def __init__(self, item_type, mutable=True):
@@ -267,6 +271,7 @@ colspecs = {
     sqltypes.Smallinteger : PGSmallInteger,
     sqltypes.Numeric : PGNumeric,
     sqltypes.Float : PGFloat,
+    PGDoublePrecision : PGDoublePrecision,
     sqltypes.DateTime : PGDateTime,
     sqltypes.Date : PGDate,
     sqltypes.Time : PGTime,
@@ -294,7 +299,7 @@ ischema_names = {
     'uuid':PGUuid,
     'bit':PGBit,
     'macaddr': PGMacAddr,
-    'double precision' : PGFloat,
+    'double precision' : PGDoublePrecision,
     'timestamp' : PGDateTime,
     'timestamp with time zone' : PGDateTime,
     'timestamp without time zone' : PGDateTime,
@@ -518,7 +523,7 @@ class PGDialect(default.DefaultDialect):
                     numericprec, numericscale = charlen.split(',')
                 charlen = False
             if attype == 'double precision':
-                numericprec, numericscale = (53, False)
+                numericprec, numericscale = (True, False)
                 charlen = False
             if attype == 'integer':
                 numericprec, numericscale = (32, 0)
index a4a9451a8f7c24157d803e21812aef041fe4ccba..cfa892f54959d64d3dec0efab91c1e86f62cfcb4 100644 (file)
@@ -565,7 +565,7 @@ class AssertsCompiledSQL(object):
             eq_(c.construct_params(params), checkparams)
 
 class ComparesTables(object):
-    def assert_tables_equal(self, table, reflected_table):
+    def assert_tables_equal(self, table, reflected_table, strict_types=False):
         base_mro = sqltypes.TypeEngine.__mro__
         assert len(table.c) == len(reflected_table.c)
         for c, reflected_c in zip(table.c, reflected_table.c):
@@ -573,11 +573,14 @@ class ComparesTables(object):
             assert reflected_c is reflected_table.c[c.name]
             eq_(c.primary_key, reflected_c.primary_key)
             eq_(c.nullable, reflected_c.nullable)
-            assert len(
-                set(type(reflected_c.type).__mro__).difference(base_mro).intersection(
-                set(type(c.type).__mro__).difference(base_mro)
-                )
-            ) > 0, "Type '%s' doesn't correspond to type '%s'" % (reflected_c.type, c.type)
+            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)
+            else:
+                assert len(
+                    set(type(reflected_c.type).__mro__).difference(base_mro).intersection(
+                    set(type(c.type).__mro__).difference(base_mro)
+                    )
+                ) > 0, "Type '%s' doesn't correspond to type '%s'" % (reflected_c.type, c.type)
 
             if isinstance(c.type, sqltypes.String):
                 eq_(c.type.length, reflected_c.type.length)
index 8ca714badc79033c9441c59562a87a369f46a271..340132192d18039308fcfc1f1746839511ab5fc2 100644 (file)
@@ -940,7 +940,8 @@ class SpecialTypesTest(TestBase, ComparesTables):
             Column('flag', postgres.PGBit),
             Column('addr', postgres.PGInet),
             Column('addr2', postgres.PGMacAddr),
-            Column('addr3', postgres.PGCidr)
+            Column('addr3', postgres.PGCidr),
+            Column('doubleprec', postgres.PGDoublePrecision)
         )
         
         metadata.create_all()
@@ -953,7 +954,7 @@ class SpecialTypesTest(TestBase, ComparesTables):
         m = MetaData(testing.db)
         t = Table('sometable', m, autoload=True)
         
-        self.assert_tables_equal(table, t)
+        self.assert_tables_equal(table, t, strict_types=True)
         
 
 class MatchTest(TestBase, AssertsCompiledSQL):