/** * @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); } } }
/** * Fetch the schema version of the current database * * @return string */ public final function getSchemaVersion() { if (!in_array('schema_info', $this->dbAdapter->listTables())) { $this->createTable('schema_info', array('primary' => false), array(array('version', 'string'))); $this->dbAdapter->insert('schema_info', array('version' => '00000000000000')); return '00000000000000'; } return $this->dbAdapter->fetchOne($this->dbAdapter->select()->from('schema_info', 'version')->limit(1)); }
/** * * @param string $tableName * @return boolean */ protected final function _isTableExists($tableName) { if (!self::$_tablesList) { self::$_tablesList = array_map('strtolower', $this->_db->listTables()); } return in_array(strtolower($tableName), self::$_tablesList); }
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; } } }
/** * List Tables * * @return array */ public function getTableNames() { return $this->_connection->listTables(); }
public function indexAction() { $this->view->tables = $this->_db->listTables(); }
/** * Returns a list of the tables in the database. * * @return array */ public function listTables() { return $this->_adapter->listTables(); }
/** * Retrieve table list * * @return array */ public function getTables() { return $this->_read->listTables(); }
/** * Test the Adapter's listTables() method. * Fetch the list of tables and verify that the test table exists in * the list. */ public function testListTables() { $table = $this->getIdentifier(self::TABLE_NAME); $tables = $this->_db->listTables(); $this->assertContains($table, $tables); }
/** * Drop database tables. * * @param Zend_Db_Adapter_Abstract $db * @param string $dbType * @throws Zend_Exception */ function dropTables($db, $dbType) { $db->beginTransaction(); try { $tables = $db->listTables(); foreach ($tables as $table) { if ($dbType === 'mysql') { $db->query('DROP TABLE IF EXISTS `' . $table . '` CASCADE;'); } elseif ($dbType === 'pgsql') { $db->query('DROP TABLE IF EXISTS "' . $table . '" CASCADE;'); } elseif ($dbType === 'sqlite' && $table != 'sqlite_sequence') { $db->query('DROP TABLE IF EXISTS "' . $table . '";'); } else { continue; } } $db->commit(); } catch (Zend_Exception $exception) { $db->rollBack(); throw $exception; } }