Example #1
0
 protected function executeShowTables(ShowJob $statement, array $parameters = array())
 {
     $result = new TemporaryResult(['TABLE']);
     $schemaId = $statement->getDatabase();
     $schema = $this->schemaManager->getSchema($schemaId);
     $list = $schema->listTables();
     sort($list);
     foreach ($list as $tableName) {
         $result->addRow([$tableName]);
     }
     return $result;
 }
Example #2
0
 public function convertSqlToJob(SQLTokenIterator $tokens)
 {
     /* @var $valueParser ValueParser */
     $valueParser = $this->valueParser;
     $tokens->seekTokenNum(SqlToken::T_SHOW());
     if ($tokens->getCurrentTokenNumber() !== SqlToken::T_SHOW()) {
         throw new ErrorException("Tried to convert sql-show to job-entity when tokeniterator does not point to T_SHOW!");
     }
     $showJob = new ShowStatement();
     if ($tokens->seekTokenNum(SqlToken::T_FULL())) {
         $showJob->setIsFull(true);
     }
     switch (true) {
         case $tokens->seekTokenNum(SqlToken::T_DATABASES()):
             $showJob->setType(ShowType::DATABASES());
             break;
         case $tokens->seekTokenNum(SqlToken::T_TABLES()):
             $showJob->setType(ShowType::TABLES());
             break;
         case $tokens->seekTokenNum(SqlToken::T_VIEWS()):
             $showJob->setType(ShowType::VIEWS());
             break;
         default:
             throw new MalformedSqlException("Invalid parameter for show-statement!", $tokens);
     }
     if ($tokens->seekTokenNum(SqlToken::T_FROM())) {
         if (!$tokens->seekTokenNum(T_STRING)) {
             throw new MalformedSqlException("Missing database name after FROM in SHOW statement!");
         }
         $showJob->setDatabase($tokens->getCurrentTokenString());
     }
     if ($tokens->seekTokenNum(SqlToken::T_WHERE())) {
         if (!$valueParser->canParseTokens($tokens)) {
             throw new MalformedSqlException("Missing valid condition-value after WHERE in SHOW statement!");
         }
         /* @var $conditionValue ValuePart */
         $conditionValue = $valueParser->convertSqlToJob($tokens);
         $showJob->setConditionValue($conditionValue);
     }
     return $showJob;
 }