summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-09-01 22:42:51 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-09-01 22:42:51 +0000
commit8386fc6dc596c74f5cc9981504e274beff8d69cc (patch)
tree7299ab6dd5cc7703b496064284817a6f130f1d7c /lib/sqlalchemy/engine/base.py
parente04535a79a7528440960575e3623fa620290e026 (diff)
downloadsqlalchemy-8386fc6dc596c74f5cc9981504e274beff8d69cc.tar.gz
sequence pre-executes dont create an ExecutionContext, use straight cursor
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r--lib/sqlalchemy/engine/base.py56
1 files changed, 34 insertions, 22 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index 1ab05fe03..45d84f90d 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -837,45 +837,50 @@ class Connection(Connectable):
return self.__engine.dialect.create_execution_context(connection=self, **kwargs)
def __execute_raw(self, context):
- if self.__engine._should_log_info:
- self.__engine.logger.info(context.statement)
- self.__engine.logger.info(repr(context.parameters))
if context.parameters is not None and isinstance(context.parameters, list) and len(context.parameters) > 0 and isinstance(context.parameters[0], (list, tuple, dict)):
- self.__executemany(context)
+ self._cursor_executemany(context.cursor, context.statement, context.parameters, context=context)
else:
- self.__execute(context)
+ if context.parameters is None:
+ if context.dialect.positional:
+ parameters = ()
+ else:
+ parameters = {}
+ else:
+ parameters = context.parameters
+ self._cursor_execute(context.cursor, context.statement, parameters, context=context)
self._autocommit(context)
- def __execute(self, context):
- if context.parameters is None:
- if context.dialect.positional:
- context.parameters = ()
- else:
- context.parameters = {}
+ def _cursor_execute(self, cursor, statement, parameters, context=None):
+ if self.__engine._should_log_info:
+ self.__engine.logger.info(statement)
+ self.__engine.logger.info(repr(parameters))
try:
- context.dialect.do_execute(context.cursor, context.statement, context.parameters, context=context)
+ self.dialect.do_execute(cursor, statement, parameters, context=context)
except Exception, e:
if self.dialect.is_disconnect(e):
self.__connection.invalidate(e=e)
self.engine.dispose()
- context.cursor.close()
+ cursor.close()
self._autorollback()
if self.__close_with_result:
self.close()
- raise exceptions.DBAPIError.instance(context.statement, context.parameters, e)
+ raise exceptions.DBAPIError.instance(statement, parameters, e)
- def __executemany(self, context):
+ def _cursor_executemany(self, cursor, statement, parameters, context=None):
+ if self.__engine._should_log_info:
+ self.__engine.logger.info(statement)
+ self.__engine.logger.info(repr(parameters))
try:
- context.dialect.do_executemany(context.cursor, context.statement, context.parameters, context=context)
+ self.dialect.do_executemany(cursor, statement, parameters, context=context)
except Exception, e:
if self.dialect.is_disconnect(e):
self.__connection.invalidate(e=e)
self.engine.dispose()
- context.cursor.close()
+ cursor.close()
self._autorollback()
if self.__close_with_result:
self.close()
- raise exceptions.DBAPIError.instance(context.statement, context.parameters, e)
+ raise exceptions.DBAPIError.instance(statement, parameters, e)
# poor man's multimethod/generic function thingy
executors = {
@@ -1632,7 +1637,6 @@ class DefaultRunner(schema.SchemaVisitor):
def __init__(self, context):
self.context = context
- self.connection = context._connection._branch()
self.dialect = context.dialect
def get_column_default(self, column):
@@ -1665,9 +1669,17 @@ class DefaultRunner(schema.SchemaVisitor):
return None
def exec_default_sql(self, default):
- c = expression.select([default.arg]).compile(bind=self.connection)
- return self.connection._execute_compiled(c).scalar()
-
+ conn = self.context.connection
+ c = expression.select([default.arg]).compile(bind=conn)
+ return conn._execute_compiled(c).scalar()
+
+ def execute_string(self, stmt, params=None):
+ """execute a string statement, using the raw cursor,
+ and return a scalar result."""
+ conn = self.context._connection
+ conn._cursor_execute(self.context.cursor, stmt, params)
+ return self.context.cursor.fetchone()[0]
+
def visit_column_onupdate(self, onupdate):
if isinstance(onupdate.arg, expression.ClauseElement):
return self.exec_default_sql(onupdate)