/** * Get Query Builder object * * @return EloquentBuilder|QueryBuilder */ public function getBuilder() { if ($this->isQueryBuilder()) { return $this->query; } return $this->query->getQuery(); }
/** * @return \SQLQuery */ public function getQuery() { $query = parent::getQuery(); $query->setWhere(""); $query->setSelect("*"); $query->setFrom(sprintf("(%s) x", $this->getUnionedQuery())); return $query; }
$sum += $board->cells[$row][$j]; } echo "{$sum}\n"; } } class QueryBuilder { public static function getQuery($queryString) { $queryParts = explode(" ", $queryString); $command = array_shift($queryParts); $parameters = $queryParts; if ($command == "SetRow") { return new QuerySetRow($parameters); } if ($command == "SetCol") { return new QuerySetCol($parameters); } if ($command == "QueryRow") { return new QueryGetRow($parameters); } if ($command == "QueryCol") { return new QueryGetCol($parameters); } } } $board = new Board(); foreach (file($argv[1]) as $line) { $query = QueryBuilder::getQuery(trim($line)); $query->run($board); }
foreach ($this->fields as $field) { $select .= "`" . $this->alias('osoby_pozycje', $i) . "`.`" . $field . "` AS '" . $this->alias('osoby_pozycje', $i) . "." . $field . "', "; } if ($isLast) { $select = substr($select, 0, -2) . " "; } if (!$isFirst) { $joins .= "LEFT JOIN `" . $this->name('osoby_pozycje') . "` as `" . $this->alias('osoby_pozycje', $i) . "` ON (`" . $this->alias('osoby_pozycje', $i - 1) . "`.`pozycja_id` = `" . $this->alias('osoby_pozycje', $i) . "`.`pozycja_id` AND `" . $this->alias('osoby_pozycje', $i) . "`.`deleted` = '0') "; $joins .= "LEFT JOIN `" . $this->name('osoby') . "` as `" . $this->alias('osoby', $i) . "` ON (`" . $this->alias('osoby_pozycje', $i) . "`.`osoba_id` = `" . $this->alias('osoby', $i) . "`.`id`) "; } } elseif ($type == 'pozycje') { $select .= "`" . $this->alias('pozycje', $i) . "`.`id` AS '" . $this->alias('pozycje', $i) . ".id', "; $select .= "`" . $this->alias('pozycje', $i) . "`.`nazwa` AS '" . $this->alias('pozycje', $i) . ".nazwa'"; $select .= $isLast ? " " : ", "; $joins .= "LEFT JOIN `" . $this->name('osoby_pozycje') . "` as `" . $this->alias('osoby_pozycje', $i) . "` ON (`" . $this->alias('osoby_pozycje', $i - 1) . "`.`osoba_id` = `" . $this->alias('osoby_pozycje', $i) . "`.`osoba_id` AND `" . $this->alias('osoby_pozycje', $i) . "`.`deleted` = '0') "; $joins .= "LEFT JOIN `" . $this->name('pozycje') . "` as `" . $this->alias('pozycje', $i) . "` ON (`" . $this->alias('osoby_pozycje', $i) . "`.`pozycja_id` = `" . $this->alias('pozycje', $i) . "`.`id`) "; } } $this->query = $select . $from . $joins . $where; } public function getQuery() { return $this->query; } } $depth = 3; $queryBuilder = new QueryBuilder($depth, $id); $query = $queryBuilder->getQuery(); $results = $this->DB->selectAssocs($query); $treeBuilder = new TreeBuilder($results, $id, $depth); return $treeBuilder->getData();
/** * @return Doctrine\ORM\Query */ public function getQuery() { return $this->data_source->getQuery(); }
if (!$peregrine->post->isEmpty('before')) { $timeInput = $peregrine->post->getQueryString('before'); if (strpos($timeInput, '-') !== FALSE) { $beforeDate = strtotime($peregrine->post->getDate('before', 'Y-m-d H:i:s')); } else { $timeAgo = $prism->getTimestampFromString($peregrine->post->getAlnum('before')); if (!empty($timeAgo)) { $beforeDate = strtotime(implode(" ", $timeAgo) . " ago"); } } if (!empty($beforeDate)) { $qb->where('d.epoch >= "' . $beforeDate . '"'); } } // set a hash of the conditions, to know if the result count has changed $sql_hash = sha1($qb->getQuery()); // Count total records // This is much faster than using SQL_CALC_FOUND_ROWS if ($sql_hash != $peregrine->session->getAlnum('sql_conditions_hash')) { $total_results = 0; if (!defined('WEB_UI_DEBUG') || defined('WEB_UI_DEBUG') && !WEB_UI_DEBUG) { $total_qb = clone $qb; $total_qb->select('COUNT(*)'); $statement = $db->query($total_qb->getQuery()); while ($row = $statement->fetch()) { $total_results = $row[0]; } } $_SESSION['sql_conditions_hash'] = $sql_hash; $_SESSION['last_query_total_results'] = $total_results; $peregrine->refreshCage('session');