[Sqlalchemy-commits] [2357] sqlalchemy/trunk: - a full select() construct can be passed to query.se
Brought to you by:
zzzeek
From: <co...@sq...> - 2007-02-22 20:57:24
|
<!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>[2357] sqlalchemy/trunk: - a full select() construct can be passed to query.select() (which</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>2357</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2007-02-22 16:59:51 -0600 (Thu, 22 Feb 2007)</dd> </dl> <h3>Log Message</h3> <pre>- a full select() construct can be passed to query.select() (which worked anyway), but also query.selectfirst(), query.selectone() which will be used as is (i.e. no query is compiled). works similarly to sending the results to instances().</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunkCHANGES">sqlalchemy/trunk/CHANGES</a></li> <li><a href="#sqlalchemytrunklibsqlalchemyormquerypy">sqlalchemy/trunk/lib/sqlalchemy/orm/query.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunkCHANGES"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/CHANGES (2356 => 2357)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/CHANGES 2007-02-22 04:23:15 UTC (rev 2356) +++ sqlalchemy/trunk/CHANGES 2007-02-22 22:59:51 UTC (rev 2357) </span><span class="lines">@@ -1,3 +1,8 @@ </span><ins>+- orm: + - a full select() construct can be passed to query.select() (which + worked anyway), but also query.selectfirst(), query.selectone() which + will be used as is (i.e. no query is compiled). works similarly to + sending the results to instances(). </ins><span class="cx"> 0.3.5 </span><span class="cx"> - sql: </span><span class="cx"> - the value of "case_sensitive" defaults to True now, regardless of the </span></span></pre></div> <a id="sqlalchemytrunklibsqlalchemyormquerypy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/orm/query.py (2356 => 2357)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/orm/query.py 2007-02-22 04:23:15 UTC (rev 2356) +++ sqlalchemy/trunk/lib/sqlalchemy/orm/query.py 2007-02-22 22:59:51 UTC (rev 2357) </span><span class="lines">@@ -213,19 +213,22 @@ </span><span class="cx"> The criterion is constructed in the same way as the select_by() method.""" </span><span class="cx"> return self.count(self.join_by(*args, **params)) </span><span class="cx"> </span><del>- def selectfirst(self, *args, **params): </del><ins>+ def selectfirst(self, arg=None, **kwargs): </ins><span class="cx"> """works like select(), but only returns the first result by itself, or None if no </span><span class="cx"> objects returned.""" </span><del>- params['limit'] = 1 - ret = self.select_whereclause(*args, **params) </del><ins>+ if isinstance(arg, sql.FromClause) and arg.supports_execution(): + ret = self.select_statement(arg, **kwargs) + else: + kwargs['limit'] = 1 + ret = self.select_whereclause(whereclause=arg, **kwargs) </ins><span class="cx"> if ret: </span><span class="cx"> return ret[0] </span><span class="cx"> else: </span><span class="cx"> return None </span><span class="cx"> </span><del>- def selectone(self, *args, **params): </del><ins>+ def selectone(self, arg=None, **kwargs): </ins><span class="cx"> """works like selectfirst(), but throws an error if not exactly one result was returned.""" </span><del>- ret = list(self.select(*args, **params)[0:2]) </del><ins>+ ret = list(self.select(arg, **kwargs)[0:2]) </ins><span class="cx"> if len(ret) == 1: </span><span class="cx"> return ret[0] </span><span class="cx"> elif len(ret) == 0: </span><span class="lines">@@ -247,7 +250,7 @@ </span><span class="cx"> ret = self.extension.select(self, arg=arg, **kwargs) </span><span class="cx"> if ret is not mapper.EXT_PASS: </span><span class="cx"> return ret </span><del>- if isinstance(arg, sql.FromClause): </del><ins>+ if isinstance(arg, sql.FromClause) and arg.supports_execution(): </ins><span class="cx"> return self.select_statement(arg, **kwargs) </span><span class="cx"> else: </span><span class="cx"> return self.select_whereclause(whereclause=arg, **kwargs) </span></span></pre> </div> </div> </body> </html> |