summaryrefslogtreecommitdiffstats
path: root/system/database/DB_forge.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/database/DB_forge.php')
-rw-r--r--system/database/DB_forge.php79
1 files changed, 60 insertions, 19 deletions
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index 34c502a99..ff5eb3fe6 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -25,10 +25,8 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
- * Database Utility Class
+ * Database Forge Class
*
* @category Database
* @author EllisLab Dev Team
@@ -41,6 +39,12 @@ abstract class CI_DB_forge {
public $primary_keys = array();
public $db_char_set = '';
+ // Platform specific SQL strings
+ protected $_create_database = 'CREATE DATABASE %s';
+ protected $_drop_database = 'DROP DATABASE %s';
+ protected $_drop_table = 'DROP TABLE IF EXISTS %s';
+ protected $_rename_table = 'ALTER TABLE %s RENAME TO %s';
+
public function __construct()
{
// Assign the main database object to $this->db
@@ -59,8 +63,16 @@ abstract class CI_DB_forge {
*/
public function create_database($db_name)
{
- $sql = $this->_create_database($db_name);
- return is_bool($sql) ? $sql : $this->db->query($sql);
+ if ($this->_create_database === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ }
+ elseif ( ! $this->db->query(sprintf($this->_create_database, $db_name, $this->db->char_set, $this->db->dbcollat)))
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
+ }
+
+ return TRUE;
}
// --------------------------------------------------------------------
@@ -73,8 +85,21 @@ abstract class CI_DB_forge {
*/
public function drop_database($db_name)
{
- $sql = $this->_drop_database($db_name);
- return is_bool($sql) ? $sql : $this->db->query($sql);
+ if ($db_name === '')
+ {
+ show_error('A table name is required for that operation.');
+ return FALSE;
+ }
+ elseif ($this->_drop_database === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ }
+ elseif ( ! $this->db->query(sprintf($this->_drop_database, $db_name)))
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
+ }
+
+ return TRUE;
}
// --------------------------------------------------------------------
@@ -98,7 +123,7 @@ abstract class CI_DB_forge {
return;
}
- if ($key == '')
+ if ($key === '')
{
show_error('Key information is required for that operation.');
}
@@ -125,7 +150,7 @@ abstract class CI_DB_forge {
*/
public function add_field($field = '')
{
- if ($field == '')
+ if ($field === '')
{
show_error('Field information is required.');
}
@@ -172,7 +197,7 @@ abstract class CI_DB_forge {
*/
public function create_table($table = '', $if_not_exists = FALSE)
{
- if ($table == '')
+ if ($table === '')
{
show_error('A table name is required for that operation.');
}
@@ -197,8 +222,16 @@ abstract class CI_DB_forge {
*/
public function drop_table($table_name)
{
- $sql = $this->_drop_table($this->db->dbprefix.$table_name);
- return is_bool($sql) ? $sql : $this->db->query($sql);
+ if ($table_name === '')
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_table_name_required') : FALSE;
+ }
+ elseif ($this->_drop_table === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
+ }
+
+ return $this->db->query(sprintf($this->_drop_table, $this->db->escape_identifiers($this->db->dbprefix.$table_name)));
}
// --------------------------------------------------------------------
@@ -212,12 +245,20 @@ abstract class CI_DB_forge {
*/
public function rename_table($table_name, $new_table_name)
{
- if ($table_name == '' OR $new_table_name == '')
+ if ($table_name === '' OR $new_table_name === '')
{
show_error('A table name is required for that operation.');
+ return FALSE;
+ }
+ elseif ($this->_rename_table === FALSE)
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
}
- return $this->db->query($this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name));
+ return $this->db->query(sprintf($this->_rename_table,
+ $this->db->escape_identifiers($this->db->dbprefix.$table_name),
+ $this->db->escape_identifiers($this->db->dbprefix.$new_table_name))
+ );
}
// --------------------------------------------------------------------
@@ -232,7 +273,7 @@ abstract class CI_DB_forge {
*/
public function add_column($table = '', $field = array(), $after_field = '')
{
- if ($table == '')
+ if ($table === '')
{
show_error('A table name is required for that operation.');
}
@@ -243,7 +284,7 @@ abstract class CI_DB_forge {
{
$this->add_field(array($k => $field[$k]));
- if (count($this->fields) == 0)
+ if (count($this->fields) === 0)
{
show_error('Field information is required.');
}
@@ -271,12 +312,12 @@ abstract class CI_DB_forge {
*/
public function drop_column($table = '', $column_name = '')
{
- if ($table == '')
+ if ($table === '')
{
show_error('A table name is required for that operation.');
}
- if ($column_name == '')
+ if ($column_name === '')
{
show_error('A column name is required for that operation.');
}
@@ -296,7 +337,7 @@ abstract class CI_DB_forge {
*/
public function modify_column($table = '', $field = array())
{
- if ($table == '')
+ if ($table === '')
{
show_error('A table name is required for that operation.');
}