public function getMysql() { if (!$this->isValid()) { throw CompilerException::invalidSelect(); } $mysql = $this->getColumns() . $this->getTables() . $this->getWhereClause() . $this->getOrderByClause() . $this->getLimitClause(); return rtrim($mysql, "\n"); }
public function getMysql() { if (!$this->isValid()) { throw CompilerException::invalidInsert(); } $mysql = "INSERT\n" . $this->getTables() . $this->getColumnValuePairs(); return rtrim($mysql, "\n"); }
public function getMysql() { if (!$this->isValid()) { throw CompilerException::invalidUpdate(); } $mysql = "UPDATE\n" . $this->getTables() . $this->getColumnValuePairs() . $this->getWhereClause() . $this->getOrderByClause() . $this->getLimitClause(); return rtrim($mysql, "\n"); }
public function getTable($id) { $name = array_search($id, $this->tables, true); if (!is_string($name)) { throw CompilerException::badTableId($id); } if (0 < $id) { list(, $name) = json_decode($name); } return $name; }
protected function getOptionalFilterFunction() { if (!self::scanFunction(reset($this->request), $name, $arguments)) { return false; } if ($name !== 'filter') { return false; } if (!isset($arguments) || count($arguments) === 0) { throw CompilerException::noFilterArguments($this->request); } if (!$this->getExpression($arguments[0], self::$IS_REQUIRED, $where, $type)) { throw CompilerException::badFilterExpression($this->context, $arguments[0]); } $this->mysql->setWhere($where); array_shift($this->request); return true; }
protected function readInsert() { if (!self::scanFunction($this->request, $name, $arguments)) { return false; } if ($name !== 'insert') { return false; } if (!isset($arguments) || count($arguments) !== 1) { throw CompilerException::badInsertArgument($this->request); } $this->request = reset($arguments); // should have just one argument if (!isset($this->request) || count($this->request) !== 1) { throw CompilerException::badInsertArgument($this->request); } $this->request = reset($this->request); // ...which should not be an array if (!$this->readList()) { throw CompilerException::badInsertArgument($this->request); } return true; }
private function getOptionalSliceFunction() { if (!self::scanFunction(reset($this->request), $name, $arguments)) { return false; } if ($name !== 'slice') { return false; } // at this point, we're sure they want to slice if (!isset($arguments) || count($arguments) !== 2) { throw CompilerException::badSliceArguments($this->request); } if (!$this->scanParameter($arguments[0], $nameA) || !$this->scanParameter($arguments[1], $nameB)) { return false; } if (!$this->getSubtractiveParameters($nameA, $nameB, $start, $end)) { return false; } $this->mysql->setLimit($start, $end); array_shift($this->request); return true; }
private static function getQueryType($request, &$topLevelFunction) { if (isset($request) && count($request) >= 1) { $firstToken = reset($request); if (count($firstToken) >= 3) { list($tokenType, $functionName, ) = $firstToken; if ($tokenType === Parser::TYPE_FUNCTION) { $topLevelFunction = $functionName; switch ($functionName) { case 'get': case 'count': case 'average': case 'sum': case 'min': case 'max': return self::$TYPE_GET; case 'delete': return self::$TYPE_DELETE; case 'set': return self::$TYPE_SET; case 'insert': return self::$TYPE_INSERT; } } } } $topLevelFunction = null; throw CompilerException::unknownRequestType($request); }
private static function getTypeCast($type) { switch ($type) { case self::TYPE_BOOLEAN: return '(boolean)'; case self::TYPE_INTEGER: return '(integer)'; case self::TYPE_FLOAT: return '(float)'; case self::TYPE_STRING: return ''; default: throw CompilerException::unknownTypecast($type); } }