summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2011-02-02 22:19:25 +0100
committerPhil Sturgeon <email@philsturgeon.co.uk>2011-02-02 22:19:25 +0100
commitd88b31550ae2aeb0e3bcc11ba82d4838f8a5fd31 (patch)
tree792bff97d41430b5c36a08c8ec3ac54db97375b6 /system/database
parent5c59c7dc3254616b18057922ce012f22c18b147b (diff)
parent75f5ff5d99533a423e68686d89889d172c37d98e (diff)
Merged recent changes and tweaked multi-env changes.
Diffstat (limited to 'system/database')
-rw-r--r--system/database/DB.php2
-rw-r--r--system/database/DB_active_rec.php2
-rw-r--r--system/database/DB_cache.php2
-rw-r--r--system/database/DB_driver.php2
-rw-r--r--system/database/DB_forge.php2
-rw-r--r--system/database/DB_result.php87
-rw-r--r--system/database/DB_utility.php2
-rw-r--r--system/database/drivers/mssql/mssql_driver.php2
-rw-r--r--system/database/drivers/mssql/mssql_forge.php2
-rw-r--r--system/database/drivers/mssql/mssql_result.php2
-rw-r--r--system/database/drivers/mssql/mssql_utility.php2
-rw-r--r--system/database/drivers/mysql/mysql_driver.php2
-rw-r--r--system/database/drivers/mysql/mysql_forge.php2
-rw-r--r--system/database/drivers/mysql/mysql_result.php2
-rw-r--r--system/database/drivers/mysql/mysql_utility.php2
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php71
-rw-r--r--system/database/drivers/mysqli/mysqli_forge.php2
-rw-r--r--system/database/drivers/mysqli/mysqli_result.php2
-rw-r--r--system/database/drivers/mysqli/mysqli_utility.php2
-rw-r--r--system/database/drivers/oci8/oci8_driver.php2
-rw-r--r--system/database/drivers/oci8/oci8_forge.php2
-rw-r--r--system/database/drivers/oci8/oci8_result.php2
-rw-r--r--system/database/drivers/oci8/oci8_utility.php2
-rw-r--r--system/database/drivers/odbc/odbc_driver.php2
-rw-r--r--system/database/drivers/odbc/odbc_forge.php2
-rw-r--r--system/database/drivers/odbc/odbc_result.php2
-rw-r--r--system/database/drivers/odbc/odbc_utility.php2
-rw-r--r--system/database/drivers/postgre/postgre_driver.php2
-rw-r--r--system/database/drivers/postgre/postgre_forge.php83
-rw-r--r--system/database/drivers/postgre/postgre_result.php2
-rw-r--r--system/database/drivers/postgre/postgre_utility.php2
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php2
-rw-r--r--system/database/drivers/sqlite/sqlite_forge.php2
-rw-r--r--system/database/drivers/sqlite/sqlite_result.php2
-rw-r--r--system/database/drivers/sqlite/sqlite_utility.php2
35 files changed, 244 insertions, 61 deletions
diff --git a/system/database/DB.php b/system/database/DB.php
index 739e9d08e..513e5aefd 100644
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index dd46981b1..ce9d1c1af 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php
index 6042e0673..3bf065ca5 100644
--- a/system/database/DB_cache.php
+++ b/system/database/DB_cache.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 7fe5695b0..2d8f592e3 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php
index ce505f4ee..27f2c372d 100644
--- a/system/database/DB_forge.php
+++ b/system/database/DB_forge.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index 05f06af66..fb4268c21 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -6,7 +6,7 @@
*
* @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
@@ -28,13 +28,14 @@
*/
class CI_DB_result {
- var $conn_id = NULL;
- var $result_id = NULL;
- var $result_array = array();
- var $result_object = array();
- var $current_row = 0;
- var $num_rows = 0;
- var $row_data = NULL;
+ var $conn_id = NULL;
+ var $result_id = NULL;
+ var $result_array = array();
+ var $result_object = array();
+ var $custom_result_object = array();
+ var $current_row = 0;
+ var $num_rows = 0;
+ var $row_data = NULL;
/**
@@ -46,11 +47,48 @@ class CI_DB_result {
*/
function result($type = 'object')
{
- return ($type == 'object') ? $this->result_object() : $this->result_array();
+ if ($type == 'array') return $this->result_array();
+ else if ($type == 'object') return $this->result_object();
+ else return $this->custom_result_object($type);
}
// --------------------------------------------------------------------
+ /**
+ * Custom query result.
+ *
+ * @param class_name A string that represents the type of object you want back
+ * @return array of objects
+ */
+ function custom_result_object($class_name)
+ {
+ if (array_key_exists($class_name, $this->custom_result_object))
+ {
+ return $this->custom_result_object[$class_name];
+ }
+
+ if ($this->result_id === FALSE OR $this->num_rows() == 0)
+ {
+ return array();
+ }
+
+ // add the data to the object
+ $this->_data_seek(0);
+ $result_object = array();
+ while ($row = $this->_fetch_object())
+ {
+ $object = new $class_name();
+ foreach($row as $key => $value)
+ {
+ $object->$key = $value;
+ }
+ $result_object[] = $object;
+ }
+
+ // return the array
+ return $this->custom_result_object[$class_name] = $result_object;
+ }
+
/**
* Query result. "object" version.
*
@@ -142,7 +180,9 @@ class CI_DB_result {
$n = 0;
}
- return ($type == 'object') ? $this->row_object($n) : $this->row_array($n);
+ if ($type == 'object') return $this->row_object($n);
+ else if ($type == 'array') return $this->row_array($n);
+ else return $this->custom_row_object($n, $type);
}
// --------------------------------------------------------------------
@@ -179,7 +219,30 @@ class CI_DB_result {
// --------------------------------------------------------------------
- /**
+ /**
+ * Returns a single result row - custom object version
+ *
+ * @access public
+ * @return object
+ */
+ function custom_row_object($n, $type)
+ {
+ $result = $this->custom_result_object($type);
+
+ if (count($result) == 0)
+ {
+ return $result;
+ }
+
+ if ($n != $this->current_row AND isset($result[$n]))
+ {
+ $this->current_row = $n;
+ }
+
+ return $result[$this->current_row];
+ }
+
+ /**
* Returns a single result row - object version
*
* @access public
@@ -339,4 +402,4 @@ class CI_DB_result {
// END DB_result class
/* End of file DB_result.php */
-/* Location: ./system/database/DB_result.php */ \ No newline at end of file
+/* Location: ./system/database/DB_result.php */
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index c4d537a3b..a5f174f0a 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index eade10ee8..5a69132cd 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php
index 6b02e1eb2..70b20ecf8 100644
--- a/system/database/drivers/mssql/mssql_forge.php
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php
index c0a20dbde..2897ca5a5 100644
--- a/system/database/drivers/mssql/mssql_result.php
+++ b/system/database/drivers/mssql/mssql_result.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php
index b867dd7b1..48ecbc72a 100644
--- a/system/database/drivers/mssql/mssql_utility.php
+++ b/system/database/drivers/mssql/mssql_utility.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index f27a1eef6..df18c912e 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index 35845d6af..529ec980d 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php
index c3aa4ccd7..507389603 100644
--- a/system/database/drivers/mysql/mysql_result.php
+++ b/system/database/drivers/mysql/mysql_result.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index 1259fee6f..e9747c540 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index b50fe5f77..8942100d4 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -6,7 +6,7 @@
*
* @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
@@ -539,6 +539,24 @@ class CI_DB_mysqli_driver extends CI_DB {
// --------------------------------------------------------------------
/**
+ * Insert_batch statement
+ *
+ * Generates a platform-specific insert string from the supplied data
+ *
+ * @access public
+ * @param string the table name
+ * @param array the insert keys
+ * @param array the insert values
+ * @return string
+ */
+ function _insert_batch($table, $keys, $values)
+ {
+ return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Update statement
*
* Generates a platform-specific update string from the supplied data
@@ -571,6 +589,57 @@ class CI_DB_mysqli_driver extends CI_DB {
return $sql;
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Update_Batch statement
+ *
+ * Generates a platform-specific batch update string from the supplied data
+ *
+ * @access public
+ * @param string the table name
+ * @param array the update data
+ * @param array the where clause
+ * @return string
+ */
+ function _update_batch($table, $values, $index, $where = NULL)
+ {
+ $ids = array();
+ $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
+
+ foreach($values as $key => $val)
+ {
+ $ids[] = $val[$index];
+
+ foreach(array_keys($val) as $field)
+ {
+ if ($field != $index)
+ {
+ $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
+ }
+ }
+ }
+
+ $sql = "UPDATE ".$table." SET ";
+ $cases = '';
+
+ foreach($final as $k => $v)
+ {
+ $cases .= $k.' = CASE '."\n";
+ foreach ($v as $row)
+ {
+ $cases .= $row."\n";
+ }
+
+ $cases .= 'ELSE '.$k.' END, ';
+ }
+
+ $sql .= substr($cases, 0, -2);
+
+ $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
+
+ return $sql;
+ }
// --------------------------------------------------------------------
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index 5d5b78089..d5097335e 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php
index 16f57c079..c4d8f5d58 100644
--- a/system/database/drivers/mysqli/mysqli_result.php
+++ b/system/database/drivers/mysqli/mysqli_result.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index 84ff0daf4..e17889b8c 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 44d5dec7e..64f53cc3f 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php
index 4bcb081b2..3cd17585a 100644
--- a/system/database/drivers/oci8/oci8_forge.php
+++ b/system/database/drivers/oci8/oci8_forge.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php
index 058524f4c..88531b436 100644
--- a/system/database/drivers/oci8/oci8_result.php
+++ b/system/database/drivers/oci8/oci8_result.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php
index 48d4acec8..854b467e1 100644
--- a/system/database/drivers/oci8/oci8_utility.php
+++ b/system/database/drivers/oci8/oci8_utility.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index af90f0c7a..c8e03c356 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
index 602016ad4..3ec86b4e9 100644
--- a/system/database/drivers/odbc/odbc_forge.php
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index b673464b7..a81a2b8b7 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php
index 9f9ef5a3d..d335bed99 100644
--- a/system/database/drivers/odbc/odbc_utility.php
+++ b/system/database/drivers/odbc/odbc_utility.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index b61a9d75b..0bb7974d8 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
index 41858f36e..91a1c6861 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -6,7 +6,7 @@
*
* @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
@@ -69,7 +69,10 @@ class CI_DB_postgre_forge extends CI_DB_forge {
if ($if_not_exists === TRUE)
{
- $sql .= 'IF NOT EXISTS ';
+ if ($this->db->table_exists($table))
+ {
+ return "SELECT * FROM $table"; // Needs to return innocous but valid SQL statement
+ }
}
$sql .= $this->db->_escape_identifiers($table)." (";
@@ -90,16 +93,55 @@ class CI_DB_postgre_forge extends CI_DB_forge {
$sql .= "\n\t".$this->db->_protect_identifiers($field);
- $sql .= ' '.$attributes['TYPE'];
+ $is_unsigned = (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE);
- if (array_key_exists('CONSTRAINT', $attributes))
+ // Convert datatypes to be PostgreSQL-compatible
+ switch (strtoupper($attributes['TYPE']))
{
- $sql .= '('.$attributes['CONSTRAINT'].')';
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ break;
+ case 'SMALLINT':
+ $attributes['TYPE'] = ($is_unsigned) ? 'INTEGER' : 'SMALLINT';
+ break;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ break;
+ case 'INT':
+ $attributes['TYPE'] = ($is_unsigned) ? 'BIGINT' : 'INTEGER';
+ break;
+ case 'BIGINT':
+ $attributes['TYPE'] = ($is_unsigned) ? 'NUMERIC' : 'BIGINT';
+ break;
+ case 'DOUBLE':
+ $attributes['TYPE'] = 'DOUBLE PRECISION';
+ break;
+ case 'DATETIME':
+ $attributes['TYPE'] = 'TIMESTAMP';
+ break;
+ case 'LONGTEXT':
+ $attributes['TYPE'] = 'TEXT';
+ break;
+ case 'BLOB':
+ $attributes['TYPE'] = 'BYTEA';
+ break;
}
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
+ // If this is an auto-incrementing primary key, use the serial data type instead
+ if (in_array($field, $primary_keys) && array_key_exists('AUTO_INCREMENT', $attributes)
+ && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ $sql .= ' SERIAL';
+ }
+ else
{
- $sql .= ' UNSIGNED';
+ $sql .= ' '.$attributes['TYPE'];
+ }
+
+ // Modified to prevent constraints with integer data types
+ if (array_key_exists('CONSTRAINT', $attributes) && strpos($attributes['TYPE'], 'INT') === false)
+ {
+ $sql .= '('.$attributes['CONSTRAINT'].')';
}
if (array_key_exists('DEFAULT', $attributes))
@@ -116,9 +158,10 @@ class CI_DB_postgre_forge extends CI_DB_forge {
$sql .= ' NOT NULL';
}
- if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
+ // Added new attribute to create unqite fields. Also works with MySQL
+ if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE)
{
- $sql .= ' AUTO_INCREMENT';
+ $sql .= ' UNIQUE';
}
}
@@ -131,10 +174,17 @@ class CI_DB_postgre_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
+ // Something seems to break when passing an array to _protect_identifiers()
+ foreach ($primary_keys as $index => $key)
+ {
+ $primary_keys[$index] = $this->db->_protect_identifiers($key);
+ }
+
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
+ $sql .= "\n);";
+
if (is_array($keys) && count($keys) > 0)
{
foreach ($keys as $key)
@@ -148,12 +198,13 @@ class CI_DB_postgre_forge extends CI_DB_forge {
$key = array($this->db->_protect_identifiers($key));
}
- $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
+ foreach ($key as $field)
+ {
+ $sql .= "CREATE INDEX " . $table . "_" . str_replace(array('"', "'"), '', $field) . "_index ON $table ($field); ";
+ }
}
}
- $sql .= "\n);";
-
return $sql;
}
@@ -162,12 +213,12 @@ class CI_DB_postgre_forge extends CI_DB_forge {
/**
* Drop Table
*
- * @access private
- * @return bool
+ * @access private
+ * @return bool
*/
function _drop_table($table)
{
- return "DROP TABLE ".$this->db->_escape_identifiers($table)." CASCADE";
+ return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table)." CASCADE";
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php
index 126631201..e9a1d1607 100644
--- a/system/database/drivers/postgre/postgre_result.php
+++ b/system/database/drivers/postgre/postgre_result.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php
index f04c7f083..741c52ea8 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index d6c6897c6..5bfc1f558 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
index 0aa5d382a..56904082e 100644
--- a/system/database/drivers/sqlite/sqlite_forge.php
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php
index 9a86aa99c..7bd30db7c 100644
--- a/system/database/drivers/sqlite/sqlite_result.php
+++ b/system/database/drivers/sqlite/sqlite_result.php
@@ -6,7 +6,7 @@
*
* @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
diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php
index b76c1b366..508023e2f 100644
--- a/system/database/drivers/sqlite/sqlite_utility.php
+++ b/system/database/drivers/sqlite/sqlite_utility.php
@@ -6,7 +6,7 @@
*
* @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