summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2008-04-11 13:43:11 +0200
committerDerek Allard <derek.allard@ellislab.com>2008-04-11 13:43:11 +0200
commitd7f421133d78156a8587f9c244b4bebb4d2c6a8c (patch)
treed90427bbb69b8aabd3afa2f2eab5577dc69168a7
parent28393bfaa8f12d7212138e3efb373095c0c92177 (diff)
The MySQLi forge class is now in sync with MySQL forge.
-rw-r--r--system/database/drivers/mysqli/mysqli_forge.php125
-rw-r--r--user_guide/changelog.html1
2 files changed, 66 insertions, 60 deletions
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index 46a107565..e6bc0093f 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -53,40 +53,16 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
// --------------------------------------------------------------------
/**
- * Drop Table
- *
- * @access private
- * @return bool
- */
- function _drop_table($table)
- {
- return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Create Table
+ * Process Fields
*
* @access private
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param mixed the fields
+ * @return string
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ function _process_fields($fields)
{
- $sql = 'CREATE TABLE ';
-
- if ($if_not_exists === TRUE)
- {
- $sql .= 'IF NOT EXISTS ';
- }
-
- $sql .= $this->db->_escape_table($table)." (";
$current_field_count = 0;
+ $sql = '';
foreach ($fields as $field=>$attributes)
{
@@ -102,8 +78,16 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
$attributes = array_change_key_case($attributes, CASE_UPPER);
$sql .= "\n\t".$this->db->_protect_identifiers($field);
+
+ if (array_key_exists('NAME', $attributes))
+ {
+ $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
+ }
- $sql .= ' '.$attributes['TYPE'];
+ if (array_key_exists('TYPE', $attributes))
+ {
+ $sql .= ' '.$attributes['TYPE'];
+ }
if (array_key_exists('CONSTRAINT', $attributes))
{
@@ -120,13 +104,9 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
}
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
+ if (array_key_exists('NULL', $attributes))
{
- $sql .= ' NOT NULL';
+ $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL';
}
if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
@@ -141,6 +121,35 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
$sql .= ',';
}
}
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Create Table
+ *
+ * @access private
+ * @param string the table name
+ * @param mixed the fields
+ * @param mixed primary key(s)
+ * @param mixed key(s)
+ * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @return bool
+ */
+ function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
+ {
+ $sql = 'CREATE TABLE ';
+
+ if ($if_not_exists === TRUE)
+ {
+ $sql .= 'IF NOT EXISTS ';
+ }
+
+ $sql .= $this->db->_escape_table($table)." (";
+
+ $sql .= $this->_process_fields($fields);
if (count($primary_keys) > 0)
{
@@ -165,6 +174,19 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
// --------------------------------------------------------------------
/**
+ * Drop Table
+ *
+ * @access private
+ * @return string
+ */
+ function _drop_table($table)
+ {
+ return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Alter table query
*
* Generates a platform-specific query so that a table can be altered
@@ -173,45 +195,28 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
* @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
- * @param string the table name
- * @param string the column definition
- * @param string the default value
- * @param boolean should 'NOT NULL' be added
+ * @param array fields
* @param string the field after which we should add the new field
* @return object
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ function _alter_table($alter_type, $table, $fields, $after_field = '')
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
+ $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
// DROP has everything it needs now.
if ($alter_type == 'DROP')
{
- return $sql;
+ return $sql.$this->db->_protect_identifiers($fields);
}
- $sql .= " $column_definition";
-
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
-
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
+ $sql .= $this->_process_fields($fields);
if ($after_field != '')
{
$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
}
- return $sql;
+ return $sql;
}
// --------------------------------------------------------------------
@@ -231,6 +236,6 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
return $sql;
}
-
+
}
?> \ No newline at end of file
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 5a8d0edb4..bc1a5072c 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -79,6 +79,7 @@ Change Log
<li>Added increased security for filename handling in the Upload library.</li>
<li>Added increased security for sessions for client-side data tampering.</li>
<li>Added <kbd>form_button()</kbd> in the <a href="helpers/form_helper.html">Form helper</a>.</li>
+ <li>The MySQLi forge class is now in sync with MySQL forge. </li>
</ul>
</li>
<li>Helpers