Bugs in new database class(es), active record |
[eluser]Velizar N.[/eluser]
After an update from 1.6.3 to 1.7 this code doesn't work: Code: $this->db->select('c.Code, c.Name, cl.Language'); this is a problem: Code: $this->db->where('field_name!=', ''); and this ... Code: $this->db->order_by("cl.Language", "random"); so I recommend you to revert to the previous DB classes before some general database bug(s) fixing.
[eluser]apersaud[/eluser]
Yes, 'random' seems to be broken in 1.7. Doing: Code: $this->db->order_by('id','random')->get('table'); I get a MySQL Error (CodeIgniter formatted). The only workaround I found is to revert to doing: Code: $this->db->order_by('RAND()')->get('table');
[eluser]demogar[/eluser]
I also have a problem doing some "COUNT(table.id) AS id" (for example) in my database... So I'm using the 1.6.3 db library
[eluser]jasonjohnson[/eluser]
I've created a patch for this bug. The bug itself can be very easily reproduced using the following code: Code: $this->db->order_by('column', 'random'); My patch corrects the order_by method to test if the direction has been set to the "_random_keyword" value and bypasses a call to "_protect_identifiers" (as it would be protecting an empty value, $orderby = '' and appends extraneous text to the query (and breaks it)) -- in all other cases, this should act as expected. Code: --- DB_active_rec.orig.php 2008-10-18 02:47:54.000000000 -0500 I will be submitting this patch to the bug thread: http://codeigniter.com/bug_tracker/bug/5706/ Hope this helps! Edit: I didn't dig into CI_DB_driver::_protect_identifiers itself because it is a much more complex function. The potential for breaking stuff is much greater the deeper we dig.
[eluser]jasonjohnson[/eluser]
I checked out a fresh copy of CI from SVN to discover the order_by method had been almost completely rewritten. Probably a good sign this bug has been taken care of, it simply hasn't been checked as "Fixed" in the bug tracker. Anyone still interested in this should probably check SVN first. |
Welcome Guest, Not a member yet? Register Sign In |