Dear all,
I think I hit a bug in CodeIgniter 1.5.3 and 1.5.4.
When I use DB Active Record’s update() function in combination with the limit() function, the limit() part is not added to the SQL query.
When I then use the get() function after the before mentioned update() function, the limit() part is added to the SQL query that get() generates, even though I didn’t set limit() for the get().
Example:
$this->CI->db->set("last_page_datetime", date("Y-m-d H:i:s"));
$this->CI->db->set("last_page_ip", $this->CI->input->ip_address());
$this->CI->db->where("user_id", $user_id);
$this->CI->db->limit(1); //setting this will remain the limit for the next query. Huh?!?!?!?!?!?!
$this->CI->db->update("users");
echo $this->CI->db->last_query();
Expected result from echo statement:
UPDATE users SET last_page_datetime = '2007-09-21 22:30:12', last_page_ip = '127.0.0.1'
WHERE user_id = '2' LIMIT 1
Actual result:
UPDATE users SET last_page_datetime = '2007-09-21 22:30:12', last_page_ip = '127.0.0.1'
WHERE user_id = '2'
The error: the limit clause is missing.
Now the get():
$this->CI->db->order_by('lastname', 'ASC');
$query = $this->CI->db->get('users');
echo $this->CI->db->last_query();
Expected result from echo statement:
SELECT * FROM users ORDER BY lastname ASC
Actual result:
SELECT * FROM users ORDER BY lastname ASC LIMIT 1
The error: the limit clause from the previous query is added.
Is this a bug? Any thought/reactions are very welcome.
BTW, I saw one other thread which also reported a missing LIMIT in an update query (see second post in that thread).
TIA,
Maarten
P.S. These functions are used in a self written library, hence the “$this->CI->db->...”.
