weird bug on database model [ci 1.6.2] - 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: weird bug on database model [ci 1.6.2] (/showthread.php?tid=9011) |
weird bug on database model [ci 1.6.2] - El Forum - 06-09-2008 [eluser]adwin[/eluser] Hi .. I found a bug that not always happened in my model i use ci 1.6.2 here is my code Code: function save() as you can see, there is Code: $this->db->set('measureid',$this->measureid); measureid and goodsid is linked with other table (foreign keys) when I did insert it produce the error because measureid or goodsid not included into the insert sql. here is the error: Code: Cannot add or update a child row: a foreign key constraint fails (`ci/podt`, CONSTRAINT `podt_ibfk_2` FOREIGN KEY (`goodsid`) REFERENCES `mtgoods` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) as you can see on my code, i have set the goodsid and measureid right ? weird bug on database model [ci 1.6.2] - El Forum - 06-09-2008 [eluser]Pascal Kriete[/eluser] That is quite odd, and I have no idea what could be causing it. Even if the variables aren't defined the fields should still get set. What type of database are you using? And can you try it without the transaction, just to whittle away at the possible causes and get a reduced version. weird bug on database model [ci 1.6.2] - El Forum - 06-09-2008 [eluser]adwin[/eluser] I did a research on this Code: $this->db->set('measureid',$this->measureid); it produce this code: Code: goodsid:1Array ( [`measureid`] => '1' [`qty`] => 20 [`unitprice`] => '30000' [`discount`] => '300' [`total`] => 599700 ) and something even weird than this if I change the goodsid into something other that 1 it will produce a correct result: Code: goodsid:6Array ( [`measureid`] => '1' [`goodsid`] => '6' [`qty`] => 20 [`unitprice`] => '30000' [`discount`] => '300' [`total`] => 599700 ) ... and this one will make you confuse a lot ... I change the code into this (just changing the place of measureid and goodsid Code: $this->db->set('goodsid',$this->goodsid); if the goodsid and measureid = 1 the result : (no measureid in the ar_set) Code: goodsid: 1 measureid :1 Array ( [`goodsid`] => '1' [`qty`] => 20 [`unitprice`] => '30000' [`discount`] => '300' [`total`] => 599700 ) if the goodsid changed to other than 1 result Code: goodsid: 10 measureid :1 Array ( [`goodsid`] => '10' [`measureid`] => '1' [`qty`] => 20 [`unitprice`] => '30000' [`discount`] => '300' [`total`] => 599700 ) I will check on active record set() function after this so weird ... so true ... weird bug on database model [ci 1.6.2] - El Forum - 06-09-2008 [eluser]adwin[/eluser] [quote author="inparo" date="1213011231"]That is quite odd, and I have no idea what could be causing it. Even if the variables aren't defined the fields should still get set. What type of database are you using? And can you try it without the transaction, just to whittle away at the possible causes and get a reduced version.[/quote] I did without transaction ... look at my 2nd post. i just doing db->set() ... I use mysql database ... before i used to use array instead of using db->set() and it works well ... now i want to make my code looks better so I use set. any idea hahahaha ... weird bug on database model [ci 1.6.2] - El Forum - 06-09-2008 [eluser]adwin[/eluser] I make a deeper research on this I did a modification on system\database\DB_active_rec.php Code: function set($key, $value = '', $escape = TRUE) I just add print_r($this->ar_set); echo '<br/>'; to see what the happens in arr_set[] array ... and when the code (my 2nd post) was runned it produce Code: Array ( [`goodsid`] => '1' ) but if I change the measureid into something else Code: Array ( [`goodsid`] => '1' ) so weird ... ps: I use PHP Version 5.2.5 weird bug on database model [ci 1.6.2] - El Forum - 06-09-2008 [eluser]adwin[/eluser] I found the problem but don't know which one is the error ... and i think it is not logic at all .. I found that the problem was caused by calculatetotal() function ... but that function dont have anything to do with db->ar_set() Code: function calculatetotal(){ let me know if someone knows about this incident .. i am still curious ... |