Part of the EllisLab Network

Bug Report

Manage NULL value on ActiveRecord

Date: 03/14/2008 Severity: Minor
Status: Bogus Reporter: Alessandro Pagnin
Version: 1.6.1
Keywords:

Description

When a variable as a NULL value, the SQL has to change.

=== Example ===
$this->db->get_where(’table’, array(’col’=> $a));
generate:
SELECT * FROM table WHERE col = $a;
but if $a == NULL I think that the correct code is:
SELECT * FROM table WHERE col is NULL;

Reference:
http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html

Code Sample

$this->db->get_where('table', array('col'=> $a));

Expected Result

// With $a != NULL
SELECT * FROM table WHERE col = $a;
// With $a == NULL
SELECT * FROM table WHERE col IS NULL;

Actual Result

SELECT * FROM table WHERE col = $a;

Comment on Bug Report

Page 1 of 1 pages
Posted by: Seppo on 20 March 2008 1:10pm
Seppo's avatar

I’m actually getting

SELECT * FROM (`table`) WHERE `col` IS NULL

as expected.

This is my code

function index()
    
{
        $this
->load->database();
        
$a = null;
        
$this->db->get_where('table', array('col'=> $a));
        
$this->load->view('welcome_message');
    
}

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?