當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Condition::setFirstParameter方法代碼示例

本文整理匯總了PHP中Condition::setFirstParameter方法的典型用法代碼示例。如果您正苦於以下問題:PHP Condition::setFirstParameter方法的具體用法?PHP Condition::setFirstParameter怎麽用?PHP Condition::setFirstParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Condition的用法示例。


在下文中一共展示了Condition::setFirstParameter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: convertSqlToJob

 public function convertSqlToJob(SQLTokenIterator $tokens, $from = TokenIterator::NEXT)
 {
     if (!$tokens->seekTokenText('(', $from)) {
         throw new ErrorException("Tried to parse sql-parenthesis when token-iterator does not point to paranthesis ('(' sign)!");
     }
     /* @var $parenthesis ParenthesisPart */
     $parenthesis = new ParenthesisPart();
     switch (true) {
         case $this->selectParser->canParseTokens($tokens):
             $parenthesis->setContain($this->selectParser->convertSqlToJob($tokens));
             break;
         case $this->valueParser->canParseTokens($tokens):
             $parenthesis->setContain($this->valueParser->convertSqlToJob($tokens));
             break;
     }
     if (!$tokens->seekTokenText(')')) {
         throw new MalformedSqlException("Missing ')' at the end of a parenthesis!", $tokens);
     }
     if ($tokens->seekTokenNum(T_STRING, TokenIterator::NEXT, [SqlToken::T_AS()])) {
         $parenthesis->setAlias($tokens->getCurrentTokenString());
     }
     if ($parenthesis->getContain() instanceof Select && $tokens->isTokenNum(SqlToken::T_UNION())) {
         $unionSelect = new Select();
         while ($tokens->seekTokenNum(SqlToken::T_UNION())) {
             /* @var $lastUnionedSelect Select */
             $lastUnionedSelect = $parenthesis->getContain();
             while (!is_null($lastUnionedSelect->getUnionSelect())) {
                 $lastUnionedSelect = $lastUnionedSelect->getUnionSelect();
             }
             $isUnionAll = $tokens->seekTokenNum(SqlToken::T_ALL());
             $isUnionDistinct = $tokens->seekTokenNum(SqlToken::T_DISTINCT());
             $isUnionAll = $isUnionAll || $tokens->seekTokenNum(SqlToken::T_ALL());
             if ($isUnionAll && $isUnionDistinct) {
                 throw new MalformedSqlException("UNION cannot be ALL and DISTINCT at the same time!", $tokens);
             }
             $isUnionInParenthesis = $tokens->seekTokenText('(');
             if (!$this->selectParser->canParseTokens($tokens)) {
                 throw new MalformedSqlException("Missing following SELECT statement after UNION in SELECT statement!", $tokens);
             }
             $lastUnionedSelect->setUnionSelect($this->selectParser->convertSqlToJob($tokens), $isUnionDistinct);
             if ($isUnionInParenthesis && !$tokens->seekTokenText(')')) {
                 throw new MalformedSqlException("Missing ending parenthesis after UNION in SELECT statement!", $tokens);
             }
         }
         $unionSelect->setUnionSelect($parenthesis->getContain());
         ### APPENDED CONDITION (HAVING)
         if ($tokens->seekTokenNum(SqlToken::T_HAVING())) {
             if (!$this->valueParser->canParseTokens($tokens)) {
                 throw new MalformedSqlException("Missing condition for WHERE clause in SELECT statement!", $tokens);
             }
             $condition = new Condition();
             $condition->setFirstParameter($this->valueParser->convertSqlToJob($tokens));
             $unionSelect->setResultFilter($condition);
         }
         ### ORDER
         if ($tokens->seekTokenNum(SqlToken::T_ORDER())) {
             if (!$tokens->seekTokenNum(SqlToken::T_BY())) {
                 throw new MalformedSqlException("Missing BY after ORDER on SELECT statement!", $tokens);
             }
             do {
                 if (!$this->valueParser->canParseTokens($tokens)) {
                     throw new MalformedSqlException("Missing value for ORDER BY part on SELECT statement!", $tokens);
                 }
                 $orderValue = $this->valueParser->convertSqlToJob($tokens);
                 if ($tokens->seekTokenNum(SqlToken::T_DESC())) {
                     $unionSelect->addOrderColumn($orderValue, SqlToken::T_DESC());
                 } else {
                     $tokens->seekTokenNum(SqlToken::T_ASC());
                     $unionSelect->addOrderColumn($orderValue, SqlToken::T_ASC());
                 }
             } while ($tokens->seekTokenText(','));
         }
         ### LIMIT
         if ($tokens->seekTokenNum(SqlToken::T_LIMIT())) {
             if (!$tokens->seekTokenNum(T_NUM_STRING)) {
                 throw new MalformedSqlException("Missing offset number for LIMIT part in SELECT statement!", $tokens);
             }
             $unionSelect->setLimitOffset((int) $tokens->getCurrentTokenString());
             if ($tokens->seekTokenText(',')) {
                 if (!$tokens->seekTokenNum(T_NUM_STRING)) {
                     throw new MalformedSqlException("Missing length number for LIMIT part in SELECT statement!", $tokens);
                 }
                 $unionSelect->setLimitRowCount((int) $tokens->getCurrentTokenString());
             }
         }
         $parenthesis->setContain($unionSelect);
     }
     return $parenthesis;
 }
開發者ID:addiks,項目名稱:phpsql,代碼行數:89,代碼來源:ParenthesisParser.php


注:本文中的Condition::setFirstParameter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。