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/mysqli | |
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/mysqli')
-rw-r--r-- | system/database/drivers/mysqli/mysqli_forge.php | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index d1e5e20ff..1a568ccd9 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -82,16 +82,34 @@ class CI_DB_mysqli_forge extends CI_DB_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; } // -------------------------------------------------------------------- |