summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-08-22 11:12:36 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-08-22 11:12:36 -0400
commitd3c1f245efb22b45c77561345346469cf6a82ddd (patch)
treed0a403d74c779e8a9f130f5a6b83ad67bd589189 /lib/sqlalchemy
parent647a28a03e21c70c2195c2a0ea6f6c3e21d72958 (diff)
downloadsqlalchemy-d3c1f245efb22b45c77561345346469cf6a82ddd.tar.gz
- Improvement to multi-param statement logging,
long lists of bound parameter sets will be compressed with an informative indicator of the compression taking place. Exception messages use the same improved formatting. [ticket:2243]
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/engine/base.py4
-rw-r--r--lib/sqlalchemy/exc.py12
-rw-r--r--lib/sqlalchemy/sql/util.py22
3 files changed, 28 insertions, 10 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index 3139904d2..e350b5bed 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -24,7 +24,7 @@ import inspect, StringIO, sys, operator
from itertools import izip
from sqlalchemy import exc, schema, util, types, log, interfaces, \
event, events
-from sqlalchemy.sql import expression
+from sqlalchemy.sql import expression, util as sql_util
from sqlalchemy import processors
import collections
@@ -1617,7 +1617,7 @@ class Connection(Connectable):
if self._echo:
self.engine.logger.info(statement)
- self.engine.logger.info("%r", parameters)
+ self.engine.logger.info("%r", sql_util._repr_params(parameters, batches=10))
try:
if context.executemany:
self.dialect.do_executemany(
diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py
index 951e44d61..0cc52fd25 100644
--- a/lib/sqlalchemy/exc.py
+++ b/lib/sqlalchemy/exc.py
@@ -146,15 +146,11 @@ class StatementError(SQLAlchemyError):
self.orig = orig
def __str__(self):
- 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 parameter sets' % len(self.params)))
+ from sqlalchemy.sql import util
+ params_repr = util._repr_params(self.params, 10)
return ' '.join((SQLAlchemyError.__str__(self),
- repr(self.statement), repr(self.params)))
+ repr(self.statement), repr(params_repr)))
+
class DBAPIError(StatementError):
"""Raised when the execution of a database operation fails.
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py
index fa65070aa..61a95d764 100644
--- a/lib/sqlalchemy/sql/util.py
+++ b/lib/sqlalchemy/sql/util.py
@@ -170,6 +170,28 @@ def _quote_ddl_expr(element):
else:
return repr(element)
+class _repr_params(object):
+ """A string view of bound parameters, truncating
+ display to the given number of 'multi' parameter sets.
+
+ """
+ def __init__(self, params, batches):
+ self.params = params
+ self.batches = batches
+
+ def __repr__(self):
+ if isinstance(self.params, (list, tuple)) and \
+ len(self.params) > self.batches and \
+ isinstance(self.params[0], (list, dict, tuple)):
+ return ' '.join((
+ repr(self.params[:self.batches - 2])[0:-1],
+ " ... displaying %i of %i total bound parameter sets ... " % (self.batches, len(self.params)),
+ repr(self.params[-2:])[1:]
+ ))
+ else:
+ return repr(self.params)
+
+
def expression_as_ddl(clause):
"""Given a SQL expression, convert for usage in DDL, such as
CREATE INDEX and CHECK CONSTRAINT.