本文整理汇总了PHP中CI_DB_forge::_alter_table方法的典型用法代码示例。如果您正苦于以下问题:PHP CI_DB_forge::_alter_table方法的具体用法?PHP CI_DB_forge::_alter_table怎么用?PHP CI_DB_forge::_alter_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CI_DB_forge
的用法示例。
在下文中一共展示了CI_DB_forge::_alter_table方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _alter_table
/**
* ALTER TABLE
*
* @param string $alter_type ALTER type
* @param string $table Table name
* @param mixed $field Column definition
* @return string|string[]
*/
protected function _alter_table($alter_type, $table, $field)
{
if ($alter_type === 'DROP') {
return parent::_alter_table($alter_type, $table, $field);
} elseif ($alter_type === 'CHANGE') {
$alter_type = 'MODIFY';
}
$sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
$sqls = array();
for ($i = 0, $c = count($field); $i < $c; $i++) {
if ($field[$i]['_literal'] !== FALSE) {
$field[$i] = "\n\t" . $field[$i]['_literal'];
} else {
$field[$i]['_literal'] = "\n\t" . $this->_process_column($field[$i]);
if ($alter_type === 'MODIFY' && !empty($field[$i]['new_name'])) {
$sqls[] = $sql . ' RENAME COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' ' . $this->db->escape_identifiers($field[$i]['new_name']);
}
}
}
$sql .= ' ' . $alter_type . ' ';
$sql .= count($field) === 1 ? $field[0] : '(' . implode(',', $field) . ')';
// RENAME COLUMN must be executed after MODIFY
array_unshift($sqls, $sql);
return $sql;
}
示例2: _alter_table
/**
* ALTER TABLE
*
* @param string $alter_type ALTER type
* @param string $table Table name
* @param mixed $field Column definition
* @return string|string[]
*/
protected function _alter_table($alter_type, $table, $field)
{
if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) {
return parent::_alter_table($alter_type, $table, $field);
}
$sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
$sqls = array();
for ($i = 0, $c = count($field); $i < $c; $i++) {
if ($field[$i]['_literal'] !== FALSE) {
return FALSE;
}
if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type'])) {
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' TYPE ' . $field[$i]['type'] . $field[$i]['length'];
}
if (!empty($field[$i]['default'])) {
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' SET DEFAULT ' . $field[$i]['default'];
}
if (isset($field[$i]['null'])) {
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
}
if (!empty($field[$i]['new_name'])) {
$sqls[] = $sql . ' RENAME COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' TO ' . $this->db->escape_identifiers($field[$i]['new_name']);
}
}
return $sqls;
}
示例3: _alter_table
/**
* ALTER TABLE
*
* @param string $alter_type ALTER type
* @param string $table Table name
* @param mixed $field Column definition
* @return string|string[]
*/
protected function _alter_table($alter_type, $table, $field)
{
if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) {
return parent::_alter_table($alter_type, $table, $field);
}
$sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table) . ' ALTER COLUMN ';
$sqls = array();
for ($i = 0, $c = count($field); $i < $c; $i++) {
$sqls[] = $sql . $this->_process_column($field[$i]);
}
return $sqls;
}
示例4: _alter_table
/**
* ALTER TABLE
*
* @param string $alter_type ALTER type
* @param string $table Table name
* @param mixed $field Column definition
* @return string|string[]
*/
protected function _alter_table($alter_type, $table, $field)
{
if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) {
return parent::_alter_table($alter_type, $table, $field);
}
$sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
$sqls = array();
for ($i = 0, $c = count($field); $i < $c; $i++) {
if ($field[$i]['_literal'] !== FALSE) {
$sqls[] = $sql . ' CHANGE ' . $field[$i]['_literal'];
} else {
$alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE ';
$sqls[] = $sql . $alter_type . $this->_process_column($field[$i]);
}
}
return $sqls;
}
示例5: _alter_table
/**
* ALTER TABLE
*
* @param string $alter_type ALTER type
* @param string $table Table name
* @param mixed $field Column definition
* @return string|string[]
*/
protected function _alter_table($alter_type, $table, $field)
{
if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) {
return parent::_alter_table($alter_type, $table, $field);
}
$sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
$sqls = array();
for ($i = 0, $c = count($field), $sql .= $alter_type . ' '; $i < $c; $i++) {
if ($field[$i]['_literal'] !== FALSE) {
return FALSE;
}
if (isset($field[$i]['type'])) {
$sqls[] = $sql . ' TYPE ' . $field[$i]['type'] . $field[$i]['length'];
}
if (!empty($field[$i]['default'])) {
$sqls[] = $sql . ' ALTER ' . $this->db->escape_identifiers($field[$i]['name']) . ' SET ' . $field[$i]['default'];
}
if (isset($field[$i]['null'])) {
$sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = ' . ($field[$i]['null'] === TRUE ? 'NULL' : '1') . ' WHERE "RDB$FIELD_NAME" = ' . $this->db->escape($field[$i]['name']) . ' AND "RDB$RELATION_NAME" = ' . $this->db->escape($table);
}
if (!empty($field[$i]['new_name'])) {
$sqls[] = $sql . ' ALTER ' . $this->db->escape_identifiers($field[$i]['name']) . ' TO ' . $this->db->escape_identifiers($field[$i]['new_name']);
}
}
return $sqls;
}
示例6: _alter_table
/**
* ALTER TABLE
*
* @todo implement drop_column(), modify_column()
* @param string $alter_type ALTER type
* @param string $table Table name
* @param mixed $field Column definition
* @return string|string[]
*/
protected function _alter_table($alter_type, $table, $field)
{
if ($alter_type === 'DROP' or $alter_type === 'CHANGE') {
// drop_column():
// BEGIN TRANSACTION;
// CREATE TEMPORARY TABLE t1_backup(a,b);
// INSERT INTO t1_backup SELECT a,b FROM t1;
// DROP TABLE t1;
// CREATE TABLE t1(a,b);
// INSERT INTO t1 SELECT a,b FROM t1_backup;
// DROP TABLE t1_backup;
// COMMIT;
return FALSE;
}
return parent::_alter_table($alter_type, $table, $field);
}
示例7: _alter_table
/**
* ALTER TABLE
*
* @param string $alter_type ALTER type
* @param string $table Table name
* @param mixed $field Column definition
* @return string|string[]
*/
protected function _alter_table($alter_type, $table, $field)
{
if ($alter_type === 'DROP') {
return parent::_alter_table($alter_type, $table, $field);
}
$sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
for ($i = 0, $c = count($field); $i < $c; $i++) {
if ($field[$i]['_literal'] !== FALSE) {
$field[$i] = $alter_type === 'ADD' ? "\n\tADD " . $field[$i]['_literal'] : "\n\tMODIFY " . $field[$i]['_literal'];
} else {
if ($alter_type === 'ADD') {
$field[$i]['_literal'] = "\n\tADD ";
} else {
$field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
}
$field[$i] = $field[$i]['_literal'] . $this->_process_column($field[$i]);
}
}
return array($sql . implode(',', $field));
}
示例8: _alter_table
/**
* ALTER TABLE.
*
* @param string $alter_type ALTER type
* @param string $table Table name
* @param mixed $field Column definition
*
* @return string|string[]
*/
protected function _alter_table($alter_type, $table, $field)
{
if (in_array($alter_type, ['DROP', 'ADD'], true)) {
return parent::_alter_table($alter_type, $table, $field);
}
$sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
$sqls = [];
for ($i = 0, $c = count($field); $i < $c; $i++) {
if ($field[$i]['_literal'] !== false) {
return false;
}
if (isset($field[$i]['type'])) {
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identififers($field[$i]['name']) . ' TYPE ' . $field[$i]['type'] . $field[$i]['length'];
}
if (!empty($field[$i]['default'])) {
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' SET DEFAULT ' . $field[$i]['default'];
}
if (isset($field[$i]['null'])) {
$sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = ' . ($field[$i]['null'] === true ? 'NULL' : '1') . ' WHERE "RDB$FIELD_NAME" = ' . $this->db->escape($field[$i]['name']) . ' AND "RDB$RELATION_NAME" = ' . $this->db->escape($table);
}
if (!empty($field[$i]['new_name'])) {
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' TO ' . $this->db->escape_identifiers($field[$i]['new_name']);
}
}
return $sqls;
}