public function testQueryBuilderAggregates() { $qb = db_max('post', 'postViews'); $this->assertEqual($qb->getSQL(), 'SELECT MAX(`postViews`) max FROM `post` `post`'); $qb = db_max('post', 'postViews', 'maxPostViews'); $this->assertEqual($qb->getSQL(), 'SELECT MAX(`postViews`) maxPostViews FROM `post` `post`'); $qb = db_min('post', 'postViews'); $this->assertEqual($qb->getSQL(), 'SELECT MIN(`postViews`) min FROM `post` `post`'); $qb = db_sum('post', 'postViews'); $this->assertEqual($qb->getSQL(), 'SELECT SUM(`postViews`) sum FROM `post` `post`'); $qb = db_avg('post', 'postViews'); $this->assertEqual($qb->getSQL(), 'SELECT AVG(`postViews`) avg FROM `post` `post`'); $qb = db_max('post', 'postViews'); $qb->min('postViews', 'min'); $this->assertEqual($qb->getSQL(), 'SELECT MAX(`postViews`) max, MIN(`postViews`) min FROM `post` `post`'); $qb = db_select('post', 'p')->max('postViews', 'max')->min('postViews', 'min'); $this->assertEqual($qb->getSQL(), 'SELECT MAX(`postViews`) max, MIN(`postViews`) min FROM `post` `p`'); }
function GetNextCatID($id) { if (isset($this->cache['NextCatID'][$id])) { return $this->cache['NextCatID'][$id]; } $r = db_min($this->settings['content'], 'id', "`id`>{$id}"); if ($r <= 0) { $r = -1; } $this->cache['NextCatID'][$id] = $r; return $r; }
function db_move_down($table, $id, $clause = '', $idfield = 'id', $orderfield = 'order') { $order = db_field_value($table, $orderfield, "`{$idfield}`={$id}"); if ($order == '') { return false; } $min = db_min($table, 'order', "`{$orderfield}`>{$order}" . (trim($clause) != '' ? ' AND ' . $clause : '')); if ($min == '') { return false; } $next = db_field_value($table, $idfield, "`{$orderfield}`={$min}" . (trim($clause) != '' ? ' AND ' . $clause : '')); if ($next == '') { return false; } return db_swap_values($table, $id, $next, $orderfield, $idfield); }