]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
more fixes to bound parameter exception reporting rel_0_5_4p2
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 26 May 2009 17:03:03 +0000 (17:03 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 26 May 2009 17:03:03 +0000 (17:03 +0000)
CHANGES
lib/sqlalchemy/exc.py
test/base/except.py

diff --git a/CHANGES b/CHANGES
index 314794b58771cd9081a5af1c81ecdad643e5af16..cced2b719cdd040b0fd4eecf6b6c3ddaff3e620f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -9,7 +9,7 @@ CHANGES
 
 - sql
     - Repaired the printing of SQL exceptions which are not 
-      based on parameters.
+      based on parameters or are not executemany() style.
       
 - postgres
     - Deprecated the hardcoded TIMESTAMP function, which when
index e0310d03c1c6a24f98c24d66b928f9440e76d0a6..ce130ce3c2af9752c0c8146d0919aed89127f052 100644 (file)
@@ -132,11 +132,11 @@ class DBAPIError(SQLAlchemyError):
         self.connection_invalidated = connection_invalidated
 
     def __str__(self):
-        if self.params and len(self.params) > 10:
+        if isinstance(self.params, (list, tuple)) and len(self.params) > 10 and isinstance(self.params[0], (list, dict, tuple)):
             return ' '.join((SQLAlchemyError.__str__(self),
                              repr(self.statement),
                              repr(self.params[:2]),
-                             '... and a total of %i bound parameters' % len(self.params)))
+                             '... and a total of %i bound parameter sets' % len(self.params)))
         return ' '.join((SQLAlchemyError.__str__(self),
                          repr(self.statement), repr(self.params)))
 
index c2b60f32a7bab67e83668072c9d6e67dc7b53d64..3f4d654771e7ef96ae47b304747cc73f9b14222c 100644 (file)
@@ -32,6 +32,45 @@ class WrapTest(unittest.TestCase):
                 'this is a message', None, OperationalError())
         except sa_exceptions.DBAPIError, exc:
             assert str(exc) == "(OperationalError)  'this is a message' None"
+
+    def test_tostring_large_dict(self):
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', {'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 'f':6, 'g':7, 'h':8, 'i':9, 'j':10, 'k':11}, OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc).startswith("(OperationalError)  'this is a message' {")
+
+    def test_tostring_large_list(self):
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc).startswith("(OperationalError)  'this is a message' [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]")
+
+    def test_tostring_large_executemany(self):
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', [{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},], OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc) == "(OperationalError)  'this is a message' [{1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}, {1: 1}]", str(exc)
+
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', [{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},], OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc) == "(OperationalError)  'this is a message' [{1: 1}, {1: 1}] ... and a total of 11 bound parameter sets"
+
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', [(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)], OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc) == "(OperationalError)  'this is a message' [(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)]"
+
+        try:
+            raise sa_exceptions.DBAPIError.instance(
+                'this is a message', [(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), ], OperationalError())
+        except sa_exceptions.DBAPIError, exc:
+            assert str(exc) == "(OperationalError)  'this is a message' [(1,), (1,)] ... and a total of 11 bound parameter sets"
         
     def test_db_error_busted_dbapi(self):
         try: