本文整理汇总了PHP中Zend_Db_Adapter_Abstract::describeTable方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db_Adapter_Abstract::describeTable方法的具体用法?PHP Zend_Db_Adapter_Abstract::describeTable怎么用?PHP Zend_Db_Adapter_Abstract::describeTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Db_Adapter_Abstract
的用法示例。
在下文中一共展示了Zend_Db_Adapter_Abstract::describeTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param null $options
* @param bool $autoLoad
*/
public function __construct($options = null, $autoLoad = true)
{
$this->_db = Zend_Db_Table::getDefaultAdapter();
$this->_options = $options;
if (isset($options['blacklist']) && !isset($options['whitelist'])) {
if (is_array($options['blacklist'])) {
$this->_blackList = $options['blacklist'];
} else {
$this->_blackList[] = (string) $options['blacklist'];
}
} elseif (isset($options['whitelist']) && !empty($options['whitelist'])) {
if (is_array($options['whitelist'])) {
$this->_whiteList = $options['whitelist'];
} else {
$this->_whiteList[] = (string) $options['whitelist'];
}
}
if ($autoLoad) {
$tables = $this->_db->listTables();
foreach ($tables as $table) {
$scheme = $this->_db->describeTable($table);
$this->addTable($table, $scheme);
}
}
}
示例2: getTableDescription
/**
* Get Table information
*
* @param string $tableName
* @return array
*/
protected function getTableDescription($tableName)
{
if (!isset($this->_tableMetadata[$tableName])) {
$this->_tableMetadata[$tableName] = $this->_connection->describeTable($tableName);
}
return $this->_tableMetadata[$tableName];
}
示例3: _setupMetadata
/**
* Initializes metadata.
*
* If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata
* information. Returns true if and only if the metadata are loaded from cache.
*
* @return boolean
* @throws Kwf_Exception
*/
protected function _setupMetadata()
{
if (count($this->_metadata) > 0) {
return true;
}
// Assume that metadata will be loaded from cache
$isMetadataFromCache = true;
// Define the cache identifier where the metadata are saved
//get db configuration
$dbConfig = $this->_db->getConfig();
$port = isset($dbConfig['options']['port']) ? ':' . $dbConfig['options']['port'] : (isset($dbConfig['port']) ? ':' . $dbConfig['port'] : null);
$host = isset($dbConfig['options']['host']) ? ':' . $dbConfig['options']['host'] : (isset($dbConfig['host']) ? ':' . $dbConfig['host'] : null);
// Define the cache identifier where the metadata are saved
$cacheId = 'dbtbl_' . md5($port . $host . '/' . $dbConfig['dbname'] . ':' . $this->_schema . '.' . $this->_name);
// If $this has no metadata cache or metadata cache misses
if (!($metadata = Kwf_Cache_SimpleStatic::fetch($cacheId))) {
// Metadata are not loaded from cache
$isMetadataFromCache = false;
// Fetch metadata from the adapter's describeTable() method
$metadata = $this->_db->describeTable($this->_name, $this->_schema);
// If $this has a metadata cache, then cache the metadata
Kwf_Cache_SimpleStatic::add($cacheId, $metadata);
}
// Assign the metadata to $this
$this->_metadata = $metadata;
// Return whether the metadata were loaded from cache
return $isMetadataFromCache;
}
示例4: testDescribeTable
/**
* Test Adapter's describeTable() method.
* Retrieve the adapter's description of the test table and examine it.
*/
public function testDescribeTable()
{
$idKey = $this->getResultSetKey('id');
$bodyKey = $this->getResultSetKey('body');
$table = $this->getIdentifier(self::TABLE_NAME);
$desc = $this->_db->describeTable($table);
$this->assertThat($desc, $this->arrayHasKey($bodyKey));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('SCHEMA_NAME'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('TABLE_NAME'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('COLUMN_NAME'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('COLUMN_POSITION'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('DATA_TYPE'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('DEFAULT'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('NULLABLE'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('LENGTH'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('SCALE'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('PRECISION'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('UNSIGNED'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('PRIMARY'));
$this->assertThat($desc[$bodyKey], $this->arrayHasKey('PRIMARY_POSITION'));
$this->assertEquals($table, $desc[$bodyKey]['TABLE_NAME']);
$this->assertEquals($bodyKey, $desc[$bodyKey]['COLUMN_NAME']);
$this->assertEquals(4, $desc[$bodyKey]['COLUMN_POSITION']);
$this->assertEquals($this->_textDataType, $desc[$bodyKey]['DATA_TYPE']);
$this->assertEquals('', $desc[$bodyKey]['DEFAULT']);
$this->assertTrue($desc[$bodyKey]['NULLABLE']);
$this->assertEquals(0, $desc[$bodyKey]['SCALE']);
$this->assertEquals(0, $desc[$bodyKey]['PRECISION']);
$this->assertEquals('', $desc[$bodyKey]['PRIMARY']);
$this->assertEquals('', $desc[$bodyKey]['PRIMARY_POSITION']);
$this->assertTrue($desc[$idKey]['PRIMARY']);
$this->assertEquals(1, $desc[$idKey]['PRIMARY_POSITION']);
}
示例5: _setup
/**
* Populate static properties for this table module.
*
* @return void
* @throws Zend_Db_Table_Exception
*/
protected function _setup()
{
// get the database adapter
if (!$this->_db) {
$this->_db = self::getDefaultAdapter();
}
if (!$this->_db instanceof Zend_Db_Adapter_Abstract) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception('No object of type Zend_Db_Adapter_Abstract has been specified');
}
// get the table name
if (!$this->_name) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception('No table name has been specified');
}
// get the table columns
if (!$this->_cols) {
$desc = $this->_db->describeTable($this->_name);
$this->_cols = array_keys($desc);
}
// primary key
if ($this->_primary && array_intersect((array) $this->_primary, $this->_cols) !== (array) $this->_primary) {
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception("Primary key column(s) (" . implode(',', (array) $this->_primary) . ") are not columns in this table (" . implode(',', $this->_cols) . ")");
}
}
示例6: tableExists
/**
* checks if a given table exists
*
* @param string $_tableSchema
* @param string $_tableName
* @return boolean return true if the table exists, otherwise false
*/
public function tableExists($_tableName)
{
$tableName = SQL_TABLE_PREFIX . $_tableName;
try {
$tableInfo = $this->_db->describeTable($tableName);
} catch (Zend_Db_Statement_Exception $e) {
$tableInfo = null;
}
return !empty($tableInfo);
}
示例7: _alterEnumValues
/**
*
* @param array $enumValues
* @param boolean $reverse
*/
protected function _alterEnumValues(array $enumValues, $reverse = false)
{
foreach ($enumValues as $tableName => $fields) {
if ($this->_isTableExists($tableName)) {
$table = $this->_db->describeTable($tableName);
foreach ($fields as $fieldName => $fieldEnums) {
if (!isset($table[$fieldName])) {
continue;
}
preg_match('/^enum\\((.*)\\)$/', $table[$fieldName]['DATA_TYPE'], $matches);
foreach (explode(',', $matches[1]) as $value) {
$enums[] = trim($value, "'");
}
$newEnums = $enums;
if (isset($fieldEnums['add'])) {
if (!$reverse) {
foreach ($fieldEnums['add'] as $fieldEnum) {
$newEnums[] = $fieldEnum;
}
} else {
foreach ($fieldEnums['add'] as $fieldEnum) {
$this->_db->delete($tableName, $fieldName . ' = \'' . $fieldEnum . '\'');
}
$newEnums = array_diff($newEnums, $fieldEnums['add']);
}
$newEnums = array_unique($newEnums);
}
if (isset($fieldEnums['remove'])) {
if (!$reverse) {
foreach ($fieldEnums['remove'] as $fieldEnum) {
$this->_db->delete($tableName, $fieldName . ' = \'' . $fieldEnum . '\'');
}
$newEnums = array_diff($newEnums, $fieldEnums['remove']);
} else {
foreach ($fieldEnums['remove'] as $fieldEnum) {
$newEnums[] = $fieldEnum;
}
}
$newEnums = array_unique($newEnums);
}
sort($enums);
sort($newEnums);
if ($enums != $newEnums) {
foreach ($newEnums as &$value) {
$value = '\'' . $value . '\'';
}
$table[$fieldName]['DATA_TYPE'] = 'enum(' . implode(',', $newEnums) . ')';
$this->_alterTable($table[$fieldName]);
}
}
}
}
}
示例8: findPrimaryKey
/**
* Find PRIMARY KEY
* @param Zend_Db_Adapter_Abstract $db
* @param string $table
* @return array | boolean (false)
*/
public function findPrimaryKey(Zend_Db_Adapter_Abstract $db, $table)
{
$fields = $db->describeTable($table);
$primary = false;
foreach ($fields as $name => $info) {
if ($info['PRIMARY'] == 1) {
$primary = $info;
break;
}
}
return $primary;
}
示例9: hasSchema
/**
* Is the schema ready?
*
* @return bool
*/
public function hasSchema()
{
try {
$schema = $this->adapter->describeTable($this->tableName);
} catch (\Zend_Db_Statement_Exception $exception) {
return false;
} catch (\PDOException $exception) {
return false;
}
if (is_array($schema) && !empty($schema)) {
return true;
}
return false;
}
示例10: create
/**
*
* @param string $table
* @param string $adapter
* @param string $module
* @return void
* @throws Zend_Tool_Project_Exception
* @throws Exception
*/
public function create($table, $adapter, $module = null)
{
$name = ZendT_Tool_ModelTProvider::convertTableNameToClassName($table);
$this->_print(' Criando Models ');
$this->_print('name: ' . $name . ' | table: ' . $table . ' | adapter : ' . $adapter . ' | module: ' . $module);
$this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
$this->connect($this->_loadedProfile, $adapter);
// Check that there is not a dash or underscore, return if doesnt match regex
if (preg_match('#[_-]#', $name)) {
throw new Zend_Tool_Project_Provider_Exception('Form names should be camel cased.');
}
$originalName = $name;
$name = ucfirst($name);
if ($table == '') {
throw new Zend_Tool_Project_Provider_Exception('You must provide both the Form name as well as the actual db table\'s name.');
}
// get request/response object
$request = $this->_registry->getRequest();
$response = $this->_registry->getResponse();
// alert the user about inline converted names
$tense = $request->isPretend() ? 'would be' : 'is';
if ($name !== $originalName) {
$response->appendContent('Note: The canonical model name that ' . $tense . ' used with other providers is "' . $name . '";' . ' not "' . $originalName . '" as supplied', array('color' => array('yellow')));
}
/**
* Cria o DB Table
*/
try {
$formResources = Zend_Tool_Project_Provider_Form::createResource($this->_loadedProfile, $name, $module);
} catch (Exception $e) {
$response = $this->_registry->getResponse();
$response->setException($e);
return;
}
// do the creation
if ($request->isPretend()) {
$response->appendContent('Would create a Form at ' . $formResources->getContext()->getPath());
} else {
$response->appendContent('Creating a Form at ' . $formResources->getContext()->getPath());
$formResources->create();
$this->_storeProfile();
$fileName = $formResources->getContext()->getPath();
$formContext = new ZendT_Tool_Context_FormFile();
$descTable = $this->_dbAdapter->describeTable($originalName);
$formContext->setProperties($descTable);
file_put_contents($fileName, "<?php \n" . $formContext->getContents() . "\n?>");
}
$this->_print(' Finalizado Models ');
}
示例11: _setupMetadata
/**
* Initialize metadata.
* Call describeTable() to discover metadata information.
*
* @return void
* @throws Zend_Db_Table_Exception
*/
protected function _setupMetadata()
{
// @todo: support for caching the information from describeTable.
if (strpos($this->_name, '.')) {
list($schemaName, $tableName) = explode('.', $this->_name);
$this->_schema = $schemaName;
$this->_name = $tableName;
} else {
$schemaName = $this->_schema;
$tableName = $this->_name;
}
$this->_metadata = $this->_db->describeTable($tableName, $schemaName);
if (!$this->_cols) {
$this->_cols = array_keys($this->_metadata);
}
}
示例12: _setupMetadata
/**
* Initializes metadata.
*
* If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata
* information. Returns true if and only if the metadata are loaded from cache.
*
* @return boolean
* @throws Zend_Db_Table_Exception
*/
protected function _setupMetadata()
{
if (strpos($this->_name, '.')) {
list($schemaName, $tableName) = explode('.', $this->_name);
$this->_schema = $schemaName;
$this->_name = $tableName;
} else {
$schemaName = $this->_schema;
$tableName = $this->_name;
}
// Assume that metadata will be loaded from cache
$isMetadataFromCache = true;
// If $this has no metadata cache but the class has a default metadata cache
if (null === $this->_metadataCache && null !== self::$_defaultMetadataCache) {
// Make $this use the default metadata cache of the class
$this->_setMetadataCache(self::$_defaultMetadataCache);
}
// If $this has a metadata cache
if (null !== $this->_metadataCache) {
// Define the cache identifier where the metadata are saved
$cacheId = md5("{$schemaName}.{$tableName}");
}
// If $this has no metadata cache or metadata cache misses
if (null === $this->_metadataCache || !($metadata = $this->_metadataCache->load($cacheId))) {
// Metadata are not loaded from cache
$isMetadataFromCache = false;
// Fetch metadata from the adapter's describeTable() method
$metadata = $this->_db->describeTable($tableName, $schemaName);
// If $this has a metadata cache, then cache the metadata
if (null !== $this->_metadataCache && !$this->_metadataCache->save($metadata, $cacheId)) {
/**
* @see Zend_Db_Table_Exception
*/
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception('Failed saving metadata to metadataCache');
}
}
// Assign the metadata to $this
$this->_metadata = $metadata;
// Update the columns
$this->_cols = array_keys($this->_metadata);
// Return whether the metadata were loaded from cache
return $isMetadataFromCache;
}
示例13: loadSchemaFromDb
public static function loadSchemaFromDb(Zend_Db_Adapter_Abstract $db, Zend_Cache_Core $cache)
{
static $tables = array();
if (empty($tables)) {
if (!($tables = $cache->load('tables'))) {
$tables = $db->listTables();
$cache->save($tables, 'tables');
}
}
foreach ($tables as $table) {
if (!isset(self::$schema[$table])) {
if (!($tableStructure = $cache->load('tables_' . $table))) {
$tableStructure = $db->describeTable($table);
$cache->save($tableStructure, 'tables_' . $table);
}
self::$schema[$table] = $tableStructure;
}
}
}
示例14: _setup
/**
* Populate static properties for this table module.
*
* @return void
* @throws Zend_Db_Table_Exception
*/
protected function _setup($config = array())
{
// get the database adapter
if (!$this->_db) {
$this->_db = $this->_getDefaultAdapter();
}
if (!$this->_db instanceof Zend_Db_Adapter_Abstract) {
throw new Zend_Db_Table_Exception('db object does not extend Zend_Db_Adapter_Abstract');
}
// get the table name
if (isset($config['name'])) {
$this->_name = $config['name'];
}
if (!$this->_name) {
$this->_name = self::$_inflector->underscore(get_class($this));
}
// get the table columns
if (!$this->_cols) {
$tmp = array_keys($this->_db->describeTable($this->_name));
foreach ($tmp as $native) {
$this->_cols[$native] = self::$_inflector->camelize($native);
}
}
// primary key
if (isset($config['primary'])) {
$this->_primary = $config['primary'];
}
if (!$this->_primary) {
// none specified
$table = $this->_name;
throw new Zend_Db_Table_Exception("primary key not specified for table '{$table}'");
}
if (!array_key_exists($this->_primary, $this->_cols)) {
// wrong name
$key = $this->_primary;
$table = $this->_name;
throw new Zend_Db_Table_Exception("primary key '{$key}' not in columns for table '{$table}'");
}
}
示例15: create
/**
*
* @param string $table
* @param string $adapter
* @param string $module
* @return void
* @throws Zend_Tool_Project_Exception
* @throws Exception
*/
public function create($table, $adapter, $module = null)
{
$name = ZendT_Tool_ModelTProvider::convertTableNameToClassName($table);
$this->_print(' Criando Models ');
$this->_print('name: ' . $name . ' | table: ' . $table . ' | adapter : ' . $adapter . ' | module: ' . $module);
$this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
$applicationConfigResource = $this->_loadedProfile->search('ApplicationConfigFile');
if (!$applicationConfigResource) {
throw new Zend_Tool_Project_Exception('A project with an application config file is required to use this provider.');
}
$zf = $applicationConfigResource->getAsZendConfig();
$_configDb = $zf->resources->multidb->{$adapter};
if (!$_configDb) {
throw new Zend_Tool_Project_Exception('Adapter not found in config application "resources.multidb.' . $adapter . '" .');
}
$configDb = array();
$configDb['host'] = $_configDb->host;
$configDb['username'] = $_configDb->username;
$configDb['password'] = $_configDb->password;
$configDb['dbname'] = $_configDb->dbname;
$this->_dbAdapter = Zend_Db::factory($_configDb->adapter, $configDb);
$sql = "SELECT uccfk.column_name\n ,uccpk.table_name table_name_pk\n ,NULL object_name_pk\n ,uccpk.column_name column_name_pk\n FROM user_cons_columns uccfk\n ,user_constraints uc\n ,user_cons_columns uccpk\n WHERE uccfk.constraint_name = uc.constraint_name\n AND uc.r_constraint_name = uccpk.constraint_name\n AND uc.constraint_type = 'R'\n AND uccfk.table_name = '" . strtoupper($table) . "'";
$referenceMap = $this->_dbAdapter->fetchAll($sql);
foreach ($referenceMap as &$reference) {
$reference['OBJECT_NAME_PK'] = $this->getObjectName($reference['TABLE_NAME_PK']);
}
$sql = "SELECT distinct uccfk.TABLE_NAME\n FROM user_cons_columns uccfk\n ,user_constraints uc\n ,user_cons_columns uccpk\n WHERE uccfk.constraint_name = uc.constraint_name\n AND uc.r_constraint_name = uccpk.constraint_name\n AND uc.constraint_type = 'R'\n AND uccpk.table_name = '" . strtoupper($table) . "'";
$dependentTables = $this->_dbAdapter->fetchAll($sql);
foreach ($dependentTables as &$dependentTable) {
$dependentTable['OBJECT_NAME'] = $this->getObjectName($dependentTable['TABLE_NAME']);
}
// Check that there is not a dash or underscore, return if doesnt match regex
if (preg_match('#[_-]#', $name)) {
throw new Zend_Tool_Project_Provider_Exception('DbTable names should be camel cased.');
}
$originalName = $name;
$name = ucfirst($name);
if ($table == '') {
throw new Zend_Tool_Project_Provider_Exception('You must provide both the DbTable name as well as the actual db table\'s name.');
}
/*if (Zend_Tool_Project_Provider_DbTable::hasResource($this->_loadedProfile, $name, $module)) {
throw new Zend_Tool_Project_Provider_Exception('This project already has a DbTable named ' . $name);
}*/
// get request/response object
$request = $this->_registry->getRequest();
$response = $this->_registry->getResponse();
// alert the user about inline converted names
$tense = $request->isPretend() ? 'would be' : 'is';
if ($name !== $originalName) {
$response->appendContent('Note: The canonical model name that ' . $tense . ' used with other providers is "' . $name . '";' . ' not "' . $originalName . '" as supplied', array('color' => array('yellow')));
}
/**
* Cria o DB Table
*/
try {
$tableResource = Zend_Tool_Project_Provider_DbTable::createResource($this->_loadedProfile, $name, $table, $module);
} catch (Exception $e) {
$response = $this->_registry->getResponse();
$response->setException($e);
return;
}
// do the creation
if ($request->isPretend()) {
$response->appendContent('Would create a DbTable at ' . $tableResource->getContext()->getPath());
} else {
$response->appendContent('Creating a DbTable at ' . $tableResource->getContext()->getPath());
$tableResource->create();
$this->_storeProfile();
$fileName = $tableResource->getContext()->getPath();
$dbTableContext = new ZendT_Tool_Context_DbTableModelFile();
$this->_dbAdapter->describeTable($originalName);
$data = array();
$data['modelName'] = $name;
$data['moduleName'] = $module;
$data['tableName'] = $table;
$data['adapter'] = $adapter;
$data['referenceMap'] = $referenceMap;
$data['dependentTables'] = $dependentTables;
$dbTableContext->setProperties($data);
file_put_contents($fileName, "<?php \n" . $dbTableContext->getContents() . "\n?>");
/**
* Configura o nome do objeto dentro dos comentários
* da tabela
*/
$this->setObjectName($table, ZendT_Tool_ModelTProvider::convertTableNameToObjectName($module, $table));
}
/**
* Cria o Model
*/
try {
$modelResource = Zend_Tool_Project_Provider_Model::createResource($this->_loadedProfile, $name, $module);
//.........这里部分代码省略.........