diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2005-12-23 01:37:10 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2005-12-23 01:37:10 +0000 |
commit | dbd407d62ac3cbf6e54de7499f1a95b54e3e4204 (patch) | |
tree | aba3a06c75f1c7e477e2429cfe6d97401242da35 /lib/sqlalchemy/engine.py | |
parent | d22f5edcae0f29c6542e800660bc4fef9b3f12cb (diff) | |
download | sqlalchemy-dbd407d62ac3cbf6e54de7499f1a95b54e3e4204.tar.gz |
move execute parameter processing from sql.ClauseElement to engine.execute_compiled
testbase gets "assert_sql_count" method, moves execution wrapping to pre_exec to accomodate engine change
move _get_colparams from Insert/Update to ansisql since it applies to compilation
ansisql also insures that select list for columns is unique, helps the mapper with the "distinct" keyword
docstrings/cleanup
Diffstat (limited to 'lib/sqlalchemy/engine.py')
-rw-r--r-- | lib/sqlalchemy/engine.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/sqlalchemy/engine.py b/lib/sqlalchemy/engine.py index 349bb4d1d..1e5ba34d0 100644 --- a/lib/sqlalchemy/engine.py +++ b/lib/sqlalchemy/engine.py @@ -324,10 +324,11 @@ class SQLEngine(schema.SchemaEngine): pass def execute_compiled(self, compiled, parameters, connection=None, cursor=None, echo=None, **kwargs): - """executes the given string-based SQL statement with the given parameters. + """executes the given compiled statement object with the given parameters. - The parameters can be a dictionary or a list, or a list of dictionaries or lists, depending - on the paramstyle of the DBAPI. + The parameters can be a dictionary of key/value pairs, or a list of dictionaries for an + executemany() style of execution. Engines that use positional parameters will convert + the parameters to a list before execution. If the current thread has specified a transaction begin() for this engine, the statement will be executed in the context of the current transactional connection. @@ -360,6 +361,12 @@ class SQLEngine(schema.SchemaEngine): if cursor is None: cursor = connection.cursor() + executemany = parameters is not None and (isinstance(parameters, list) or isinstance(parameters, tuple)) + if executemany: + parameters = [compiled.get_params(**m) for m in parameters] + else: + parameters = compiled.get_params(**parameters) + def proxy(statement=None, parameters=None): if statement is None: return cursor @@ -371,7 +378,7 @@ class SQLEngine(schema.SchemaEngine): parameters = [p.values() for p in parameters] else: parameters = parameters.values() - + self.execute(statement, parameters, connection=connection, cursor=cursor) return cursor |