From b1c3c2463fcedbe842da92d3b6432d6bc1a4e37c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 30 Sep 2009 20:57:40 +0000 Subject: [PATCH] - Added support for reflecting the DOUBLE PRECISION type, via a new postgres.PGDoublePrecision object. This is postgresql.DOUBLE_PRECISION in 0.6. [ticket:1085] --- CHANGES | 6 ++++++ lib/sqlalchemy/databases/postgres.py | 9 +++++++-- lib/sqlalchemy/test/testing.py | 15 +++++++++------ test/dialect/test_postgres.py | 5 +++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/CHANGES b/CHANGES index e5bb8cd7b9..9559f6a4ad 100644 --- 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 ===== diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 154d971e35..03d0377a0e 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -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) diff --git a/lib/sqlalchemy/test/testing.py b/lib/sqlalchemy/test/testing.py index a4a9451a8f..cfa892f549 100644 --- a/lib/sqlalchemy/test/testing.py +++ b/lib/sqlalchemy/test/testing.py @@ -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) diff --git a/test/dialect/test_postgres.py b/test/dialect/test_postgres.py index 8ca714badc..340132192d 100644 --- a/test/dialect/test_postgres.py +++ b/test/dialect/test_postgres.py @@ -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): -- 2.47.3