]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fixed numeric test for pg8000, factored out decimal/float codes
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 9 Apr 2010 17:01:17 +0000 (13:01 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 9 Apr 2010 17:01:17 +0000 (13:01 -0400)
lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/dialects/postgresql/pg8000.py
lib/sqlalchemy/dialects/postgresql/psycopg2.py
test/dialect/test_postgresql.py

index dcdaa3c7b16e7c4a6c03f9b70640b2f4afff7dca..312ae9aa8a35b0fe2786edea42a1479353e35054 100644 (file)
@@ -80,6 +80,10 @@ from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, VARCHAR, \
         CHAR, TEXT, FLOAT, NUMERIC, \
         DATE, BOOLEAN
 
+_DECIMAL_TYPES = (1700, 1231)
+_FLOAT_TYPES = (700, 701, 1021, 1022)
+
+
 class REAL(sqltypes.Float):
     __visit_name__ = "REAL"
 
index c822e37a5738bc392258495f4a52ebcd34767064..862c915aa21a781abe0bd15d61b414205d9ac751 100644 (file)
@@ -26,23 +26,24 @@ from sqlalchemy import util, exc
 from sqlalchemy import processors
 from sqlalchemy import types as sqltypes
 from sqlalchemy.dialects.postgresql.base import PGDialect, \
-                PGCompiler, PGIdentifierPreparer, PGExecutionContext
+                PGCompiler, PGIdentifierPreparer, PGExecutionContext,\
+                _DECIMAL_TYPES, _FLOAT_TYPES
 
 class _PGNumeric(sqltypes.Numeric):
     def result_processor(self, dialect, coltype):
         if self.asdecimal:
-            if coltype in (700, 701, 1021, 1022):
+            if coltype in _FLOAT_TYPES:
                 return processors.to_decimal_processor_factory(decimal.Decimal)
-            elif coltype in (1700, 1231):
+            elif coltype in _DECIMAL_TYPES:
                 # pg8000 returns Decimal natively for 1700
                 return None
             else:
                 raise exc.InvalidRequestError("Unknown PG numeric type: %d" % coltype)
         else:
-            if coltype in (700, 701, 1021, 1022):
+            if coltype in _FLOAT_TYPES:
                 # pg8000 returns float natively for 701
                 return None
-            elif coltype in (1700, 1231):
+            elif coltype in _DECIMAL_TYPES:
                 return processors.to_float
             else:
                 raise exc.InvalidRequestError("Unknown PG numeric type: %d" % coltype)
index 45d1bf29e5ddbe32eb6d105f04b9b45c1c1db9f7..2a51a72397267dd990129e9a5ea0c2f06478063a 100644 (file)
@@ -68,7 +68,7 @@ from sqlalchemy.sql import operators as sql_operators
 from sqlalchemy import types as sqltypes
 from sqlalchemy.dialects.postgresql.base import PGDialect, PGCompiler, \
                                             PGIdentifierPreparer, PGExecutionContext, \
-                                            ENUM, ARRAY
+                                            ENUM, ARRAY, _DECIMAL_TYPES, _FLOAT_TYPES
 
 
 logger = logging.getLogger('sqlalchemy.dialects.postgresql')
@@ -80,18 +80,18 @@ class _PGNumeric(sqltypes.Numeric):
 
     def result_processor(self, dialect, coltype):
         if self.asdecimal:
-            if coltype in (700, 701, 1021, 1022):
+            if coltype in _FLOAT_TYPES:
                 return processors.to_decimal_processor_factory(decimal.Decimal)
-            elif coltype in (1700, 1231):
+            elif coltype in _DECIMAL_TYPES:
                 # pg8000 returns Decimal natively for 1700
                 return None
             else:
                 raise exc.InvalidRequestError("Unknown PG numeric type: %d" % coltype)
         else:
-            if coltype in (700, 701, 1021, 1022):
+            if coltype in _FLOAT_TYPES:
                 # pg8000 returns float natively for 701
                 return None
-            elif coltype in (1700, 1231):
+            elif coltype in _DECIMAL_TYPES:
                 return processors.to_float
             else:
                 raise exc.InvalidRequestError("Unknown PG numeric type: %d" % coltype)
index bcf8ac95629c597b54583ae4eee7a6d490b073d8..14814bc20f45e0ffab3ac2b756c684a874ffb7ec 100644 (file)
@@ -1326,11 +1326,12 @@ class MiscTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL):
             exception_cls = eng.dialect.dbapi.ProgrammingError
         assert_raises(exception_cls, eng.execute, "show transaction isolation level")
     
-    @testing.only_on('postgresql+psycopg2', 
-                        "this assertion isn't used on others, "
-                        "except pg8000 which circumvents it")
+    @testing.fails_on('+zxjdbc', 
+                        "psycopg2/pg8000 specific assertion")
+    @testing.fails_on('pypostgresql', 
+                        "psycopg2/pg8000 specific assertion")
     def test_numeric_raise(self):
-        stmt = text("select 'hi' as hi", typemap={'hi':Numeric})
+        stmt = text("select cast('hi' as char) as hi", typemap={'hi':Numeric})
         assert_raises(
             exc.InvalidRequestError,
             testing.db.execute, stmt