diff options
-rw-r--r-- | system/database/DB_forge.php | 21 | ||||
-rw-r--r-- | system/database/drivers/mssql/mssql_forge.php | 19 | ||||
-rw-r--r-- | system/database/drivers/mysql/mysql_forge.php | 20 | ||||
-rw-r--r-- | system/database/drivers/mysqli/mysqli_forge.php | 19 | ||||
-rw-r--r-- | system/database/drivers/oci8/oci8_forge.php | 19 | ||||
-rw-r--r-- | system/database/drivers/odbc/odbc_forge.php | 20 | ||||
-rw-r--r-- | system/database/drivers/postgre/postgre_forge.php | 19 | ||||
-rw-r--r-- | system/database/drivers/sqlite/sqlite_driver.php | 18 | ||||
-rw-r--r-- | user_guide/changelog.html | 3 | ||||
-rw-r--r-- | user_guide/database/forge.html | 11 |
10 files changed, 164 insertions, 5 deletions
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index cd468bc6a..5f25ebedc 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -209,6 +209,27 @@ class CI_DB_forge { // --------------------------------------------------------------------
/**
+ * Rename Table
+ *
+ * @access public
+ * @param string the old table name
+ * @param string the new table name
+ * @return bool
+ */
+ function rename_table($table_name, $new_table_name)
+ {
+ if ($table_name == '' OR $new_table_name == '')
+ {
+ show_error('A table name is required for that operation.');
+ }
+
+ $sql = $this->_rename_table($table_name, $new_table_name);
+ return $this->db->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Column Add
*
* @access public
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index baf776c74..63063f259 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -215,5 +215,24 @@ class CI_DB_mssql_forge extends CI_DB_forge { }
+ // --------------------------------------------------------------------
+
+ /**
+ * Rename a table
+ *
+ * Generates a platform-specific query so that a table can be renamed
+ *
+ * @access private
+ * @param string the old table name
+ * @param string the new table name
+ * @return string
+ */
+ function _rename_table($table_name, $new_table_name)
+ {
+ // I think this syntax will work, but can find little documentation on renaming tables in MSSQL
+ $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/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 6e3a2d170..4eb449ef2 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -177,7 +177,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { * Drop Table
*
* @access private
- * @return bool
+ * @return string
*/
function _drop_table($table)
{
@@ -219,5 +219,23 @@ class CI_DB_mysql_forge extends CI_DB_forge { return $sql;
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Rename a table
+ *
+ * Generates a platform-specific query so that a table can be renamed
+ *
+ * @access private
+ * @param string the old table name
+ * @param string the new table name
+ * @return string
+ */
+ function _rename_table($table_name, $new_table_name)
+ {
+ $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/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index cb315a450..46a107565 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -213,5 +213,24 @@ class CI_DB_mysqli_forge extends CI_DB_forge { return $sql;
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Rename a table
+ *
+ * Generates a platform-specific query so that a table can be renamed
+ *
+ * @access private
+ * @param string the old table name
+ * @param string the new table name
+ * @return string
+ */
+ function _rename_table($table_name, $new_table_name)
+ {
+ $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/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index b9d9e6354..a3940aedb 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -212,5 +212,24 @@ class CI_DB_oci8_forge extends CI_DB_forge { }
+ // --------------------------------------------------------------------
+
+ /**
+ * Rename a table
+ *
+ * Generates a platform-specific query so that a table can be renamed
+ *
+ * @access private
+ * @param string the old table name
+ * @param string the new table name
+ * @return string
+ */
+ function _rename_table($table_name, $new_table_name)
+ {
+ $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/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 374c15fcd..66e1722d8 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -232,5 +232,25 @@ class CI_DB_odbc_forge extends CI_DB_forge { }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Rename a table
+ *
+ * Generates a platform-specific query so that a table can be renamed
+ *
+ * @access private
+ * @param string the old table name
+ * @param string the new table name
+ * @return string
+ */
+ function _rename_table($table_name, $new_table_name)
+ {
+ $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/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 81ac8e92b..72a61748d 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -215,5 +215,24 @@ class CI_DB_postgre_forge extends CI_DB_forge { }
+ // --------------------------------------------------------------------
+
+ /**
+ * Rename a table
+ *
+ * Generates a platform-specific query so that a table can be renamed
+ *
+ * @access private
+ * @param string the old table name
+ * @param string the new table name
+ * @return string
+ */
+ function _rename_table($table_name, $new_table_name)
+ {
+ $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/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 16a8308c1..2ad5d6120 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -635,6 +635,24 @@ class CI_DB_sqlite_driver extends CI_DB { @sqlite_close($conn_id);
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Rename a table
+ *
+ * Generates a platform-specific query so that a table can be renamed
+ *
+ * @access private
+ * @param string the old table name
+ * @param string the new table name
+ * @return string
+ */
+ function _rename_table($table_name, $new_table_name)
+ {
+ $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
+ return $sql;
+ }
+
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html index 1efaa6b2a..5a8d0edb4 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -62,7 +62,8 @@ Change Log <ul>
<li>Active Record
<ul>
- <li>Added the ability to prevent escaping in having() clauses.</li>
+ <li>Added the ability to prevent escaping in <kbd>having()</kbd> clauses.</li>
+ <li>Added <kbd>rename_table()</kbd> into <a href="./database/forge.html">DBForge</a>.</li>
<li>Fixed a bug that wasn't allowing escaping to be turned off if the value of a query was NULL.</li>
</ul>
</li>
diff --git a/user_guide/database/forge.html b/user_guide/database/forge.html index f21591c7f..655ab96c1 100644 --- a/user_guide/database/forge.html +++ b/user_guide/database/forge.html @@ -71,6 +71,7 @@ Database Forge Class <li><a href="#add_key">Adding Keys</a></li>
<li><a href="#create_table">Creating a Table</a></li>
<li><a href="#drop_table">Dropping a Table</a></li>
+<li><a href="#rename_table">Renaming a Table</a></li>
<li><a href="#modifying_tables">Modifying a Table</a></li>
</ul>
@@ -168,7 +169,7 @@ already be running, since the forge class relies on it.</p> <br />
$this->dbforge->add_key('blog_name');<br />
// gives KEY (blog_name)</code></p>
-<h2><a name="create_table" id="create_table2"></a>Creating a table</h2>
+<h2><a name="create_table" id="create_table"></a>Creating a table</h2>
<p>After fields and keys have been declared, you can create a new table with</p>
<p><code>$this->dbforge->create_table('table_name');<br />
// gives CREATE TABLE table_name</code></p>
@@ -178,8 +179,12 @@ already be running, since the forge class relies on it.</p> <h2><a name="drop_table" id="drop_table"></a>Dropping a table</h2>
<p>Executes a DROP TABLE sql</p>
<p><code>$this->dbforge->drop_table('table_name');<br />
-// gives DROP TABLE IF EXISTS table_name</code></p>
-<h1><a name="modifying_tables" id="drop_table2"></a>Modifying Tables</h1>
+ // gives DROP TABLE IF EXISTS table_name</code></p>
+<h2><a name="rename_table" id="rename_table"></a>Renaming a table</h2>
+<p>Executes a TABLE rename</p>
+<p><code>$this->dbforge->rename_table('old_table_name', 'new_table_name');<br />
+ // gives ALTER TABLE old_table_name RENAME TO new_table_name</code></p>
+<h1><a name="modifying_tables" id="modifying_tables"></a>Modifying Tables</h1>
<h2>$this->dbforge->add_column()</h2>
<p>The add_column() function is used to modify an existing table. It accepts the same field array as above, and can be used for an unlimited number of additional fields.</p>
<p><code>$fields = array(<br />
|