• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WHERE condition has missed in query

#1
We faced an issue while updating a table record.

We have provided WHERE condition to update 1 record in table. But in query there is no WHERE condition (its missed) while updating for that table. So query has updated all the 20 k records in table.

Query:

$result = $this->update($id, TABLE_NAME);


In log:

UPDATE `TABLE_NAME` SET `status` = 1, `user_id` = 322, `updated_by` = 'system'

Expected:
UPDATE `TABLE_NAME` SET `status` = 1, `user_id` = 322, `updated_by` = 'system' WHERE `TABLE_NAME`.`id` =  '2454'


This logic is there from long time and it was working fine. At particular time the WHERE condition has broken and till now we are not able to replicate the issue.
Reply

#2
@Sangamesh,

This seems pretty straight forward. Something has changed to cause this to happen. Is it possible to see the whole method/function that houses the mentioned query above? Also, was there any changes made to the code? Do you have a code versioning tool that is used? Exactly, when did it stop working and what events happened prior to query not working correctly anymore?
Reply

#3
(07-02-2019, 08:07 AM)php_rocs Wrote: @Sangamesh,

This seems pretty straight forward. Something has changed to cause this to happen.  Is it possible to see the whole method/function that houses the mentioned query above?  Also, was there any changes made to the code?  Do you have a code versioning tool that is used?  Exactly, when did it stop working and what events happened prior to query not working correctly anymore?

We have written the logic of update the query inside our custom model.

Custom model then will call to CI model.

$this->db->update($this->table_name, $attributes);

But even we have logic of updating to other table in another query with where condition as below mentioned

$this->db->where(array('id' => $id))->where('active IS NULL')->update($this->table_name, $attributes);


We are running these 2 queries inside transaction.

When we faced that issue, 2 tables got updated to all the records without WHERE condition in 2 queries.

Is there any transaction problem? or our queries tries to update at same time any other queries has loaded? or any other scenarios?

Not sure on all these
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.