CodeIgniter Forums
active record bug on update - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: active record bug on update (/showthread.php?tid=3560)



active record bug on update - El Forum - 10-10-2007

[eluser]anurat[/eluser]
Hi All,
I found that if I put null value in where clause,
It will update the whole table. This is very serious
It should return an error and not execute the command
which is what happens if you use sql update statement.

Here is an example.
Code:
$id = null;
  $_data = array( 'csu_id' => 20 );
  $this->db->where( 'sl_id', $id );
  $this->db->update( 'storefront_lead', $_data );
All rows will have csu_id = 20

Thanks,
Anurat,


active record bug on update - El Forum - 10-10-2007

[eluser]Michael Wales[/eluser]
This bug was documented here.

A few potential solutions were posted as well: here and here.

I think the jury is still out there as to whether this is actually a bug or not. You really should validate your data prior to performing any potentially destructive queries.


active record bug on update - El Forum - 10-10-2007

[eluser]anurat[/eluser]
I disagree. If I run an sql query equivalent to this
it will just return an error. I expect this to behave the same.
If not you'd be better of using good old sql query.

Allowing an incomplete query to run is unacceptable.