/** * Get the list of tables available in the current connection. * * @return array The list of tables in the connected database/schema. */ public function listTables() { list($sql, $params) = $this->_dialect->listTablesSql($this->_connection->config()); $result = []; $statement = $this->_connection->execute($sql, $params); while ($row = $statement->fetch()) { $result[] = $row[0]; } $statement->closeCursor(); return $result; }
/** * Helper method for running each step of the reflection process. * * @param \CakeDC\OracleDriver\Database\Schema\Method $method Object with method metadata. * @param string $name The table name. * @param array $config The config data. * @return void * @throws \Cake\Database\Exception on query failure. */ protected function _reflect($method, $name, $config) { list($sql, $params) = $this->_dialect->describeParametersSql($name, $config); if (empty($sql)) { return; } try { $statement = $this->_connection->execute($sql, $params); } catch (PDOException $e) { throw new Exception($e->getMessage(), 500, $e); } foreach ($statement->fetchAll('assoc') as $row) { $this->_dialect->convertParametersDescription($method, $row); } $statement->closeCursor(); }
/** * Get the column metadata for a table. * * Caching will be applied if `cacheMetadata` key is present in the Connection * configuration options. Defaults to _cake_model_ when true. * * @param string $name The name of the table to describe. * @return \Cake\Database\Schema\Table Object with column metadata. * @throws \Cake\Database\Exception when table cannot be described. */ public function describe($name) { $cacheConfig = $this->cacheMetadata(); if ($cacheConfig) { $cacheKey = $this->_connection->configName() . '_' . $name; $cached = Cache::read($cacheKey, $cacheConfig); if ($cached !== false) { return $cached; } } $config = $this->_connection->config(); list($sql, $params) = $this->_dialect->describeTableSql($name, $config); $statement = $this->_executeSql($sql, $params); if (count($statement) === 0) { throw new Exception(sprintf('Cannot describe %s. It has 0 columns.', $name)); } $table = new Table($name); foreach ($statement->fetchAll('assoc') as $row) { $this->_dialect->convertFieldDescription($table, $row); } list($sql, $params) = $this->_dialect->describeIndexSql($name, $config); $statement = $this->_executeSql($sql, $params); foreach ($statement->fetchAll('assoc') as $row) { $this->_dialect->convertIndexDescription($table, $row); } list($sql, $params) = $this->_dialect->describeForeignKeySql($name, $config); $statement = $this->_executeSql($sql, $params); foreach ($statement->fetchAll('assoc') as $row) { $this->_dialect->convertForeignKeyDescription($table, $row); } $statement->closeCursor(); if (!empty($cacheConfig)) { Cache::write($cacheKey, $table, $cacheConfig); } return $table; }
/** * {@inheritDoc} */ protected function _foreignOnClause($on) { $parent = parent::_foreignOnClause($on); return $parent === 'RESTRICT' ? parent::_foreignOnClause(Table::ACTION_SET_NULL) : $parent; }