diff options
author | Andrey Andreev <narf@devilix.net> | 2014-01-21 22:37:15 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2014-01-21 22:37:15 +0100 |
commit | 1a9a4dc55112d264a61e1c50cf52733c993e0e52 (patch) | |
tree | cce9623d55d0057445d6f7d0f4bd6c021969847b /system/database/DB_forge.php | |
parent | ba8bf563095657b8b6104ecc3d3a990f3e6ceb75 (diff) | |
parent | 27f798b9d64025fecaaecbd80a8cba41d455940f (diff) |
Merge branch 'feature/dbforge_table_attributes' into develop
Diffstat (limited to 'system/database/DB_forge.php')
-rw-r--r-- | system/database/DB_forge.php | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 1cebb189c..fc4a9230f 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -314,9 +314,10 @@ abstract class CI_DB_forge { * * @param string $table Table name * @param bool $if_not_exists Whether to add IF NOT EXISTS condition + * @param array $attributes Associative array of table attributes * @return bool */ - public function create_table($table = '', $if_not_exists = FALSE) + public function create_table($table = '', $if_not_exists = FALSE, array $attributes = array()) { if ($table === '') { @@ -332,7 +333,7 @@ abstract class CI_DB_forge { show_error('Field information is required.'); } - $sql = $this->_create_table($table, $if_not_exists); + $sql = $this->_create_table($table, $if_not_exists, $attributes); if (is_bool($sql)) { @@ -368,9 +369,10 @@ abstract class CI_DB_forge { * * @param string $table Table name * @param bool $if_not_exists Whether to add 'IF NOT EXISTS' condition + * @param array $attributes Associative array of table attributes * @return mixed */ - protected function _create_table($table, $if_not_exists) + protected function _create_table($table, $if_not_exists, $attributes) { if ($if_not_exists === TRUE && $this->_create_table_if === FALSE) { @@ -406,10 +408,11 @@ abstract class CI_DB_forge { } // _create_table will usually have the following format: "%s %s (%s\n)" - $sql = sprintf($this->_create_table.';', + $sql = sprintf($this->_create_table.'%s;', $sql, $this->db->escape_identifiers($table), - $columns + $columns, + $this->_create_table_attr($attributes) ); return $sql; @@ -418,6 +421,29 @@ abstract class CI_DB_forge { // -------------------------------------------------------------------- /** + * CREATE TABLE attributes + * + * @param array $attributes Associative array of table attributes + * @return string + */ + protected function _create_table_attr($attributes) + { + $sql = ''; + + foreach (array_keys($attributes) as $key) + { + if (is_string($key)) + { + $sql .= ' '.strtoupper($key).' '.$attributes[$key]; + } + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** * Drop Table * * @param string $table_name Table name |