summaryrefslogtreecommitdiffstats
path: root/system/database/DB_forge.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@server-speed.net>2011-01-28 22:51:06 +0100
committerFlorian Pritz <bluewind@server-speed.net>2011-01-28 22:58:52 +0100
commitce2b69675075444c9e40b72bcdd42ab7edbbe633 (patch)
tree2932f13b0db14fe53dc0622d888318db638a017f /system/database/DB_forge.php
parentb6b8a6587c399bfd89e13e92ce04ee8486688e6e (diff)
update to CI 2.0
Signed-off-by: Florian Pritz <bluewind@server-speed.net>
Diffstat (limited to 'system/database/DB_forge.php')
-rwxr-xr-x[-rw-r--r--]system/database/DB_forge.php79
1 files changed, 43 insertions, 36 deletions
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index c5931db27..27f2c372d 100644..100755
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -2,11 +2,11 @@
/**
* Code Igniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -24,9 +24,9 @@
*/
class CI_DB_forge {
- var $fields = array();
+ var $fields = array();
var $keys = array();
- var $primary_keys = array();
+ var $primary_keys = array();
var $db_char_set = '';
/**
@@ -34,7 +34,7 @@ class CI_DB_forge {
*
* Grabs the CI super object instance so we can access it.
*
- */
+ */
function CI_DB_forge()
{
// Assign the main database object to $this->db
@@ -55,12 +55,12 @@ class CI_DB_forge {
function create_database($db_name)
{
$sql = $this->_create_database($db_name);
-
+
if (is_bool($sql))
{
return $sql;
}
-
+
return $this->db->query($sql);
}
@@ -76,12 +76,12 @@ class CI_DB_forge {
function drop_database($db_name)
{
$sql = $this->_drop_database($db_name);
-
+
if (is_bool($sql))
{
return $sql;
}
-
+
return $this->db->query($sql);
}
@@ -103,15 +103,15 @@ class CI_DB_forge {
{
$this->add_key($one, $primary);
}
-
+
return;
}
-
+
if ($key == '')
{
show_error('Key information is required for that operation.');
}
-
+
if ($primary === TRUE)
{
$this->primary_keys[] = $key;
@@ -137,7 +137,7 @@ class CI_DB_forge {
{
show_error('Field information is required.');
}
-
+
if (is_string($field))
{
if ($field == 'id')
@@ -157,16 +157,16 @@ class CI_DB_forge {
{
show_error('Field information is required for that operation.');
}
-
+
$this->fields[] = $field;
}
}
-
+
if (is_array($field))
{
$this->fields = array_merge($this->fields, $field);
}
-
+
}
// --------------------------------------------------------------------
@@ -179,19 +179,19 @@ class CI_DB_forge {
* @return bool
*/
function create_table($table = '', $if_not_exists = FALSE)
- {
+ {
if ($table == '')
{
show_error('A table name is required for that operation.');
}
-
+
if (count($this->fields) == 0)
- {
+ {
show_error('Field information is required.');
}
$sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists);
-
+
$this->_reset();
return $this->db->query($sql);
}
@@ -208,12 +208,12 @@ class CI_DB_forge {
function drop_table($table_name)
{
$sql = $this->_drop_table($this->db->dbprefix.$table_name);
-
+
if (is_bool($sql))
{
return $sql;
}
-
+
return $this->db->query($sql);
}
@@ -233,7 +233,7 @@ class CI_DB_forge {
{
show_error('A table name is required for that operation.');
}
-
+
$sql = $this->_rename_table($table_name, $new_table_name);
return $this->db->query($sql);
}
@@ -261,24 +261,25 @@ class CI_DB_forge {
foreach ($field as $k => $v)
{
- $this->add_field(array($k => $field[$k]));
+ $this->add_field(array($k => $field[$k]));
if (count($this->fields) == 0)
- {
+ {
show_error('Field information is required.');
}
-
+
$sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field);
$this->_reset();
-
+
if ($this->db->query($sql) === FALSE)
{
return FALSE;
}
}
-
+
return TRUE;
+
}
// --------------------------------------------------------------------
@@ -293,7 +294,7 @@ class CI_DB_forge {
*/
function drop_column($table = '', $column_name = '')
{
-
+
if ($table == '')
{
show_error('A table name is required for that operation.');
@@ -305,7 +306,7 @@ class CI_DB_forge {
}
$sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name);
-
+
return $this->db->query($sql);
}
@@ -332,23 +333,29 @@ class CI_DB_forge {
foreach ($field as $k => $v)
{
+ // If no name provided, use the current name
+ if ( ! isset($field[$k]['name']))
+ {
+ $field[$k]['name'] = $k;
+ }
+
$this->add_field(array($k => $field[$k]));
if (count($this->fields) == 0)
- {
+ {
show_error('Field information is required.');
}
-
+
$sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields);
$this->_reset();
-
+
if ($this->db->query($sql) === FALSE)
{
return FALSE;
}
}
-
+
return TRUE;
}
@@ -364,9 +371,9 @@ class CI_DB_forge {
*/
function _reset()
{
- $this->fields = array();
+ $this->fields = array();
$this->keys = array();
- $this->primary_keys = array();
+ $this->primary_keys = array();
}
}