diff options
author | Andrey Andreev <narf@devilix.net> | 2014-01-20 17:19:13 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2014-01-20 17:19:13 +0100 |
commit | 27f798b9d64025fecaaecbd80a8cba41d455940f (patch) | |
tree | c0f19d7dc6bab73157513a4b7efff3af9bfbf75f /system/database/drivers/pdo | |
parent | 4d0571666d03511ac5b4a1f2a6882ccb1509a209 (diff) |
Add support for optional table attributes to CI_DB_forge::create_table()
Supersedes PRs #989, #2776
Related issue: #41
Diffstat (limited to 'system/database/drivers/pdo')
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php index 74689d91e..3ac98e6c3 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php @@ -96,16 +96,34 @@ class CI_DB_pdo_mysql_forge extends CI_DB_pdo_forge { // -------------------------------------------------------------------- /** - * Class constructor + * CREATE TABLE attributes * - * @param object &$db Database object - * @return void + * @param array $attributes Associative array of table attributes + * @return string */ - public function __construct(&$db) + protected function _create_table_attr($attributes) { - parent::__construct($db); + $sql = ''; + + foreach (array_keys($attributes) as $key) + { + if (is_string($key)) + { + $sql .= ' '.strtoupper($key).' = '.$attributes[$key]; + } + } - $this->_create_table .= ' DEFAULT CHARSET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat; + if ( ! empty($this->db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET')) + { + $sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set; + } + + if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE')) + { + $sql .= ' COLLATE = '.$this->db->dbcollat; + } + + return $sql; } // -------------------------------------------------------------------- |