Beispiel #1
0
 public function testOrderRandom()
 {
     $builder = new BaseBuilder('user', $this->db);
     $builder->orderBy('name', 'random');
     $expectedSQL = "SELECT * FROM \"user\" ORDER BY RAND()";
     $this->assertEquals($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
 }
Beispiel #2
0
 /**
  * ORDER BY
  *
  * @param    string $orderby
  * @param    string $direction ASC, DESC or RANDOM
  * @param    bool   $escape
  *
  * @return    BaseBuilder
  */
 public function orderBy($orderby, $direction = '', $escape = null)
 {
     $direction = strtoupper(trim($direction));
     if ($direction === 'RANDOM') {
         if (!is_float($orderby) && ctype_digit((string) $orderby)) {
             $orderby = (double) ($orderby > 1 ? "0.{$orderby}" : $orderby);
         }
         if (is_float($orderby)) {
             $this->db->simpleQuery("SET SEED {$orderby}");
         }
         $orderby = $this->randomKeyword[0];
         $direction = '';
         $escape = false;
     }
     return parent::orderBy($orderby, $direction, $escape);
 }