[Sqlalchemy-commits] [2364] sqlalchemy/trunk: - fixed function execution with explicit connections,
Brought to you by:
zzzeek
From: <co...@sq...> - 2007-02-27 17:02:07
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[2364] sqlalchemy/trunk: - fixed function execution with explicit connections, when you dont </title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>2364</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2007-02-27 13:04:43 -0600 (Tue, 27 Feb 2007)</dd> </dl> <h3>Log Message</h3> <pre>- fixed function execution with explicit connections, when you dont explicitly say "select()" off the function, i.e. conn.execute(func.dosomething())</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunkCHANGES">sqlalchemy/trunk/CHANGES</a></li> <li><a href="#sqlalchemytrunklibsqlalchemyenginebasepy">sqlalchemy/trunk/lib/sqlalchemy/engine/base.py</a></li> <li><a href="#sqlalchemytrunktestsqlquerypy">sqlalchemy/trunk/test/sql/query.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunkCHANGES"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/CHANGES (2363 => 2364)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/CHANGES 2007-02-25 22:44:52 UTC (rev 2363) +++ sqlalchemy/trunk/CHANGES 2007-02-27 19:04:43 UTC (rev 2364) </span><span class="lines">@@ -2,6 +2,9 @@ </span><span class="cx"> - exists() becomes useable as a standalone selectable, not just in a </span><span class="cx"> WHERE clause </span><span class="cx"> - correlated subqueries work inside of ORDER BY, GROUP BY </span><ins>+ - fixed function execution with explicit connections, when you dont + explicitly say "select()" off the function, i.e. + conn.execute(func.dosomething()) </ins><span class="cx"> - orm: </span><span class="cx"> - a full select() construct can be passed to query.select() (which </span><span class="cx"> worked anyway), but also query.selectfirst(), query.selectone() which </span></span></pre></div> <a id="sqlalchemytrunklibsqlalchemyenginebasepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/engine/base.py (2363 => 2364)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/engine/base.py 2007-02-25 22:44:52 UTC (rev 2363) +++ sqlalchemy/trunk/lib/sqlalchemy/engine/base.py 2007-02-27 19:04:43 UTC (rev 2364) </span><span class="lines">@@ -439,7 +439,11 @@ </span><span class="cx"> return self.execute(object, *multiparams, **params).scalar() </span><span class="cx"> </span><span class="cx"> def execute(self, object, *multiparams, **params): </span><del>- return Connection.executors[type(object).__mro__[-2]](self, object, *multiparams, **params) </del><ins>+ for c in type(object).__mro__: + if c in Connection.executors: + return Connection.executors[c](self, object, *multiparams, **params) + else: + raise exceptions.InvalidRequestError("Unexecuteable object type: " + str(type(object))) </ins><span class="cx"> </span><span class="cx"> def execute_default(self, default, **kwargs): </span><span class="cx"> return default.accept_schema_visitor(self.__engine.dialect.defaultrunner(self.__engine, self.proxy, **kwargs)) </span><span class="lines">@@ -467,7 +471,10 @@ </span><span class="cx"> return [multiparams[0]] </span><span class="cx"> else: </span><span class="cx"> return multiparams </span><del>- </del><ins>+ + def execute_function(self, func, *multiparams, **params): + return self.execute_clauseelement(func.select(), *multiparams, **params) + </ins><span class="cx"> def execute_clauseelement(self, elem, *multiparams, **params): </span><span class="cx"> executemany = len(multiparams) > 0 </span><span class="cx"> if executemany: </span><span class="lines">@@ -478,7 +485,6 @@ </span><span class="cx"> </span><span class="cx"> def execute_compiled(self, compiled, *multiparams, **params): </span><span class="cx"> """Execute a sql.Compiled object.""" </span><del>- </del><span class="cx"> if not compiled.can_execute: </span><span class="cx"> raise exceptions.ArgumentError("Not an executeable clause: %s" % (str(compiled))) </span><span class="cx"> cursor = self.__engine.dialect.create_cursor(self.connection) </span><span class="lines">@@ -501,6 +507,7 @@ </span><span class="cx"> </span><span class="cx"> # poor man's multimethod/generic function thingy </span><span class="cx"> executors = { </span><ins>+ sql._Function : execute_function, </ins><span class="cx"> sql.ClauseElement : execute_clauseelement, </span><span class="cx"> sql.ClauseVisitor : execute_compiled, </span><span class="cx"> schema.SchemaItem:execute_default, </span></span></pre></div> <a id="sqlalchemytrunktestsqlquerypy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/sql/query.py (2363 => 2364)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/sql/query.py 2007-02-25 22:44:52 UTC (rev 2363) +++ sqlalchemy/trunk/test/sql/query.py 2007-02-27 19:04:43 UTC (rev 2364) </span><span class="lines">@@ -232,6 +232,16 @@ </span><span class="cx"> z = testbase.db.func.current_date().scalar() </span><span class="cx"> assert x == y == z </span><span class="cx"> </span><ins>+ def test_conn_functions(self): + conn = testbase.db.connect() + try: + x = conn.execute(func.current_date()).scalar() + y = conn.execute(func.current_date().select()).scalar() + z = conn.scalar(func.current_date()) + finally: + conn.close() + assert x == y == z + </ins><span class="cx"> def test_update_functions(self): </span><span class="cx"> """test sending functions and SQL expressions to the VALUES and SET clauses of INSERT/UPDATE instances, </span><span class="cx"> and that column-level defaults get overridden""" </span></span></pre> </div> </div> </body> </html> |