Skip to content

#1045 Fixes incorrect sql-string when passing empty values to buildQuery #1050

Merged
merged 3 commits into from Jul 28, 2012

2 participants

@suralc
suralc commented Jul 28, 2012

Fixes #1045

Build Status

@suralc suralc commented on the diff Jul 28, 2012
framework/db/CDbCommand.php
$sql.="\nHAVING ".$query['having'];
- if(isset($query['order']))
+ if(!empty($query['order']))
$sql.="\nORDER BY ".$query['order'];
$limit=isset($query['limit']) ? (int)$query['limit'] : -1;
@suralc
suralc added a note Jul 28, 2012

I let isset stay there, as it will build an valid sql-string, even if limit is empty
(Well, empty resultset, but still valid atleast on mysql)

LIMIT 0


mysql> SELECT * FROM addon LIMIT 0,0;
Empty set (0.00 sec)

@samdark
Yii Software LLC member
samdark added a note Jul 28, 2012

Yeah, that's OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@samdark samdark and 1 other commented on an outdated diff Jul 28, 2012
framework/db/CDbCommand.php
@@ -541,27 +541,27 @@ private function queryInternal($method,$mode,$params=array())
*/
public function buildQuery($query)
{
- $sql=isset($query['distinct']) && $query['distinct'] ? 'SELECT DISTINCT' : 'SELECT';
- $sql.=' '.(isset($query['select']) ? $query['select'] : '*');
+ $sql=!empty($query['distinct']) && $query['distinct'] ? 'SELECT DISTINCT' : 'SELECT';
@samdark
Yii Software LLC member
samdark added a note Jul 28, 2012

No need for && $query['distinct'] here.

@suralc
suralc added a note Jul 28, 2012

Edit: yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@samdark samdark was assigned Jul 28, 2012
@samdark samdark merged commit 5140e0d into yiisoft:master Jul 28, 2012
@samdark
Yii Software LLC member
samdark commented Jul 28, 2012

Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.