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

Merged
merged 3 commits into from Jul 28, 2012

Conversation

Projects
None yet
2 participants
@suralc
Contributor

suralc commented Jul 28, 2012

Fixes #1045

Build Status

$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;

This comment has been minimized.

@suralc

suralc Jul 28, 2012

Contributor

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)

@suralc

suralc Jul 28, 2012

Contributor

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)

This comment has been minimized.

@samdark

samdark Jul 28, 2012

Member

Yeah, that's OK.

@samdark

samdark Jul 28, 2012

Member

Yeah, that's OK.

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';

This comment has been minimized.

@samdark

samdark Jul 28, 2012

Member

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

@samdark

samdark Jul 28, 2012

Member

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

This comment has been minimized.

@suralc

suralc Jul 28, 2012

Contributor

Edit: yes

@suralc

suralc Jul 28, 2012

Contributor

Edit: yes

@ghost ghost assigned samdark Jul 28, 2012

@suralc

This comment has been minimized.

Show comment
Hide comment

samdark added a commit that referenced this pull request Jul 28, 2012

Merge pull request #1050 from suralc/1045-clean-fix-builtQuery
#1045 Fixes incorrect sql-string when passing empty values to buildQuery

@samdark samdark merged commit 5140e0d into yiisoft:master Jul 28, 2012

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Jul 28, 2012

Member

Thanks for the fix.

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