From 74eeaf3459e8ef779d198f8e6c386eeea48b296c Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 13 Dec 2021 15:20:58 +0900 Subject: [PATCH] Allow setting new charset in DB::modifyColumn() --- common/framework/db.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/common/framework/db.php b/common/framework/db.php index 79759080d..25a31e9c6 100644 --- a/common/framework/db.php +++ b/common/framework/db.php @@ -841,9 +841,10 @@ class DB * @param bool $notnull * @param string $after_column * @param string $new_name + * @param string $new_charset * @return BaseObject */ - public function modifyColumn(string $table_name, string $column_name, string $type = 'number', $size = null, $default = null, $notnull = false, $after_column = null, $new_name = null): \BaseObject + public function modifyColumn(string $table_name, string $column_name, string $type = 'number', $size = null, $default = null, $notnull = false, $after_column = null, $new_name = null, $new_charset = null): \BaseObject { // Normalize the type and size. list($type, $xetype, $size) = Parsers\DBTableParser::getTypeAndSize($type, strval($size)); @@ -858,6 +859,15 @@ class DB $query = sprintf("ALTER TABLE `%s` MODIFY `%s` ", $this->addQuotes($this->_prefix . $table_name), $this->addQuotes($column_name)); } $query .= $size ? sprintf('%s(%s)', $type, $size) : $type; + + // Add the character set information. + if (isset($new_charset)) + { + $new_collation = preg_match('/^utf8/i', $new_charset) ? ($new_charset . '_unicode_ci') : ($new_charset . '_general_ci'); + $query .= ' CHARACTER SET ' . $new_charset . ' COLLATE ' . $new_collation; + } + + // Add the NOT NULL constraint. $query .= $notnull ? ' NOT NULL' : ''; // Add the default value according to the type.