From 32c9de472a4055508e0eda38366817e12c4ea19d Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 5 Jul 2018 22:43:53 +0900 Subject: [PATCH] Improve addColumn() and modifyColumn() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 특정 컬럼 이후에 컬럼을 추가할 수 있도록 허용 - 모든 integer 타입의 size 속성을 무시 (tinyint 제외) --- classes/db/DBMysql.class.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/classes/db/DBMysql.class.php b/classes/db/DBMysql.class.php index a74ac3cff..2a12f94c9 100644 --- a/classes/db/DBMysql.class.php +++ b/classes/db/DBMysql.class.php @@ -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) {