]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- added unit test for exception formatting
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 26 May 2009 01:00:46 +0000 (01:00 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 26 May 2009 01:00:46 +0000 (01:00 +0000)
- Deprecated the hardcoded TIMESTAMP function, which when
used as func.TIMESTAMP(value) would render "TIMESTAMP value".
This breaks on some platforms as Postgres doesn't allow
bind parameters to be used in this context.  The hard-coded
uppercase is also inappropriate and there's lots of other
PG casts that we'd need to support.  So instead, use
text constructs i.e. select(["timestamp '12/05/09'"]).

CHANGES
lib/sqlalchemy/databases/postgres.py
test/base/except.py
test/dialect/postgres.py

diff --git a/CHANGES b/CHANGES
index a2ba1c57209a45d970971ea2c7ae8838da8a29ce..314794b58771cd9081a5af1c81ecdad643e5af16 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -10,7 +10,17 @@ CHANGES
 - sql
     - Repaired the printing of SQL exceptions which are not 
       based on parameters.
-
+      
+- postgres
+    - Deprecated the hardcoded TIMESTAMP function, which when
+      used as func.TIMESTAMP(value) would render "TIMESTAMP value".
+      This breaks on some platforms as Postgres doesn't allow
+      bind parameters to be used in this context.  The hard-coded
+      uppercase is also inappropriate and there's lots of other
+      PG casts that we'd need to support.  So instead, use
+      text constructs i.e. select(["timestamp '12/05/09'"]).
+      
+      
 0.5.4p1
 =======
 
index 068afaf3dd2b786bf35cdae76502a0735516472e..4fc79921bae28bdfc095d72300f3eed945bcc391 100644 (file)
@@ -706,7 +706,6 @@ class PGDialect(default.DefaultDialect):
         return domains
 
 
-
 class PGCompiler(compiler.DefaultCompiler):
     operators = compiler.DefaultCompiler.operators.copy()
     operators.update(
@@ -721,7 +720,7 @@ class PGCompiler(compiler.DefaultCompiler):
     functions = compiler.DefaultCompiler.functions.copy()
     functions.update (
         {
-            'TIMESTAMP':lambda x:'TIMESTAMP %s' % x,
+            'TIMESTAMP':util.deprecated(message="Use a literal string 'timestamp <value>' instead")(lambda x:'TIMESTAMP %s' % x),
         }
     )
 
index 457137c4ce8d9c34a724c54917b4620f490162d1..c2b60f32a7bab67e83668072c9d6e67dc7b53d64 100644 (file)
@@ -25,7 +25,14 @@ class WrapTest(unittest.TestCase):
                 '', [], OperationalError())
         except sa_exceptions.DBAPIError:
             self.assert_(True)
-
+    
+    def test_tostring(self):
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', None, OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc) == "(OperationalError)  'this is a message' None"
+        
     def test_db_error_busted_dbapi(self):
         try:
             raise sa_exceptions.DBAPIError.instance(
index d613ad2ddf0e522396e1b88976ffc30d6fad89b8..2dfbe018ccf99af0e1dbf97cfab92d0e911b03a4 100644 (file)
@@ -865,6 +865,8 @@ class ArrayTest(TestBase, AssertsExecutionResults):
 
 class TimeStampTest(TestBase, AssertsExecutionResults):
     __only_on__ = 'postgres'
+    
+    @testing.uses_deprecated()
     def test_timestamp(self):
         engine = testing.db
         connection = engine.connect()