summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/base.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-09-25 10:29:52 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2013-09-25 10:29:52 -0700
commit03671e9ee4c13f4d7e98ec4a5076fd9c9979e44d (patch)
tree8b56024ae1ef21d19d09763530beafb8b8d624ce /lib/sqlalchemy/engine/base.py
parent08a6a8b51916ab1d084a0070bbb07001cabb1c38 (diff)
downloadsqlalchemy-pr/30.tar.gz
Replace a big loop + dict lookup in Connection.execute() with a simple visitorpr/30
pattern
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r--lib/sqlalchemy/engine/base.py25
1 files changed, 7 insertions, 18 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index 9a10e829e..93539cb14 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -652,17 +652,16 @@ class Connection(Connectable):
DBAPI-agnostic way, use the :func:`~.expression.text` construct.
"""
- for c in type(object).__mro__:
- if c in Connection.executors:
- return Connection.executors[c](
- self,
- object,
- multiparams,
- params)
- else:
+ if isinstance(object, util.string_types[0]):
+ return self._execute_text(object, multiparams, params)
+ try:
+ meth = object._execute_on_connection
+ except AttributeError:
raise exc.InvalidRequestError(
"Unexecutable object type: %s" %
type(object))
+ else:
+ return meth(self, multiparams, params)
def _execute_function(self, func, multiparams, params):
"""Execute a sql.FunctionElement object."""
@@ -1038,16 +1037,6 @@ class Connection(Connectable):
if self.should_close_with_result:
self.close()
- # poor man's multimethod/generic function thingy
- executors = {
- expression.FunctionElement: _execute_function,
- expression.ClauseElement: _execute_clauseelement,
- Compiled: _execute_compiled,
- schema.SchemaItem: _execute_default,
- ddl.DDLElement: _execute_ddl,
- util.string_types[0]: _execute_text
- }
-
def default_schema_name(self):
return self.engine.dialect.get_default_schema_name(self)