Exemplo n.º 1
0
 public function parsePlainValue(SQLTokenIterator $tokens, ValueJob $valueJob)
 {
     switch (true) {
         case $tokens->seekTokenNum(T_NUM_STRING):
             $valueJob->addChainValue((double) $tokens->getCurrentTokenString());
             break;
         case $tokens->seekTokenNum(T_CONSTANT_ENCAPSED_STRING):
             $string = $tokens->getCurrentTokenString();
             if (($string[0] === '"' || $string[0] === "'") && $string[0] === $string[strlen($string) - 1]) {
                 // remove quotes if needed
                 $string = substr($string, 1, strlen($string) - 2);
             }
             $valueJob->addChainValue($string);
             break;
         case $tokens->seekTokenNum(T_VARIABLE):
             $variableString = $tokens->getCurrentTokenString();
             $variable = Variable::factory($variableString);
             if ($variableString === '?') {
                 $variable->setIndex($tokens->countTokenOccourences(T_VARIABLE, 0, $tokens->getIndex() - 1));
             }
             $valueJob->addChainValue($variable);
             break;
         case $this->parenthesisParser->canParseTokens($tokens):
             $valueJob->addChainValue($this->parenthesisParser->convertSqlToJob($tokens));
             break;
         case $this->functionParser->canParseTokens($tokens):
             $valueJob->addChainValue($this->functionParser->convertSqlToJob($tokens));
             break;
         case $this->columnParser->canParseTokens($tokens):
             $valueJob->addChainValue($this->columnParser->convertSqlToJob($tokens));
             break;
         case $this->caseParser->canParseTokens($tokens):
             $valueJob->addChainValue($this->caseParser->convertSqlToJob($tokens));
             break;
         case $tokens->seekTokenNum(SqlToken::T_DEFAULT()):
         case $tokens->seekTokenNum(SqlToken::T_NULL()):
         case $tokens->seekTokenNum(SqlToken::T_FALSE()):
         case $tokens->seekTokenNum(SqlToken::T_TRUE()):
         case $tokens->seekTokenNum(SqlToken::T_CURRENT_TIMESTAMP()):
         case $tokens->seekTokenNum(SqlToken::T_CURRENT_DATE()):
         case $tokens->seekTokenNum(SqlToken::T_CURRENT_TIME()):
         case $tokens->seekTokenNum(SqlToken::T_CURRENT_USER()):
             $valueJob->addChainValue($tokens->getCurrentTokenNumber());
             break;
         default:
             return false;
     }
     return true;
 }