/** * Analyze the given query, producing a semantic representation of the most important elements * as well as related schema information. * * @param \DataBundle\Connection $connection * @param type $db * @param type $query * @return QueryAnalysis */ public function analyzeQuery(Connection $connection, $db, $query) { $driver = $this->drivers->getDriver($connection->getType()); $analysis = $driver->analyzeQuery($query); $model = new QueryAnalysis(); $model->setValid($analysis->valid); if (!$analysis->valid) { return $model; } $selection = array(); if (isset($analysis->selection)) { foreach ($analysis->selection as $select) { $selection[] = new QuerySelection($select->column, $select->alias); } } $model->setSelection($selection); // Fetch the schemas $froms = array(); if (isset($analysis->from)) { foreach ($analysis->from as $source) { $from = new QuerySource(); $from->setName($source->name); $from->setColumns($this->schema->getTableSchema($connection, $db, $source->name)); $froms[] = $from; } } $model->setFrom($froms); return $model; }
/** * Get detailed information about the given table. * @REST\Post("/connections/{id}/schema/dbs/{db}/tables/{tableName}/columns") */ public function getTableColumns($id, $db, $tableName, Request $request) { $details = json_decode($request->getContent()); $key = $request->request->get('key'); $connection = $this->connections->getConnection($id); if (!$connection) { return new Response('{"message":"No such connection"}', 404); } if (!$connection->unlock($key)) { return new Response('{"message":"Invalid key"}', 400); } return $this->schema->getTableSchema($connection, $db, $tableName); }