Part of the EllisLab Network

Bug Report

db->where() issue

Date: 05/13/2008 Severity: Critical
Status: Resolved Reporter: stanleyxu
Version: 1.6.2
Keywords:

Description

The following code
  $db->where(‘field’,’‘);

will be translated as
  WHERE `field`=

It should be
  WHERE `field`=’‘

The quotation marks are missing.

Code Sample

$db->where('field','');

Expected Result

WHERE `field`=’‘

Actual Result

WHERE `field`=

Comment on Bug Report

Page 1 of 1 pages
Posted by: stanleyxu on 13 May 2008 7:37pm
stanleyxu's avatar

Solution:

Change Line 457 to

if ($escape === TRUE OR $v === ‘’ OR $v === NULL)
{
  $v = ’ ‘.$this->escape($v);
}

Posted by: nicovv on 14 May 2008 5:36am
no avatar

Yes, I encountered the same bug, but the fix is OK!
Thanks

Posted by: Derek Allard on 14 May 2008 6:34am
Derek Allard's avatar

This doesn’t strike me as a bug at all.  CodeIgniter is comparing “field” against what yo asked it to compare against… which is nothing.  If I wanted to test for it that way I’d probably use

$this->db->where('field','""', FALSE);
// or
$this->db->where('field = ""');

Posted by: stanleyxu on 14 May 2008 7:42am
stanleyxu's avatar

Actually my code is:

$fields = explode(’,’, $csv_line); // $csv_line = “0,,2”
$db->where(array(
  ‘field0’ => $fields[0],
  ‘field1’ => $fields[1], // $fields[1] == “”
  ‘field2’ => $fields[2]
));

In previous version, fields[1] would be translated as “‘’”.
But in this version the SQL-statement is:
WHERE `field0`=‘1’ AND `field1`= AND `field2`=‘2’

Hi Derek, can you say it is not a bug?

Posted by: Derek Allard on 14 May 2008 7:59am
Derek Allard's avatar

I concede that earlier versions may have parsed it differently.  Behaviour was changed due to another bug report.

This being discussed in http://codeigniter.com/forums/viewthread/79423/.  Let’s continue the discussion there, and if warranted we’ll re-open this.

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?