mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Improve addColumn() and modifyColumn()
- 특정 컬럼 이후에 컬럼을 추가할 수 있도록 허용 - 모든 integer 타입의 size 속성을 무시 (tinyint 제외)
This commit is contained in:
parent
35b73eec0b
commit
32c9de472a
1 changed files with 12 additions and 6 deletions
|
|
@ -467,10 +467,11 @@ class DBMySQL extends DB
|
|||
* @param boolean $notnull not null status, default value is false
|
||||
* @return void
|
||||
*/
|
||||
function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = null, $notnull = false)
|
||||
function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = null, $notnull = false, $after = null)
|
||||
{
|
||||
$type = $this->column_type[$type];
|
||||
if(strtoupper($type) == 'INTEGER')
|
||||
$type = strtolower($type);
|
||||
$type = isset($this->column_type[$type]) ? $this->column_type[$type] : $type;
|
||||
if(in_array($type, ['integer', 'int', 'bigint', 'smallint']))
|
||||
{
|
||||
$size = '';
|
||||
}
|
||||
|
|
@ -492,6 +493,10 @@ class DBMySQL extends DB
|
|||
{
|
||||
$query .= " NOT NULL ";
|
||||
}
|
||||
if($after_column)
|
||||
{
|
||||
$query .= sprintf(" AFTER `%s` ", $after_column);
|
||||
}
|
||||
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
|
@ -520,12 +525,13 @@ class DBMySQL extends DB
|
|||
*/
|
||||
function modifyColumn($table_name, $column_name, $type = 'number', $size = '', $default = '', $notnull = false)
|
||||
{
|
||||
$type = $this->column_type[$type];
|
||||
if(strtoupper($type) == 'INTEGER')
|
||||
$type = strtolower($type);
|
||||
$type = isset($this->column_type[$type]) ? $this->column_type[$type] : $type;
|
||||
if(in_array($type, ['integer', 'int', 'bigint', 'smallint']))
|
||||
{
|
||||
$size = '';
|
||||
}
|
||||
|
||||
|
||||
$query = sprintf("ALTER TABLE `%s%s` MODIFY `%s` ", $this->prefix, $table_name, $column_name);
|
||||
if($size)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue