From 24fbc61e4a46c1e9f185c36629960dce0bad71e2 Mon Sep 17 00:00:00 2001 From: Zachary Flower Date: Sun, 2 Nov 2014 21:50:15 -0700 Subject: Add support for the COMMENT field in DBForge and MySQL Forge classes (pdo, mysql, and mysqli) Signed-off-by: Zachary Flower --- system/database/DB_forge.php | 30 ++++++++++++++++++++++ system/database/drivers/mysql/mysql_forge.php | 1 + system/database/drivers/mysqli/mysqli_forge.php | 1 + .../drivers/pdo/subdrivers/pdo_mysql_forge.php | 1 + 4 files changed, 33 insertions(+) diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index aa8bbbe3f..df3b90be6 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -156,6 +156,13 @@ abstract class CI_DB_forge { */ protected $_default = ' DEFAULT '; + /** + * COMMENT value representation in CREATE/ALTER TABLE statements + * + * @var string + */ + protected $_comment = ' COMMENT '; + // -------------------------------------------------------------------- /** @@ -849,6 +856,7 @@ abstract class CI_DB_forge { .$field['default'] .$field['null'] .$field['auto_increment'] + .$field['comment'] .$field['unique']; } @@ -986,6 +994,28 @@ abstract class CI_DB_forge { // -------------------------------------------------------------------- + /** + * Field attribute COMMENT + * + * @param array &$attributes + * @param array &$field + * @return void + */ + protected function _attr_comment(&$attributes, &$field) + { + if ($this->_comment === FALSE) + { + return; + } + + if (!empty($attributes['COMMENT'])) + { + $field['comment'] = $this->_default.$this->db->escape($attributes['COMMENT']); + } + } + + // -------------------------------------------------------------------- + /** * Process primary keys * diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 6f0d6c5e2..7053fa11d 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -192,6 +192,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { .$field['null'] .$field['default'] .$field['auto_increment'] + .$field['comment'] .$field['unique'] .$extra_clause; } diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index c9a5b6db7..c92d22264 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -194,6 +194,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge { .$field['null'] .$field['default'] .$field['auto_increment'] + .$field['comment'] .$field['unique'] .$extra_clause; } diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php index 6cdfcabb5..85b6ebe84 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php @@ -206,6 +206,7 @@ class CI_DB_pdo_mysql_forge extends CI_DB_pdo_forge { .$field['null'] .$field['default'] .$field['auto_increment'] + .$field['comment'] .$field['unique'] .$extra_clause; } -- cgit v1.2.3-24-g4f1b