From 5d69a6e8e096faa99fb838dabd7fe548213b0f26 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 28 Oct 2013 15:34:47 +0200 Subject: Fix #2703 --- system/database/DB_forge.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'system/database/DB_forge.php') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index d52029ecd..f156d24eb 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -740,6 +740,18 @@ abstract class CI_DB_forge { '_literal' => FALSE ); + if ($create_table === FALSE) + { + if (isset($attributes['AFTER'])) + { + $field['after'] = $attributes['after']; + } + elseif (isset($attributes['FIRST'])) + { + $field['first'] = (bool) $attributes['FIRST']; + } + } + $this->_attr_default($attributes, $field); if (isset($attributes['NULL'])) @@ -748,11 +760,15 @@ abstract class CI_DB_forge { { $field['null'] = empty($this->_null) ? '' : ' '.$this->_null; } - elseif ($create_table === TRUE) + else { $field['null'] = ' NOT NULL'; } } + elseif ($create_table === TRUE) + { + $field['null'] = ' NOT NULL'; + } $this->_attr_auto_increment($attributes, $field); $this->_attr_unique($attributes, $field); -- cgit v1.2.3-24-g4f1b From 96185a3a0edcc27fa0af6df761d6353a2208ea9d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 28 Oct 2013 16:04:02 +0200 Subject: Really fix #2703 --- system/database/DB_forge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/DB_forge.php') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index f156d24eb..92806d305 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -744,7 +744,7 @@ abstract class CI_DB_forge { { if (isset($attributes['AFTER'])) { - $field['after'] = $attributes['after']; + $field['after'] = $attributes['AFTER']; } elseif (isset($attributes['FIRST'])) { -- cgit v1.2.3-24-g4f1b From 225c37315bdaa05371cd3142dda25783f4cca8af Mon Sep 17 00:00:00 2001 From: mjnaderi Date: Thu, 19 Dec 2013 00:35:08 +0330 Subject: Cleanup DB_forge _process_indexes --- system/database/DB_forge.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/database/DB_forge.php') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 92806d305..bde4e2872 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -984,7 +984,6 @@ abstract class CI_DB_forge { */ protected function _process_indexes($table) { - $table = $this->db->escape_identifiers($table); $sqls = array(); for ($i = 0, $c = count($this->keys); $i < $c; $i++) -- cgit v1.2.3-24-g4f1b From 18c2e0c7d75ae91d0223bccf41d07e5a42626cd4 Mon Sep 17 00:00:00 2001 From: mjnaderi Date: Thu, 19 Dec 2013 01:16:17 +0330 Subject: Cleanup DB_forge _process_indexes --- system/database/DB_forge.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database/DB_forge.php') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index bde4e2872..bec8d5554 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -984,6 +984,7 @@ abstract class CI_DB_forge { */ protected function _process_indexes($table) { + $table = $this->db->escape_identifiers($table); $sqls = array(); for ($i = 0, $c = count($this->keys); $i < $c; $i++) @@ -1008,7 +1009,7 @@ abstract class CI_DB_forge { is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); $sqls[] = 'CREATE INDEX '.$this->db->escape_identifiers(implode('_', $this->keys[$i])) - .' ON '.$this->db->escape_identifiers($table) + .' ON '.$table .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).');'; } -- cgit v1.2.3-24-g4f1b From d3a6ca207f5851852a4d0de7c70c861434f70c5c Mon Sep 17 00:00:00 2001 From: mjnaderi Date: Thu, 19 Dec 2013 01:35:57 +0330 Subject: Use table name as a prefix for index names --- system/database/DB_forge.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/database/DB_forge.php') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index bec8d5554..1cebb189c 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -984,7 +984,6 @@ abstract class CI_DB_forge { */ protected function _process_indexes($table) { - $table = $this->db->escape_identifiers($table); $sqls = array(); for ($i = 0, $c = count($this->keys); $i < $c; $i++) @@ -1008,8 +1007,8 @@ abstract class CI_DB_forge { is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); - $sqls[] = 'CREATE INDEX '.$this->db->escape_identifiers(implode('_', $this->keys[$i])) - .' ON '.$table + $sqls[] = 'CREATE INDEX '.$this->db->escape_identifiers($table.'_'.implode('_', $this->keys[$i])) + .' ON '.$this->db->escape_identifiers($table) .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).');'; } -- cgit v1.2.3-24-g4f1b From 27f798b9d64025fecaaecbd80a8cba41d455940f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 20 Jan 2014 18:19:13 +0200 Subject: Add support for optional table attributes to CI_DB_forge::create_table() Supersedes PRs #989, #2776 Related issue: #41 --- system/database/DB_forge.php | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'system/database/DB_forge.php') 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; @@ -417,6 +420,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 * -- cgit v1.2.3-24-g4f1b From 871754af60251993d640981e107d2def5f2db396 Mon Sep 17 00:00:00 2001 From: darwinel Date: Tue, 11 Feb 2014 17:34:57 +0100 Subject: 2013 > 2014 Update copyright notices from 2013 to 2014. And update one calendar example in user_guide from year 2013/2014 to 2014/2015. --- system/database/DB_forge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/DB_forge.php') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index fc4a9230f..4eeb74a9c 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b