1. diana clarke
  2. sqlalchemy-2450

Commits

Mike Bayer  committed 2c7cf22

- added unit test for exception formatting
- 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'"]).

  • Participants
  • Parent commits 6712f67
  • Branches default

Comments (0)

Files changed (4)

File CHANGES

View file
  • Ignore whitespace
 - 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
 =======
 

File lib/sqlalchemy/databases/postgres.py

View file
  • Ignore whitespace
         return domains
 
 
-
 class PGCompiler(compiler.DefaultCompiler):
     operators = compiler.DefaultCompiler.operators.copy()
     operators.update(
     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),
         }
     )
 

File test/base/except.py

View file
  • Ignore whitespace
                 '', [], 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(

File test/dialect/postgres.py

View file
  • Ignore whitespace
 
 class TimeStampTest(TestBase, AssertsExecutionResults):
     __only_on__ = 'postgres'
+    
+    @testing.uses_deprecated()
     def test_timestamp(self):
         engine = testing.db
         connection = engine.connect()