Exemplo n.º 1
0
 public function convertSqlToJob(SQLTokenIterator $tokens)
 {
     $tokens->seekTokenNum(SqlToken::T_USE());
     if ($tokens->getCurrentTokenNumber() !== SqlToken::T_USE()) {
         throw new MalformedSqlException("Tried to parse USE statement when token-iterator does not point to T_USE!", $tokens);
     }
     if ($tokens->seekTokenNum(T_VARIABLE)) {
         $databaseName = Variable::factory($tokens->getCurrentTokenString());
     } elseif ($tokens->seekTokenNum(T_STRING)) {
         $databaseName = $tokens->getCurrentTokenString();
     } elseif ($tokens->seekTokenNum(T_CONSTANT_ENCAPSED_STRING)) {
         $databaseName = $tokens->getCurrentTokenString();
         if (($databaseName[0] === '"' || $databaseName[0] === "'") && $databaseName[0] === $databaseName[strlen($databaseName) - 1]) {
             // remove quotes if needed
             $databaseName = substr($databaseName, 1, strlen($databaseName) - 2);
         }
     } else {
         throw new MalformedSqlException("Missing database-specifier for USE statement!", $tokens);
     }
     $databaseNameValue = new ValuePart();
     $databaseNameValue->addChainValue($databaseName);
     $useJob = new UseStatement();
     $useJob->setDatabase($databaseNameValue);
     return $useJob;
 }
Exemplo n.º 2
0
 public function resolveValueJob(ValuePart $valueJob, ExecutionContext $context)
 {
     $chainValues = $valueJob->getChainValues();
     $value = null;
     foreach ($valueJob->getChainValues() as $chainValue) {
         if (is_null($value)) {
             $value = $chainValue;
             continue;
         }
         switch (true) {
             case $chainValue instanceof Like:
             case $chainValue instanceof Enum:
                 $chainValue->setCheckValue($value);
                 break;
             case $chainValue instanceof ConditionJob:
                 $chainValue->setFirstParameter($value);
                 break;
         }
         $value = $this->resolveValue($chainValue, $context);
     }
     return $this->resolveValue($value, $context);
 }
Exemplo n.º 3
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;
 }