/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { if (!$query->isType(QueryInterface::TYPE_ALTER)) { return null; } return $this->getAlterChain()->getResult($query); }
/** * QueryDecorator constructor. * * @param QueryInterface $decoratedQuery * @throws Exception */ public function __construct(QueryInterface $decoratedQuery) { if (!$decoratedQuery->isType(static::TYPE)) { throw new Exception('Not a ' . static::TYPE . ' query.'); } $this->decoratedQuery = $decoratedQuery; }
/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { if (!$query->isType(QueryInterface::TYPE_CREATE)) { return null; } return $this->getCreateChain()->getResult($query); }
/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { if (!$query->isType(QueryInterface::TYPE_SELECT)) { return null; } return $this->getSelectChain()->getResult($query); }
/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { if (!$query instanceof ShowQuery || $query->getObject() !== ShowQuery::EXPRESSION_COLLATION) { return null; } return $this->getResultFromData(self::$data, self::$fields); }
/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { if (!$query instanceof AlterQuery || $query->getObject() !== AlterQuery::EXPRESSION_TABLE) { return null; } $command = new ApplySchema($query->getSql()); $this->client->executeCommand($command); return new EmptyResult(); }
/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { if (!$query instanceof ShowQuery || $query->getObject() !== ShowQuery::EXPRESSION_DATABASES) { return null; } $command = new GetKeyspaces(); /* @var $vtCtldResult GetKeyspacesResult */ $vtCtldResult = $this->client->executeCommand($command); return new Databases($vtCtldResult); }
/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { if (!$query instanceof ShowQuery || $query->getObject() !== ShowQuery::EXPRESSION_TABLES) { return null; } $tablet = $this->tablet->getTablet(); $command = new GetSchema($tablet->getAlias()); /* @var $vtCtldResult GetSchemaResult */ $vtCtldResult = $this->client->executeCommand($command); return new Tables($vtCtldResult); }
/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { if (!$query instanceof ShowQuery || $query->getObject() !== ShowQuery::EXPRESSION_CREATE_DATABASE) { return null; } $database = $query->getCreateObjectExpression(ShowQuery::EXPRESSION_CREATE_DATABASE); $newData = []; $newData[] = array_map(function ($row) use($database) { return str_replace('{DB}', $database, $row); }, self::$data); return $this->getResultFromData($newData, self::$fields); }
/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { /* @var $query SelectQuery */ if (!$query->isType(QueryInterface::TYPE_SELECT)) { return null; } $field = $query->getFirstField(); if ($field->getType() !== Expression::TYPE_FUNCTION || $field->getExpression() !== Expression::EXPR_USER) { return null; } return $this->getResultFromData(self::$data, self::$fields); }
/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { if (!$query->isType(QueryInterface::TYPE_USE)) { return null; } $query = new UseQuery($query); $keyspace = $query->getDbName(); $this->dsn->getConfig()->setKeyspace($keyspace); if ($this->client instanceof CachingClient) { $this->client->clearCache(); } return new EmptyResult(); }
/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { if (!$query instanceof ShowQuery || $query->getObject() !== ShowQuery::EXPRESSION_INDEX) { return null; } $fromExpr = $query->getFromExpression(); if (!$fromExpr) { throw new Exception('From expression missing.'); } $tablet = $this->tablet->getTablet(); $schemaCmd = new GetSchema($tablet->getAlias()); /* @var $result GetSchemaResult */ $result = $this->client->executeCommand($schemaCmd); return new IndexFrom($result, $fromExpr); }
/** * @param QueryInterface $query * * @return Result|null * @throws Exception */ public function process(QueryInterface $query) { if (!$query instanceof ShowQuery || $query->getObject() !== ShowQuery::EXPRESSION_CREATE_TABLE) { return null; } $table = $query->getCreateObjectExpression(ShowQuery::EXPRESSION_CREATE_TABLE); if (!$table) { throw new Exception('Table missing.'); } $tablet = $this->tablet->getTablet(); $schemaCmd = new GetSchema($tablet->getAlias()); /* @var $result GetSchemaResult */ $result = $this->client->executeCommand($schemaCmd); return new CreateTable($result, $table); }
/** * @param QueryInterface $query * @param array $params * * @return Result * @throws PDOException */ public function executeRead(QueryInterface $query, array $params = []) { $cursor = null; try { $reader = $this->connection; $tabletType = $this->clusterConfig->getReadFrom(); if ($this->isInTransaction()) { $reader = $this->getTransaction(); $tabletType = TabletType::MASTER; } $cursor = $reader->execute($this->ctx, $query->getSql(), $params, $tabletType); } catch (VitessException $e) { $this->handleException($e); return new Result(null, $e); } return new Result(new Cursor($cursor)); }