summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-12-05 00:46:11 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-12-05 00:46:11 -0500
commit8e24584d8d242d40d605752116ac05be33f697d3 (patch)
tree3bd83f533b0743e4eef7f377e74a62d60adc4995 /lib/sqlalchemy/engine/base.py
parentaf75fdf60fd3498ab3c5757e81a5d6b5e52f590d (diff)
downloadsqlalchemy-8e24584d8d242d40d605752116ac05be33f697d3.tar.gz
- ResultProxy and friends always reference the DBAPI connection at the same time
as the cursor. There is no reason for CursorFairy - the only use case would be, end-user is using the pool or pool.manage with DBAPI connections, uses a cursor, deferences the owning connection and continues using cursor. This is an almost nonexistent use case and isn't correct usage at a DBAPI level. Take out CursorFairy. - move the "check for a dot in the colname" logic out to the sqlite dialect.
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r--lib/sqlalchemy/engine/base.py54
1 files changed, 34 insertions, 20 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index 90d6bda86..267249971 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -1319,6 +1319,23 @@ class Connection(Connectable):
self.close()
return r
+
+ def _safe_close_cursor(self, cursor):
+ """Close the given cursor, catching exceptions
+ and turning into log warnings.
+
+ """
+ try:
+ cursor.close()
+ except Exception, e:
+ try:
+ ex_text = str(e)
+ except TypeError:
+ ex_text = repr(e)
+ self.connection._logger.warn("Error closing cursor: %s", ex_text)
+
+ if isinstance(e, (SystemExit, KeyboardInterrupt)):
+ raise
def _handle_dbapi_exception(self,
e,
@@ -1347,7 +1364,7 @@ class Connection(Connectable):
self.engine.dispose()
else:
if cursor:
- cursor.close()
+ self._safe_close_cursor(cursor)
self._autorollback()
if self.should_close_with_result:
self.close()
@@ -2163,7 +2180,6 @@ class ResultMetaData(object):
# saved attribute lookup self._processors)
self._keymap = keymap = {}
self.keys = []
- self._echo = parent._echo
context = parent.context
dialect = context.dialect
typemap = dialect.dbapi_type_map
@@ -2172,14 +2188,6 @@ class ResultMetaData(object):
if dialect.description_encoding:
colname = colname.decode(dialect.description_encoding)
- if '.' in colname:
- # sqlite will in some circumstances prepend table name to
- # colnames, so strip
- origname = colname
- colname = colname.split('.')[-1]
- else:
- origname = None
-
if context.result_map:
try:
name, obj, type_ = context.result_map[colname.lower()]
@@ -2208,11 +2216,6 @@ class ResultMetaData(object):
# or the more precise ColumnElement)
keymap[name.lower()] = (processor, None)
- # store the "origname" if we truncated (sqlite only)
- if origname and \
- keymap.setdefault(origname.lower(), rec) is not rec:
- keymap[origname.lower()] = (processor, None)
-
if dialect.requires_name_normalize:
colname = dialect.normalize_name(colname)
@@ -2221,11 +2224,22 @@ class ResultMetaData(object):
for o in obj:
keymap[o] = rec
- if self._echo:
- self.logger = context.engine.logger
- self.logger.debug(
+ if parent._echo:
+ context.engine.logger.debug(
"Col %r", tuple(x[0] for x in metadata))
-
+
+ def _set_keymap_synonym(self, name, origname):
+ """Set a synonym for the given name.
+
+ Some dialects (SQLite at the moment) may use this to
+ adjust the column names that are significant within a
+ row.
+
+ """
+ rec = (processor, i) = self._keymap[origname.lower()]
+ if self._keymap.setdefault(name, rec) is not rec:
+ self._keymap[name] = (processor, None)
+
def _key_fallback(self, key):
map = self._keymap
result = None
@@ -2413,7 +2427,7 @@ class ResultProxy(object):
if not self.closed:
self.closed = True
- self.cursor.close()
+ self.connection._safe_close_cursor(self.cursor)
if _autoclose_connection and \
self.connection.should_close_with_result:
self.connection.close()