From: Mike Bayer Date: Sun, 1 Nov 2009 22:43:45 +0000 (+0000) Subject: - Added support for reflecting the INTERVAL YEAR TO MONTH X-Git-Tag: rel_0_5_7~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2a34d521a3d6cece1e6748e17fe8bf46c86b8f70;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Added support for reflecting the INTERVAL YEAR TO MONTH and INTERVAL DAY TO SECOND syntaxes of the INTERVAL type. [ticket:460] --- diff --git a/CHANGES b/CHANGES index 55ffae23ac..9e79d063b9 100644 --- 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] diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index be9148835d..f380bcb28f 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -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 diff --git a/lib/sqlalchemy/test/testing.py b/lib/sqlalchemy/test/testing.py index cfa892f549..1211e6e9ce 100644 --- a/lib/sqlalchemy/test/testing.py +++ b/lib/sqlalchemy/test/testing.py @@ -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( diff --git a/test/dialect/test_postgres.py b/test/dialect/test_postgres.py index 340132192d..fb915665a7 100644 --- a/test/dialect/test_postgres.py +++ b/test/dialect/test_postgres.py @@ -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'