- result sets from CRUD operations close their underlying cursor immediately.

will also autoclose the connection if defined for the operation; this
    allows more efficient usage of connections for successive CRUD operations
    with less chance of "dangling connections".
This commit is contained in:
Mike Bayer
2007-06-14 18:17:05 +00:00
parent ca5480de91
commit baba8281df
5 changed files with 27 additions and 10 deletions
+4
View File
@@ -31,6 +31,10 @@
- result.last_inserted_ids() should return a list that is identically
sized to the primary key constraint of the table. values that were
"passively" created and not available via cursor.lastrowid will be None.
- result sets from CRUD operations close their underlying cursor immediately.
will also autoclose the connection if defined for the operation; this
allows more efficient usage of connections for successive CRUD operations
with less chance of "dangling connections".
- long-identifier detection fixed to use > rather than >= for
max ident length [ticket:589]
- fixed bug where selectable.corresponding_column(selectable.c.col)
+5 -5
View File
@@ -134,11 +134,11 @@ def descriptor():
class PGExecutionContext(default.DefaultExecutionContext):
def is_select(self):
return re.match(r'SELECT', self.statement.lstrip(), re.I) and not re.search(r'FOR UPDATE\s*$', self.statement, re.I)
def _is_server_side(self):
return self.dialect.server_side_cursors and self.is_select() and not re.search(r'FOR UPDATE(?: NOWAIT)?\s*$', self.statement, re.I)
def create_cursor(self):
if self.dialect.server_side_cursors and self.is_select():
if self._is_server_side():
# use server-side cursors:
# http://lists.initd.org/pipermail/psycopg/2007-January/005251.html
ident = "c" + hex(random.randint(0, 65535))[2:]
@@ -147,7 +147,7 @@ class PGExecutionContext(default.DefaultExecutionContext):
return self.connection.connection.cursor()
def get_result_proxy(self):
if self.dialect.server_side_cursors and self.is_select():
if self._is_server_side():
return base.BufferedRowResultProxy(self)
else:
return base.ResultProxy(self)
+3
View File
@@ -141,6 +141,9 @@ class SQLiteExecutionContext(default.DefaultExecutionContext):
if self.compiled.isinsert:
self._last_inserted_ids = [self.cursor.lastrowid] + self._last_inserted_ids[1:]
super(SQLiteExecutionContext, self).post_exec()
def is_select(self):
return re.match(r'SELECT|PRAGMA', self.statement.lstrip(), re.I) is not None
class SQLiteDialect(ansisql.ANSIDialect):
+14 -4
View File
@@ -861,10 +861,20 @@ class ResultProxy(object):
self.closed = False
self.cursor = context.cursor
self.__echo = logging.is_debug_enabled(context.engine.logger)
self._init_metadata()
rowcount = property(lambda s:s.context.get_rowcount())
connection = property(lambda s:s.context.connection)
if context.is_select():
self._init_metadata()
self._rowcount = None
else:
self._rowcount = context.get_rowcount()
self.close()
connection = property(lambda self:self.context.connection)
def _get_rowcount(self):
if self._rowcount is not None:
return self._rowcount
else:
return self.context.get_rowcount()
rowcount = property(_get_rowcount)
def _init_metadata(self):
if hasattr(self, '_ResultProxy__props'):
+1 -1
View File
@@ -191,7 +191,7 @@ class DefaultExecutionContext(base.ExecutionContext):
return proc(params)
def is_select(self):
return re.match(r'SELECT', self.statement.lstrip(), re.I)
return re.match(r'SELECT', self.statement.lstrip(), re.I) is not None
def create_cursor(self):
return self.connection.connection.cursor()