Welcome Guest, Not a member yet? Register   Sign In
Orderby column RAND() error
#1

[eluser]barbazul[/eluser]
A couple of days ago I found this bug marked as Resolved on the bug tracker.

I wasn't satisfied by the way it was resolved (by not mentioning the random ordering feature) so I looked for ways of really fixing the bug.

The reason why the guys at ellislab decided to make a short term solution was that each DB engine has a different way of calling the RAND() function

My idea of a good fix would be to set a key word to trigger random ordering like "random_order" or something like that.

I set out to look for the different ways of random ordering in the currently supported DB Drivers and the only big difference I found, was the way of calling the RAND() function, that is, the rest of the syntax remains untouched. This supported my idea for the fix so I prepared a list of changes to be made to DB_AR and to each driver.

I know for sure this will work in MySQL but I haven't tested in any of the other devices

File system/database/DB_active_record.php
Line 406
Code:
//Check for random ordering
if (strtolower($orderby) == ‘random’)
{
$orderby = $this->_random();
}

File system/database/drivers/mssql/mssql_driver.php
Line 478
Code:
// --------------------------------------------------------------------

/**
* Order criteria used for random ordering
*
* @return string
*/
function _random()
{
return “NEWID()”;
}

File system/database/drivers/mysql/mysql_driver.php
Line 485
Code:
// --------------------------------------------------------------------

/**
* Order criteria used for random ordering
*
* @return string
*/
function _random()
{
return “RAND()”;
}

File system/database/drivers/mysqli/mysqli_driver.php
Line 475
Code:
// --------------------------------------------------------------------

/**
* Order criteria used for random ordering
*
* @return string
*/
function _random()
{
return “RAND()”;
}

File system/database/drivers/oci8/oci8_driver.php
Line 601
Code:
// --------------------------------------------------------------------

/**
* Order criteria used for random ordering
*
* @return string
*/
function _random()
{
return “dbms_random.value”;
}

File system/database/drivers/odbc/odbc_driver.php
Line 449
Code:
// --------------------------------------------------------------------

/**
* Order criteria used for random ordering
*
* @return string
*/
function _random()
{
return “RND(”.time().")";
}

File system/database/drivers/postgre/postgre_driver.php
Line 482
Code:
// --------------------------------------------------------------------

/**
* Order criteria used for random ordering
*
* @return string
*/
function _random()
{
return “RANDOM()”;
}

File system/database/drivers/sqlite/sqlite_driver.php
Line 481
Code:
// --------------------------------------------------------------------

/**
* Order criteria used for random ordering
*
* @return string
*/
function _random()
{
return “RANDOM()”;
}


-- EDIT: removed an apparently offensive comment


Messages In This Thread
Orderby column RAND() error - by El Forum - 11-01-2007, 08:57 PM
Orderby column RAND() error - by El Forum - 11-01-2007, 09:19 PM
Orderby column RAND() error - by El Forum - 11-02-2007, 10:46 AM
Orderby column RAND() error - by El Forum - 12-18-2007, 10:16 AM
Orderby column RAND() error - by El Forum - 12-29-2007, 01:21 PM
Orderby column RAND() error - by El Forum - 01-04-2008, 11:52 AM
Orderby column RAND() error - by El Forum - 01-04-2008, 12:35 PM
Orderby column RAND() error - by El Forum - 01-04-2008, 06:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB