本文整理汇总了PHP中DboSource::readTableParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP DboSource::readTableParameters方法的具体用法?PHP DboSource::readTableParameters怎么用?PHP DboSource::readTableParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DboSource
的用法示例。
在下文中一共展示了DboSource::readTableParameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReadTableParameters
/**
* testReadTableParameters method
*
* @access public
* @return void
*/
function testReadTableParameters()
{
$this->Dbo->cacheSources = $this->Dbo->testing = false;
$tableName = 'tinyint_' . uniqid();
$this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;');
$result = $this->Dbo->readTableParameters($tableName);
$this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName));
$expected = array('charset' => 'utf8', 'collate' => 'utf8_unicode_ci', 'engine' => 'InnoDB');
$this->assertEqual($result, $expected);
$this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;');
$result = $this->Dbo->readTableParameters($tableName);
$this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName));
$expected = array('charset' => 'cp1250', 'collate' => 'cp1250_general_ci', 'engine' => 'MyISAM');
$this->assertEqual($result, $expected);
}
示例2: _alterTable
/**
* Alter Table method
*
* @param string $type Type of operation to be done
* @param array $tables List of tables and fields
* @return bool Return true in case of success, otherwise false
* @throws MigrationException
*/
protected function _alterTable($type, $tables)
{
foreach ($tables as $table => $fields) {
$indexes = array();
if (isset($fields['indexes'])) {
$indexes = $fields['indexes'];
unset($fields['indexes']);
}
if ($type === 'drop') {
$this->_alterIndexes($indexes, $type, $table);
}
foreach ($fields as $field => $col) {
$model = new Model(array('table' => $table, 'ds' => $this->connection));
$tableFields = $this->db->describe($model);
$tableFields['indexes'] = $this->db->index($model);
$tableFields['tableParameters'] = $this->db->readTableParameters($this->db->fullTableName($model, false, false));
if ($type === 'drop') {
$field = $col;
}
if ($type === 'rename') {
$data = array('table' => $table, 'old_name' => $field, 'new_name' => $col);
} else {
$data = array('table' => $table, 'field' => $field);
}
$callbackData = $data;
if ($this->_invokePrecheck('beforeAction', $type . '_field', $data)) {
switch ($type) {
case 'add':
$sql = $this->db->alterSchema(array($table => array('add' => array($field => $col))));
break;
case 'drop':
$sql = $this->db->alterSchema(array($table => array('drop' => array($field => array()))));
break;
case 'change':
if (!isset($col['type']) || $col['type'] == $tableFields[$field]['type']) {
$def = array_merge($tableFields[$field], $col);
} else {
$def = $col;
}
if (!empty($def['length']) && !empty($col['type']) && (substr($col['type'], 0, 4) === 'date' || substr($col['type'], 0, 4) === 'time')) {
$def['length'] = null;
}
$sql = $this->db->alterSchema(array($table => array('change' => array($field => $def))));
break;
case 'rename':
$data = array();
if (array_key_exists($field, $tableFields)) {
$data = $tableFields[$field];
}
$sql = $this->db->alterSchema(array($table => array('change' => array($field => array_merge($data, array('name' => $col))))));
break;
}
if ($this->dry) {
$this->logQuery($sql);
continue;
}
$this->_invokeCallbacks('beforeAction', $type . '_field', $callbackData);
if (@$this->db->execute($sql) === false) {
throw new MigrationException($this, sprintf(__d('migrations', 'SQL Error: %s'), $this->db->error));
}
$this->_invokeCallbacks('afterAction', $type . '_field', $callbackData);
}
}
if ($type !== 'drop') {
$this->_alterIndexes($indexes, $type, $table);
}
}
return true;
}