diff options
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 25 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 3 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/ddl.py | 3 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 3 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/functions.py | 3 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/schema.py | 3 |
6 files changed, 22 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) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 8e3cf1729..f81886240 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -200,6 +200,9 @@ class Compiled(object): """Produce the internal string representation of this element.""" pass + def _execute_on_connection(self, connection, multiparams, params): + return connection._execute_compiled(self, multiparams, params) + @property def sql_compiler(self): """Return a Compiled that is capable of processing SQL expressions. diff --git a/lib/sqlalchemy/sql/ddl.py b/lib/sqlalchemy/sql/ddl.py index 2a81b3394..72ef07732 100644 --- a/lib/sqlalchemy/sql/ddl.py +++ b/lib/sqlalchemy/sql/ddl.py @@ -63,6 +63,9 @@ class DDLElement(Executable, _DDLCompiles): dialect = None callable_ = None + def _execute_on_connection(self, connection, multiparams, params): + return connection._execute_ddl(self, multiparams, params) + def execute(self, bind=None, target=None): """Execute this DDL immediately. diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 92cbc3653..ea2132e67 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -292,6 +292,9 @@ class ClauseElement(Visitable): # self return self + def _execute_on_connection(self, connection, multiparams, params): + return connection._execute_clauseelement(self, multiparams, params) + def unique_params(self, *optionaldict, **kwargs): """Return a copy with :func:`bindparam()` elements replaced. diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index 24f79466c..489be8934 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -60,6 +60,9 @@ class FunctionElement(Executable, ColumnElement, FromClause): group_contents=True, *args).\ self_group() + def _execute_on_connection(self, connection, multiparams, params): + return connection._execute_function(self, multiparams, params) + @property def columns(self): """Fulfill the 'columns' contract of :class:`.ColumnElement`. diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index b190c3874..35bab8e9d 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -68,6 +68,9 @@ class SchemaItem(SchemaEventTarget, visitors.Visitable): __visit_name__ = 'schema_item' + def _execute_on_connection(self, connection, multiparams, params): + return connection._execute_default(self, multiparams, params) + def _init_items(self, *args): """Initialize the list of child items for this SchemaItem.""" |