Welcome Guest, Not a member yet? Register   Sign In
Bugs in new database class(es), active record
#1

[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->db->join('countrylanguage cl', 'c.Code = cl.CountryCode', 'inner');
$this->db->where('cl.Language!=', '');
$this->db->order_by("cl.Language", "random");        
$query = $this->db->get('country c',10,0);

this is a problem:
Code:
$this->db->where('field_name!=', '');
$this->db->where('field_name>=', '');
etc.

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.
#2

[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');
#3

[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
#4

[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');
$this->db->get('table');

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
+++ DB_active_rec.patch.php    2008-11-10 00:43:00.000000000 -0600
@@ -874,8 +874,8 @@
             $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
         }
        
-        $orderby_statement = $this->_protect_identifiers($orderby).$direction;
-        
+        $orderby_statement = (($direction == $this->_random_keyword)?'':$this->_protect_identifiers($orderby)).$direction;
+                
         $this->ar_orderby[] = $orderby_statement;
         if ($this->ar_caching === TRUE)
         {

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.
#5

[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.




Theme © iAndrew 2016 - Forum software by © MyBB