Many new Active Record functions, and another whack of stuff
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 044fb3c..06a508e 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -35,7 +35,8 @@
 	 * database engines, so this string appears in each driver and is

 	 * used for the count_all() and count_all_results() functions.

 	 */

-	var $_count_string = "SELECT COUNT(*) AS numrows ";

+	var $_count_string = "SELECT COUNT(*) AS ";

+	var $_random_keyword = ' ASC'; // not currently supported

 	

 	/**

 	 * Non-persistent database connection

@@ -77,6 +78,22 @@
 	// --------------------------------------------------------------------

 	

 	/**

+	 * Set client character set

+	 *

+	 * @access	public

+	 * @param	string

+	 * @param	string

+	 * @return	resource

+	 */

+	function db_set_charset($charset, $collation)

+	{

+		// TODO - add support if needed

+		return TRUE;

+	}

+

+	// --------------------------------------------------------------------

+	

+	/**

 	 * Execute the query

 	 *

 	 * @access	private called by the base class

@@ -297,11 +314,21 @@
 	 * Generates a platform-specific query string so that the table names can be fetched

 	 *

 	 * @access	private

+	 * @param	boolean

 	 * @return	string

 	 */

-	function _list_tables()

+	function _list_tables($prefix_limit = FALSE)

 	{

-		return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";		

+		$sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";

+		

+		// for future compatibility

+		if ($prefix_limit !== FALSE AND $this->dbprefix != '')

+		{

+			//$sql .= " LIKE '".$this->dbprefix."%'";

+			return FALSE; // not currently supported

+		}

+		

+		return $sql;

 	}

 

 	// --------------------------------------------------------------------

@@ -393,6 +420,25 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Protect Identifiers

+	 *

+	 * This function adds backticks if appropriate based on db type

+	 *

+	 * @access	private

+	 * @param	mixed	the item(s)

+	 * @param	boolean	should spaces be backticked

+	 * @param	boolean	only affect the first word

+	 * @return	mixed	the item with backticks

+	 */	

+	function _protect_identifiers($item, $affect_spaces = TRUE, $first_word_only = FALSE)

+	{

+		// MSSQL doesn't use backticks

+		return $item;

+	}

+			

+	// --------------------------------------------------------------------

+

+	/**

 	 * Insert statement

 	 *

 	 * Generates a platform-specific insert string from the supplied data

@@ -419,9 +465,11 @@
 	 * @param	string	the table name

 	 * @param	array	the update data

 	 * @param	array	the where clause

+	 * @param	array	the orderby clause

+	 * @param	array	the limit clause

 	 * @return	string

 	 */

-	function _update($table, $values, $where, $limit = FALSE)

+	function _update($table, $values, $where, $orderby = array(), $limit = FALSE)

 	{

 		foreach($values as $key => $val)

 		{

@@ -429,8 +477,29 @@
 		}

 		

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

+		

+		$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';

 	

-		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;

+		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit;

+	}

+

+	

+	// --------------------------------------------------------------------

+

+	/**

+	 * Truncate statement

+	 *

+	 * Generates a platform-specific truncate string from the supplied data

+	 * If the database does not support the truncate() command

+	 * This function maps to "DELETE FROM table"

+	 *

+	 * @access	public

+	 * @param	string	the table name

+	 * @return	string

+	 */	

+	function _truncate($table)

+	{

+		return "TRUNCATE ".$this->_escape_table($table);

 	}

 	

 	// --------------------------------------------------------------------

@@ -443,13 +512,28 @@
 	 * @access	public

 	 * @param	string	the table name

 	 * @param	array	the where clause

+	 * @param	string	the limit clause

 	 * @return	string

 	 */	

-	function _delete($table, $where, $limit = FALSE)

+	function _delete($table, $where = array(), $like = array(), $limit = FALSE)

 	{

+		$conditions = '';

+

+		if (count($where) > 0 || count($like) > 0)

+		{

+			$conditions = "\nWHERE ";

+			$conditions .= implode("\n", $this->ar_where);

+

+			if (count($where) > 0 && count($like) > 0)

+			{

+				$conditions .= " AND ";

+			}

+			$conditions .= implode("\n", $like);

+		}

+

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

 	

-		return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;

+		return "DELETE FROM ".$table.$conditions.$limit;

 	}

 

 	// --------------------------------------------------------------------

diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php
new file mode 100644
index 0000000..63a9d83
--- /dev/null
+++ b/system/database/drivers/mssql/mssql_forge.php
@@ -0,0 +1,219 @@
+<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

+/**

+ * CodeIgniter

+ *

+ * An open source application development framework for PHP 4.3.2 or newer

+ *

+ * @package		CodeIgniter

+ * @author		Rick Ellis

+ * @copyright	Copyright (c) 2006, EllisLab, Inc.

+ * @license		http://www.codeigniter.com/user_guide/license.html

+ * @link		http://www.codeigniter.com

+ * @since		Version 1.0

+ * @filesource

+ */

+

+// ------------------------------------------------------------------------

+

+/**

+ * MS SQL Forge Class

+ *

+ * @category	Database

+ * @author		Rick Ellis

+ * @link		http://www.codeigniter.com/user_guide/database/

+ */

+class CI_DB_mssql_forge extends CI_DB_forge {

+

+	/**

+	 * Create database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database($name)

+	{

+		return "CREATE DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		return "DROP DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop Table

+	 *

+	 * @access	private

+	 * @return	bool

+	 */

+	function _drop_table($table)

+	{

+		return "DROP TABLE ".$this->db->_escape_table($table);

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Create Table

+	 *

+	 * @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

+	 */

+	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)." (";

+		$current_field_count = 0;

+

+		foreach ($fields as $field=>$attributes)

+		{

+			// Numeric field names aren't allowed in databases, so if the key is

+			// numeric, we know it was assigned by PHP and the developer manually

+			// entered the field information, so we'll simply add it to the list

+			if (is_numeric($field))

+			{

+				$sql .= "\n\t$attributes";

+			}

+			else

+			{

+				$attributes = array_change_key_case($attributes, CASE_UPPER);

+				

+				$sql .= "\n\t".$this->db->_protect_identifiers($field);

+				

+				$sql .=  ' '.$attributes['TYPE'];

+	

+				if (array_key_exists('CONSTRAINT', $attributes))

+				{

+					$sql .= '('.$attributes['CONSTRAINT'].')';

+				}

+	

+				if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)

+				{

+					$sql .= ' UNSIGNED';

+				}

+	

+				if (array_key_exists('DEFAULT', $attributes))

+				{

+					$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';

+				}

+	

+				if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)

+				{

+					$sql .= ' NULL';

+				}

+				else

+				{

+					$sql .= ' NOT NULL';			

+				}

+	

+				if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)

+				{

+					$sql .= ' AUTO_INCREMENT';

+				}

+			}

+			

+			// don't add a comma on the end of the last field

+			if (++$current_field_count < count($fields))

+			{

+				$sql .= ',';

+			}

+		}

+

+		if (count($primary_keys) > 0)

+		{

+			$primary_keys = $this->db->_protect_identifiers($primary_keys);

+			$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";

+		}

+

+		if (is_array($keys) && count($keys) > 0)

+		{

+			$keys = $this->db->_protect_identifiers($keys);

+			foreach ($keys as $key)

+			{

+				$sql .= ",\n\tFOREIGN KEY ($key)";

+			}

+		}

+

+		$sql .= "\n)";

+

+		return $sql;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Alter table query

+	 *

+	 * Generates a platform-specific query so that a table can be altered

+	 * Called by add_column(), drop_column(), and column_alter(),

+	 *

+	 * @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	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 = '')

+	{

+		$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);

+

+		// DROP has everything it needs now.

+		if ($alter_type == 'DROP')

+		{

+			return $sql;

+		}

+

+		$sql .= " $column_definition";

+

+		if ($default_value != '')

+		{

+			$sql .= " DEFAULT \"$default_value\"";

+		}

+

+		if ($null === NULL)

+		{

+			$sql .= ' NULL';

+		}

+		else

+		{

+			$sql .= ' NOT NULL';

+		}

+

+		if ($after_field != '')

+		{

+			$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);

+		}

+		

+		return $sql;

+		

+	}

+

+}

+?>
\ No newline at end of file
diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php
index 3a10221..b020a2a 100644
--- a/system/database/drivers/mssql/mssql_utility.php
+++ b/system/database/drivers/mssql/mssql_utility.php
@@ -24,48 +24,6 @@
  */

 class CI_DB_mssql_utility extends CI_DB_utility {

 

-

-	/**

-	 * Create database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _create_database($name)

-	{

-		return "CREATE DATABASE ".$name;

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

-	 * Drop database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _drop_database($name)

-	{

-		return "DROP DATABASE ".$name;

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

-	 * Drop Table

-	 *

-	 * @access	private

-	 * @return	bool

-	 */

-	function _drop_table($table)

-	{

-		return "DROP TABLE ".$this->db->_escape_table($table);

-	}

-

-	// --------------------------------------------------------------------

-

 	/**

 	 * List databases

 	 *

@@ -94,7 +52,7 @@
 	}

 

 	// --------------------------------------------------------------------

-

+	

 	/**

 	 * Repair table query

 	 *

@@ -124,6 +82,39 @@
 		return $this->db->display_error('db_unsuported_feature');

 	}

 

+	/**

+	 *

+	 * The functions below have been deprecated as of 1.6, and are only here for backwards

+	 * compatibility.  They now reside in dbforge().  The use of dbutils for database manipulation

+	 * is STRONGLY discouraged in favour if using dbforge.

+	 *

+	 */

+

+	/**

+	 * Create database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database($name)

+	{

+		return "CREATE DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		return "DROP DATABASE ".$name;

+	}

 

 }

 

diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index cd86ebf..a164552 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -42,7 +42,7 @@
 	 * database engines, so this string appears in each driver and is

 	 * used for the count_all() and count_all_results() functions.

 	 */

-	var $_count_string = "SELECT COUNT(*) AS numrows ";

+	var $_count_string = 'SELECT COUNT(*) AS ';

 	var $_random_keyword = ' RAND()'; // database specific random keyword

 

 	/**

@@ -85,6 +85,21 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Set client character set

+	 *

+	 * @access	public

+	 * @param	string

+	 * @param	string

+	 * @return	resource

+	 */

+	function db_set_charset($charset, $collation)

+	{

+		return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);

+	}

+

+	// --------------------------------------------------------------------

+	

+	/**

 	 * Version number query string

 	 *

 	 * @access	public

@@ -314,17 +329,18 @@
 	 * Generates a platform-specific query string so that the table names can be fetched

 	 *

 	 * @access	private

+	 * @param	boolean

 	 * @return	string

 	 */

 	function _list_tables($prefix_limit = FALSE)

 	{

 		$sql = "SHOW TABLES FROM `".$this->database."`";	

-		

-		if ($prefix_limit !== FALSE AND $this->_stdprefix != '')

+

+		if ($prefix_limit !== FALSE AND $this->dbprefix != '')

 		{

-			$sql .= " LIKE '".$this->_stdprefix."%'";

+			$sql .= " LIKE '".$this->dbprefix."%'";

 		}

-		

+

 		return $sql;

 	}

 	

@@ -400,14 +416,66 @@
 	 */

 	function _escape_table($table)

 	{

-		if (stristr($table, '.'))

+		if (strpos($table, '.') !== FALSE)

 		{

-			$table = preg_replace("/\./", "`.`", $table);

+			$table = str_replace('.', '`.`', $table);

 		}

 		

 		return $table;

 	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Protect Identifiers

+	 *

+	 * This function adds backticks if appropriate based on db type

+	 *

+	 * @access	private

+	 * @param	mixed	the item to escape

+	 * @param	boolean	only affect the first word

+	 * @return	mixed	the item with backticks

+	 */

+	function _protect_identifiers($item, $first_word_only = FALSE)

+	{

+		if (is_array($item))

+		{

+			$escaped_array = array();

+

+			foreach($item as $k=>$v)

+			{

+				$escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only);

+			}

+

+			return $escaped_array;

+		}	

+

+		// This function may get "item1 item2" as a string, and so

+		// we may need "`item1` `item2`" and not "`item1 item2`"

+		if (strpos($item, ' ') !== FALSE)

+		{

+			// This function may get "field >= 1", and need it to return "`field` >= 1"

+			if ($first_word_only === TRUE)

+			{

+				return '`'.preg_replace('/ /', '` ', $item, 1);

+			}

+

+			$item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item);

+		}

+

+		$exceptions = array('AS', '/', '-', '%', '+', '*');

 		

+		foreach ($exceptions as $exception)

+		{

+		

+			if (stristr($item, " `{$exception}` ") !== FALSE)

+			{

+				$item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item);

+			}

+		}

+		return $item;

+	}

+			

 	// --------------------------------------------------------------------

 

 	/**

@@ -437,9 +505,11 @@
 	 * @param	string	the table name

 	 * @param	array	the update data

 	 * @param	array	the where clause

+	 * @param	array	the orderby clause

+	 * @param	array	the limit clause

 	 * @return	string

 	 */

-	function _update($table, $values, $where, $limit = FALSE)

+	function _update($table, $values, $where, $orderby = array(), $limit = FALSE)

 	{

 		foreach($values as $key => $val)

 		{

@@ -447,8 +517,28 @@
 		}

 		

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

+		

+		$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';

 	

-		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;

+		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Truncate statement

+	 *

+	 * Generates a platform-specific truncate string from the supplied data

+	 * If the database does not support the truncate() command

+	 * This function maps to "DELETE FROM table"

+	 *

+	 * @access	public

+	 * @param	string	the table name

+	 * @return	string

+	 */	

+	function _truncate($table)

+	{

+		return "TRUNCATE ".$this->_escape_table($table);

 	}

 	

 	// --------------------------------------------------------------------

@@ -461,13 +551,28 @@
 	 * @access	public

 	 * @param	string	the table name

 	 * @param	array	the where clause

+	 * @param	string	the limit clause

 	 * @return	string

 	 */	

-	function _delete($table, $where, $limit = FALSE)

+	function _delete($table, $where = array(), $like = array(), $limit = FALSE)

 	{

+		$conditions = '';

+

+		if (count($where) > 0 || count($like) > 0)

+		{

+			$conditions = "\nWHERE ";

+			$conditions .= implode("\n", $this->ar_where);

+

+			if (count($where) > 0 && count($like) > 0)

+			{

+				$conditions .= " AND ";

+			}

+			$conditions .= implode("\n", $like);

+		}

+

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

 	

-		return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;

+		return "DELETE FROM ".$table.$conditions.$limit;

 	}

 

 	// --------------------------------------------------------------------

diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
new file mode 100644
index 0000000..8a918c0
--- /dev/null
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -0,0 +1,223 @@
+<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

+/**

+ * CodeIgniter

+ *

+ * An open source application development framework for PHP 4.3.2 or newer

+ *

+ * @package		CodeIgniter

+ * @author		Rick Ellis

+ * @copyright	Copyright (c) 2006, EllisLab, Inc.

+ * @license		http://www.codeigniter.com/user_guide/license.html

+ * @link		http://www.codeigniter.com

+ * @since		Version 1.0

+ * @filesource

+ */

+

+// ------------------------------------------------------------------------

+

+/**

+ * MySQL Forge Class

+ *

+ * @category	Database

+ * @author		Rick Ellis

+ * @link		http://www.codeigniter.com/user_guide/database/

+ */

+class CI_DB_mysql_forge extends CI_DB_forge {

+	

+	/**

+	 * Create database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database($name)

+	{

+		return "CREATE DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		return "DROP DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Process Fields

+	 *

+	 * @access	private

+	 * @param	mixed	the fields

+	 * @return	string

+	 */

+	function _process_fields($fields)

+	{

+		$current_field_count = 0;

+		$sql = '';

+

+		foreach ($fields as $field=>$attributes)

+		{

+			// Numeric field names aren't allowed in databases, so if the key is

+			// numeric, we know it was assigned by PHP and the developer manually

+			// entered the field information, so we'll simply add it to the list

+			if (is_numeric($field))

+			{

+				$sql .= "\n\t$attributes";

+			}

+			else

+			{

+				$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']).' ';

+				}

+				

+				if (array_key_exists('TYPE', $attributes))

+				{

+					$sql .=  ' '.$attributes['TYPE'];

+				}

+	

+				if (array_key_exists('CONSTRAINT', $attributes))

+				{

+					$sql .= '('.$attributes['CONSTRAINT'].')';

+				}

+	

+				if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)

+				{

+					$sql .= ' UNSIGNED';

+				}

+	

+				if (array_key_exists('DEFAULT', $attributes))

+				{

+					$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';

+				}

+	

+				if (array_key_exists('NULL', $attributes))

+				{

+					$sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL';

+				}

+	

+				if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)

+				{

+					$sql .= ' AUTO_INCREMENT';

+				}

+			}

+			

+			// don't add a comma on the end of the last field

+			if (++$current_field_count < count($fields))

+			{

+				$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)

+		{

+			$primary_keys = $this->db->_protect_identifiers($primary_keys);

+			$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";

+		}

+

+		if (is_array($keys) && count($keys) > 0)

+		{

+			$keys = $this->db->_protect_identifiers($keys);

+			foreach ($keys as $key)

+			{

+				$sql .= ",\n\tKEY ($key)";

+			}

+		}

+

+		$sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};";

+

+		return $sql;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop Table

+	 *

+	 * @access	private

+	 * @return	bool

+	 */

+	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

+	 * Called by add_column(), drop_column(), and column_alter(),

+	 *

+	 * @access	private

+	 * @param	string	the ALTER type (ADD, DROP, CHANGE)

+	 * @param	string	the column name

+	 * @param	array	fields

+	 * @param	string	the field after which we should add the new field

+	 * @return	object

+	 */

+	function _alter_table($alter_type, $table, $fields, $after_field = '')

+	{

+		$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";

+

+		// DROP has everything it needs now.

+		if ($alter_type == 'DROP')

+		{

+			return $sql.$this->db->_protect_identifiers($fields);

+		}

+

+		$sql .= $this->_process_fields($fields);

+

+		if ($after_field != '')

+		{

+			$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);

+		}

+		

+		return $sql;

+	}

+

+}

+?>
\ No newline at end of file
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index 54c110e..c24a008 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -23,34 +23,6 @@
  * @link		http://www.codeigniter.com/user_guide/database/

  */

 class CI_DB_mysql_utility extends CI_DB_utility {

-	

-	/**

-	 * Create database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _create_database($name)

-	{

-		return "CREATE DATABASE ".$name;

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

-	 * Drop database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _drop_database($name)

-	{

-		return "DROP DATABASE ".$name;

-	}

-

-	// --------------------------------------------------------------------

 

 	/**

 	 * List databases

@@ -66,19 +38,6 @@
 	// --------------------------------------------------------------------

 

 	/**

-	 * Drop Table

-	 *

-	 * @access	private

-	 * @return	bool

-	 */

-	function _drop_table($table)

-	{

-		return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table);

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

 	 * Optimize table query

 	 *

 	 * Generates a platform-specific query so that a table can be optimized

@@ -109,7 +68,6 @@
 	}

 

 	// --------------------------------------------------------------------

-

 	/**

 	 * MySQL Export

 	 *

@@ -187,9 +145,10 @@
 			$is_int = array();

 			while ($field = mysql_fetch_field($query->result_id))

 			{

+				// Most versions of MySQL store timestamp as a string

 				$is_int[$i] = (in_array(

 										strtolower(mysql_field_type($query->result_id, $i)),

-										array('tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'timestamp'),

+										array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'), 

 										TRUE)

 										) ? TRUE : FALSE;

 										

@@ -255,7 +214,39 @@
 		return $output;

 	}

 

+	/**

+	 *

+	 * The functions below have been deprecated as of 1.6, and are only here for backwards

+	 * compatibility.  They now reside in dbforge().  The use of dbutils for database manipulation

+	 * is STRONGLY discouraged in favour if using dbforge.

+	 *

+	 */

+

+	/**

+	 * Create database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database($name)

+	{

+		return "CREATE DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		return "DROP DATABASE ".$name;

+	}

 

 }

-

 ?>
\ No newline at end of file
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index ebed813..d295ca9 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -35,7 +35,7 @@
 	 * database engines, so this string appears in each driver and is

 	 * used for the count_all() and count_all_results() functions.

 	 */

-	var $_count_string = "SELECT COUNT(*) AS numrows ";

+	var $_count_string = "SELECT COUNT(*) AS ";

 	var $_random_keyword = ' RAND()'; // database specific random keyword

 

 	/**

@@ -87,6 +87,22 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Set client character set

+	 *

+	 * @access	public

+	 * @param	string

+	 * @param	string

+	 * @return	resource

+	 */

+	function db_set_charset($charset, $collation)

+	{

+		// TODO - add support if needed

+		return TRUE;

+	}

+

+	// --------------------------------------------------------------------

+	

+	/**

 	 * Version number query string

 	 *

 	 * @access	public

@@ -307,15 +323,16 @@
 	 * Generates a platform-specific query string so that the table names can be fetched

 	 *

 	 * @access	private

+	 * @param	boolean

 	 * @return	string

 	 */

 	function _list_tables($prefix_limit = FALSE)

 	{

 		$sql = "SHOW TABLES FROM `".$this->database."`";	

 		

-		if ($prefix_limit !== FALSE AND $this->_stdprefix != '')

+		if ($prefix_limit !== FALSE AND $this->dbprefix != '')

 		{

-			$sql .= " LIKE '".$this->_stdprefix."%'";

+			$sql .= " LIKE '".$this->dbprefix."%'";

 		}

 		

 		return $sql;

@@ -404,6 +421,58 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Protect Identifiers

+	 *

+	 * This function adds backticks if appropriate based on db type

+	 *

+	 * @access	private

+	 * @param	mixed	the item to escape

+	 * @param	boolean	only affect the first word

+	 * @return	mixed	the item with backticks

+	 */

+	function _protect_identifiers($item, $first_word_only = FALSE)

+	{

+		if (is_array($item))

+		{

+			$escaped_array = array();

+

+			foreach($item as $k=>$v)

+			{

+				$escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only);

+			}

+

+			return $escaped_array;

+		}	

+

+		// This function may get "item1 item2" as a string, and so

+		// we may need "`item1` `item2`" and not "`item1 item2`"

+		if (strpos($item, ' ') !== FALSE)

+		{

+			// This function may get "field >= 1", and need it to return "`field` >= 1"

+			if ($first_word_only === TRUE)

+			{

+				return '`'.preg_replace('/ /', '` ', $item, 1);

+			}

+

+			$item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item);

+		}

+

+		$exceptions = array('AS', '/', '-', '%', '+', '*');

+		

+		foreach ($exceptions as $exception)

+		{

+			if (stristr($item, " `{$exception}` ") !== FALSE)

+			{

+				$item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item);

+			}

+		}

+		

+		return $item;

+	}

+			

+	// --------------------------------------------------------------------

+

+	/**

 	 * Insert statement

 	 *

 	 * Generates a platform-specific insert string from the supplied data

@@ -430,9 +499,11 @@
 	 * @param	string	the table name

 	 * @param	array	the update data

 	 * @param	array	the where clause

+	 * @param	array	the orderby clause

+	 * @param	array	the limit clause

 	 * @return	string

 	 */

-	function _update($table, $values, $where, $limit = FALSE)

+	function _update($table, $values, $where, $orderby = array(), $limit = FALSE)

 	{

 		foreach($values as $key => $val)

 		{

@@ -440,8 +511,29 @@
 		}

 		

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

+		

+		$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';

 	

-		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;

+		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit;

+	}

+

+	

+	// --------------------------------------------------------------------

+

+	/**

+	 * Truncate statement

+	 *

+	 * Generates a platform-specific truncate string from the supplied data

+	 * If the database does not support the truncate() command

+	 * This function maps to "DELETE FROM table"

+	 *

+	 * @access	public

+	 * @param	string	the table name

+	 * @return	string

+	 */	

+	function _truncate($table)

+	{

+		return "TRUNCATE ".$this->_escape_table($table);

 	}

 	

 	// --------------------------------------------------------------------

@@ -454,13 +546,28 @@
 	 * @access	public

 	 * @param	string	the table name

 	 * @param	array	the where clause

+	 * @param	string	the limit clause

 	 * @return	string

 	 */	

-	function _delete($table, $where, $limit = FALSE)

+	function _delete($table, $where = array(), $like = array(), $limit = FALSE)

 	{

+		$conditions = '';

+

+		if (count($where) > 0 || count($like) > 0)

+		{

+			$conditions = "\nWHERE ";

+			$conditions .= implode("\n", $this->ar_where);

+

+			if (count($where) > 0 && count($like) > 0)

+			{

+				$conditions .= " AND ";

+			}

+			$conditions .= implode("\n", $like);

+		}

+

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

 	

-		return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;

+		return "DELETE FROM ".$table.$conditions.$limit;

 	}

 

 	// --------------------------------------------------------------------

diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
new file mode 100644
index 0000000..3da5d2c
--- /dev/null
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -0,0 +1,217 @@
+<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

+/**

+ * CodeIgniter

+ *

+ * An open source application development framework for PHP 4.3.2 or newer

+ *

+ * @package		CodeIgniter

+ * @author		Rick Ellis

+ * @copyright	Copyright (c) 2006, EllisLab, Inc.

+ * @license		http://www.codeigniter.com/user_guide/license.html

+ * @link		http://www.codeigniter.com

+ * @since		Version 1.0

+ * @filesource

+ */

+

+// ------------------------------------------------------------------------

+

+/**

+ * MySQLi Forge Class

+ *

+ * @category	Database

+ * @author		Rick Ellis

+ * @link		http://www.codeigniter.com/user_guide/database/

+ */

+class CI_DB_mysqli_forge extends CI_DB_forge {

+	

+	/**

+	 * Create database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database($name)

+	{

+		return "CREATE DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		return "DROP DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop Table

+	 *

+	 * @access	private

+	 * @return	bool

+	 */

+	function _drop_table($table)

+	{

+		return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table);

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Create Table

+	 *

+	 * @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

+	 */

+	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)." (";

+		$current_field_count = 0;

+

+		foreach ($fields as $field=>$attributes)

+		{

+			// Numeric field names aren't allowed in databases, so if the key is

+			// numeric, we know it was assigned by PHP and the developer manually

+			// entered the field information, so we'll simply add it to the list

+			if (is_numeric($field))

+			{

+				$sql .= "\n\t$attributes";

+			}

+			else

+			{

+				$attributes = array_change_key_case($attributes, CASE_UPPER);

+				

+				$sql .= "\n\t".$this->db->_protect_identifiers($field);

+				

+				$sql .=  ' '.$attributes['TYPE'];

+	

+				if (array_key_exists('CONSTRAINT', $attributes))

+				{

+					$sql .= '('.$attributes['CONSTRAINT'].')';

+				}

+	

+				if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)

+				{

+					$sql .= ' UNSIGNED';

+				}

+	

+				if (array_key_exists('DEFAULT', $attributes))

+				{

+					$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';

+				}

+	

+				if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)

+				{

+					$sql .= ' NULL';

+				}

+				else

+				{

+					$sql .= ' NOT NULL';			

+				}

+	

+				if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)

+				{

+					$sql .= ' AUTO_INCREMENT';

+				}

+			}

+			

+			// don't add a comma on the end of the last field

+			if (++$current_field_count < count($fields))

+			{

+				$sql .= ',';

+			}

+		}

+

+		if (count($primary_keys) > 0)

+		{

+			$primary_keys = $this->db->_protect_identifiers($primary_keys);

+			$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";

+		}

+

+		if (is_array($keys) && count($keys) > 0)

+		{

+			$keys = $this->db->_protect_identifiers($keys);

+			foreach ($keys as $key)

+			{

+				$sql .= ",\n\tKEY ($key)";

+			}

+		}

+

+		$sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};";

+

+		return $sql;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Alter table query

+	 *

+	 * Generates a platform-specific query so that a table can be altered

+	 * Called by add_column(), drop_column(), and column_alter(),

+	 *

+	 * @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	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 = '')

+	{

+		$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);

+

+		// DROP has everything it needs now.

+		if ($alter_type == 'DROP')

+		{

+			return $sql;

+		}

+

+		$sql .= " $column_definition";

+

+		if ($default_value != '')

+		{

+			$sql .= " DEFAULT \"$default_value\"";

+		}

+

+		if ($null === NULL)

+		{

+			$sql .= ' NULL';

+		}

+		else

+		{

+			$sql .= ' NOT NULL';

+		}

+

+		if ($after_field != '')

+		{

+			$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);

+		}

+		

+		return $sql;		

+	}

+}

+?>
\ No newline at end of file
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index c904e92..1d91063 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -25,47 +25,6 @@
 class CI_DB_mysqli_utility extends CI_DB_utility {

 	

 	/**

-	 * Create database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _create_database($name)

-	{

-		return "CREATE DATABASE ".$name;

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

-	 * Drop database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _drop_database($name)

-	{

-		return "DROP DATABASE ".$name;

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

-	 * Drop Table

-	 *

-	 * @access	private

-	 * @return	bool

-	 */

-	function _drop_table($table)

-	{

-		return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table);

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

 	 * List databases

 	 *

 	 * @access	private

@@ -187,9 +146,10 @@
 			$is_int = array();

 			while ($field = mysqli_fetch_field($query->result_id))

 			{

+				// Most versions of MySQL store timestamp as a string

 				$is_int[$i] = (in_array(

 										strtolower(mysql_field_type($query->result_id, $i)),

-										array('tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'timestamp'),

+										array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), // 'timestamp'),

 										TRUE)

 										) ? TRUE : FALSE;

 										

@@ -255,8 +215,39 @@
 		return $output;

 	}

 

+	/**

+	 *

+	 * The functions below have been deprecated as of 1.6, and are only here for backwards

+	 * compatibility.  They now reside in dbforge().  The use of dbutils for database manipulation

+	 * is STRONGLY discouraged in favour if using dbforge.

+	 *

+	 */

 

+	/**

+	 * Create database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database($name)

+	{

+		return "CREATE DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		return "DROP DATABASE ".$name;

+	}

 

 }

-

 ?>
\ No newline at end of file
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index c4ab700..6d3b722 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -48,7 +48,8 @@
 	 * database engines, so this string appears in each driver and is

 	 * used for the count_all() and count_all_results() functions.

 	 */

-	var $_count_string = "SELECT COUNT(1) AS numrows ";

+	var $_count_string = "SELECT COUNT(1) AS ";

+	var $_random_keyword = ' ASC'; // not currently supported

 

 	// Set "auto commit" by default

 	var $_commit = OCI_COMMIT_ON_SUCCESS;

@@ -101,6 +102,22 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Set client character set

+	 *

+	 * @access	public

+	 * @param	string

+	 * @param	string

+	 * @return	resource

+	 */

+	function db_set_charset($charset, $collation)

+	{

+		// TODO - add support if needed

+		return TRUE;

+	}

+

+	// --------------------------------------------------------------------

+	

+	/**

 	 * Version number query string

 	 *

 	 * @access  public

@@ -415,11 +432,19 @@
 	 * Generates a platform-specific query string so that the table names can be fetched

 	 *

 	 * @access  private

+	 * @param	boolean

 	 * @return  string

 	 */

-	function _list_tables()

+	function _list_tables($prefix_limit = FALSE)

 	{

-		return "SELECT TABLE_NAME FROM ALL_TABLES";

+		$sql = "SELECT TABLE_NAME FROM ALL_TABLES";

+

+		if ($prefix_limit !== FALSE AND $this->dbprefix != '')

+		{

+			$sql .= " WHERE TABLE_NAME LIKE '".$this->dbprefix."%'";

+		}

+		

+		return $sql;

 	}

 

 	// --------------------------------------------------------------------

@@ -507,6 +532,58 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Protect Identifiers

+	 *

+	 * This function adds backticks if appropriate based on db type

+	 *

+	 * @access	private

+	 * @param	mixed	the item to escape

+	 * @param	boolean	only affect the first word

+	 * @return	mixed	the item with backticks

+	 */

+	function _protect_identifiers($item, $first_word_only = FALSE)

+	{

+		if (is_array($item))

+		{

+			$escaped_array = array();

+

+			foreach($item as $k=>$v)

+			{

+				$escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only);

+			}

+

+			return $escaped_array;

+		}	

+

+		// This function may get "item1 item2" as a string, and so

+		// we may need "`item1` `item2`" and not "`item1 item2`"

+		if (strpos($item, ' ') !== FALSE)

+		{

+			// This function may get "field >= 1", and need it to return "`field` >= 1"

+			if ($first_word_only === TRUE)

+			{

+				return '`'.preg_replace('/ /', '` ', $item, 1);

+			}

+

+			$item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item);

+		}

+

+		$exceptions = array('AS', '/', '-', '%', '+', '*');

+		

+		foreach ($exceptions as $exception)

+		{

+			if (stristr($item, " `{$exception}` ") !== FALSE)

+			{

+				$item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item);

+			}

+		}

+		

+		return $item;

+	}

+			

+	// --------------------------------------------------------------------

+

+	/**

 	 * Insert statement

 	 *

 	 * Generates a platform-specific insert string from the supplied data

@@ -529,13 +606,15 @@
 	 *

 	 * Generates a platform-specific 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

+	 * @access	public

+	 * @param	string	the table name

+	 * @param	array	the update data

+	 * @param	array	the where clause

+	 * @param	array	the orderby clause

+	 * @param	array	the limit clause

+	 * @return	string

 	 */

-	function _update($table, $values, $where, $limit = FALSE)

+	function _update($table, $values, $where, $orderby = array(), $limit = FALSE)

 	{

 		foreach($values as $key => $val)

 		{

@@ -543,27 +622,62 @@
 		}

 		

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

+		

+		$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';

 	

-		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;

+		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit;

 	}

 

 	// --------------------------------------------------------------------

 

 	/**

+	 * Truncate statement

+	 *

+	 * Generates a platform-specific truncate string from the supplied data

+	 * If the database does not support the truncate() command

+	 * This function maps to "DELETE FROM table"

+	 *

+	 * @access	public

+	 * @param	string	the table name

+	 * @return	string

+	 */	

+	function _truncate($table)

+	{

+		return "TRUNCATE TABLE ".$this->_escape_table($table);

+	}

+	

+	// --------------------------------------------------------------------

+

+	/**

 	 * Delete statement

 	 *

 	 * Generates a platform-specific delete string from the supplied data

 	 *

-	 * @access  public

-	 * @param   string  the table name

-	 * @param   array   the where clause

-	 * @return  string

-	 */

-	function _delete($table, $where, $limit = FALSE)

+	 * @access	public

+	 * @param	string	the table name

+	 * @param	array	the where clause

+	 * @param	string	the limit clause

+	 * @return	string

+	 */	

+	function _delete($table, $where = array(), $like = array(), $limit = FALSE)

 	{

+		$conditions = '';

+

+		if (count($where) > 0 || count($like) > 0)

+		{

+			$conditions = "\nWHERE ";

+			$conditions .= implode("\n", $this->ar_where);

+

+			if (count($where) > 0 && count($like) > 0)

+			{

+				$conditions .= " AND ";

+			}

+			$conditions .= implode("\n", $like);

+		}

+

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

 	

-		return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;

+		return "DELETE FROM ".$table.$conditions.$limit;

 	}

 

 	// --------------------------------------------------------------------

diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php
new file mode 100644
index 0000000..c982e66
--- /dev/null
+++ b/system/database/drivers/oci8/oci8_forge.php
@@ -0,0 +1,216 @@
+<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

+/**

+ * CodeIgniter

+ *

+ * An open source application development framework for PHP 4.3.2 or newer

+ *

+ * @package		CodeIgniter

+ * @author		Rick Ellis

+ * @copyright	Copyright (c) 2006, EllisLab, Inc.

+ * @license		http://www.codeigniter.com/user_guide/license.html

+ * @link		http://www.codeigniter.com

+ * @since		Version 1.0

+ * @filesource

+ */

+

+// ------------------------------------------------------------------------

+

+/**

+ * Oracle Forge Class

+ *

+ * @category	Database

+ * @author		Rick Ellis

+ * @link		http://www.codeigniter.com/user_guide/database/

+ */

+class CI_DB_oci8_forge extends CI_DB_forge {

+

+	/**

+	 * Create database

+	 *

+	 * @access	public

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database($name)

+	{

+		return FALSE;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		return FALSE;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Create Table

+	 *

+	 * @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

+	 */

+	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)." (";

+		$current_field_count = 0;

+

+		foreach ($fields as $field=>$attributes)

+		{

+			// Numeric field names aren't allowed in databases, so if the key is

+			// numeric, we know it was assigned by PHP and the developer manually

+			// entered the field information, so we'll simply add it to the list

+			if (is_numeric($field))

+			{

+				$sql .= "\n\t$attributes";

+			}

+			else

+			{

+				$attributes = array_change_key_case($attributes, CASE_UPPER);

+				

+				$sql .= "\n\t".$this->db->_protect_identifiers($field);

+				

+				$sql .=  ' '.$attributes['TYPE'];

+	

+				if (array_key_exists('CONSTRAINT', $attributes))

+				{

+					$sql .= '('.$attributes['CONSTRAINT'].')';

+				}

+	

+				if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)

+				{

+					$sql .= ' UNSIGNED';

+				}

+	

+				if (array_key_exists('DEFAULT', $attributes))

+				{

+					$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';

+				}

+	

+				if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)

+				{

+					$sql .= ' NULL';

+				}

+				else

+				{

+					$sql .= ' NOT NULL';			

+				}

+	

+				if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)

+				{

+					$sql .= ' AUTO_INCREMENT';

+				}

+			}

+			

+			// don't add a comma on the end of the last field

+			if (++$current_field_count < count($fields))

+			{

+				$sql .= ',';

+			}

+		}

+

+		if (count($primary_keys) > 0)

+		{

+			$primary_keys = $this->db->_protect_identifiers($primary_keys);

+			$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";

+		}

+

+		if (count($keys) > 0)

+		{

+			$keys = $this->db->_protect_identifiers($keys);

+			$sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $keys) . ")";

+		}

+		

+		$sql .= "\n)";

+

+		return $sql;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop Table

+	 *

+	 * @access	private

+	 * @return	bool

+	 */

+	function _drop_table($table)

+	{

+		return FALSE;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Alter table query

+	 *

+	 * Generates a platform-specific query so that a table can be altered

+	 * Called by add_column(), drop_column(), and column_alter(),

+	 *

+	 * @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	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 = '')

+	{

+		$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);

+

+		// DROP has everything it needs now.

+		if ($alter_type == 'DROP')

+		{

+			return $sql;

+		}

+

+		$sql .= " $column_definition";

+

+		if ($default_value != '')

+		{

+			$sql .= " DEFAULT \"$default_value\"";

+		}

+

+		if ($null === NULL)

+		{

+			$sql .= ' NULL';

+		}

+		else

+		{

+			$sql .= ' NOT NULL';

+		}

+

+		if ($after_field != '')

+		{

+			$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);

+		}

+		

+		return $sql;

+		

+	}

+

+}

+?>
\ No newline at end of file
diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php
index 0f9e4e8..67296da 100644
--- a/system/database/drivers/oci8/oci8_utility.php
+++ b/system/database/drivers/oci8/oci8_utility.php
@@ -24,35 +24,6 @@
  */

 class CI_DB_oci8_utility extends CI_DB_utility {

 

-

-	/**

-	 * Create database

-	 *

-	 * @access	public

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _create_database($name)

-	{

-		return FALSE;

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

-	 * Drop database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _drop_database($name)

-	{

-		return FALSE;

-	}

-

-	// --------------------------------------------------------------------

-

 	/**

 	 * List databases

 	 *

@@ -67,19 +38,6 @@
 	// --------------------------------------------------------------------

 

 	/**

-	 * Drop Table

-	 *

-	 * @access	private

-	 * @return	bool

-	 */

-	function _drop_table($table)

-	{

-		return FALSE;

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

 	 * Optimize table query

 	 *

 	 * Generates a platform-specific query so that a table can be optimized

@@ -124,6 +82,39 @@
 		return $this->db->display_error('db_unsuported_feature');

 	}

 

-}

+	/**

+	 *

+	 * The functions below have been deprecated as of 1.6, and are only here for backwards

+	 * compatibility.  They now reside in dbforge().  The use of dbutils for database manipulation

+	 * is STRONGLY discouraged in favour if using dbforge.

+	 *

+	 */

 

+	/**

+	 * Create database

+	 *

+	 * @access	public

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database($name)

+	{

+		return FALSE;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		return FALSE;

+	}

+

+}

 ?>
\ No newline at end of file
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 040ffed..0bdfc41 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -35,8 +35,14 @@
 	 * database engines, so this string appears in each driver and is

 	 * used for the count_all() and count_all_results() functions.

 	 */

-	var $_count_string = "SELECT COUNT(*) AS numrows ";

-	var $_random_keyword = ' RND('.time().')'; // database specific random keyword

+	var $_count_string = "SELECT COUNT(*) AS ";

+	var $_random_keyword;

+

+

+	function CI_DB_odbc_driver()

+	{

+		$_random_keyword = ' RND('.time().')'; // database specific random keyword

+	}

 

 	/**

 	 * Non-persistent database connection

@@ -79,6 +85,22 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Set client character set

+	 *

+	 * @access	public

+	 * @param	string

+	 * @param	string

+	 * @return	resource

+	 */

+	function db_set_charset($charset, $collation)

+	{

+		// TODO - add support if needed

+		return TRUE;

+	}

+

+	// --------------------------------------------------------------------

+	

+	/**

 	 * Version number query string

 	 *

 	 * @access	public

@@ -276,11 +298,20 @@
 	 * Generates a platform-specific query string so that the table names can be fetched

 	 *

 	 * @access	private

+	 * @param	boolean

 	 * @return	string

 	 */

-	function _list_tables()

+	function _list_tables($prefix_limit = FALSE)

 	{

-		return "SHOW TABLES FROM `".$this->database."`";		

+		$sql = "SHOW TABLES FROM `".$this->database."`";

+

+		if ($prefix_limit !== FALSE AND $this->dbprefix != '')

+		{

+			//$sql .= " LIKE '".$this->dbprefix."%'";

+			return FALSE; // not currently supported

+		}

+		

+		return $sql;

 	}

 	

 	// --------------------------------------------------------------------

@@ -366,6 +397,58 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Protect Identifiers

+	 *

+	 * This function adds backticks if appropriate based on db type

+	 *

+	 * @access	private

+	 * @param	mixed	the item to escape

+	 * @param	boolean	only affect the first word

+	 * @return	mixed	the item with backticks

+	 */

+	function _protect_identifiers($item, $first_word_only = FALSE)

+	{

+		if (is_array($item))

+		{

+			$escaped_array = array();

+

+			foreach($item as $k=>$v)

+			{

+				$escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only);

+			}

+

+			return $escaped_array;

+		}	

+

+		// This function may get "item1 item2" as a string, and so

+		// we may need "`item1` `item2`" and not "`item1 item2`"

+		if (strpos($item, ' ') !== FALSE)

+		{

+			// This function may get "field >= 1", and need it to return "`field` >= 1"

+			if ($first_word_only === TRUE)

+			{

+				return '`'.preg_replace('/ /', '` ', $item, 1);

+			}

+

+			$item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item);

+		}

+

+		$exceptions = array('AS', '/', '-', '%', '+', '*');

+		

+		foreach ($exceptions as $exception)

+		{

+			if (stristr($item, " `{$exception}` ") !== FALSE)

+			{

+				$item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item);

+			}

+		}

+		

+		return $item;

+	}

+			

+	// --------------------------------------------------------------------

+

+	/**

 	 * Insert statement

 	 *

 	 * Generates a platform-specific insert string from the supplied data

@@ -392,9 +475,11 @@
 	 * @param	string	the table name

 	 * @param	array	the update data

 	 * @param	array	the where clause

+	 * @param	array	the orderby clause

+	 * @param	array	the limit clause

 	 * @return	string

 	 */

-	function _update($table, $values, $where, $limit = FALSE)

+	function _update($table, $values, $where, $orderby = array(), $limit = FALSE)

 	{

 		foreach($values as $key => $val)

 		{

@@ -402,8 +487,29 @@
 		}

 		

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

+		

+		$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';

 	

-		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;

+		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit;

+	}

+

+	

+	// --------------------------------------------------------------------

+

+	/**

+	 * Truncate statement

+	 *

+	 * Generates a platform-specific truncate string from the supplied data

+	 * If the database does not support the truncate() command

+	 * This function maps to "DELETE FROM table"

+	 *

+	 * @access	public

+	 * @param	string	the table name

+	 * @return	string

+	 */	

+	function _truncate($table)

+	{

+		return $this->_delete($table);

 	}

 	

 	// --------------------------------------------------------------------

@@ -416,13 +522,28 @@
 	 * @access	public

 	 * @param	string	the table name

 	 * @param	array	the where clause

+	 * @param	string	the limit clause

 	 * @return	string

 	 */	

-	function _delete($table, $where, $limit = FALSE)

+	function _delete($table, $where = array(), $like = array(), $limit = FALSE)

 	{

+		$conditions = '';

+

+		if (count($where) > 0 || count($like) > 0)

+		{

+			$conditions = "\nWHERE ";

+			$conditions .= implode("\n", $this->ar_where);

+

+			if (count($where) > 0 && count($like) > 0)

+			{

+				$conditions .= " AND ";

+			}

+			$conditions .= implode("\n", $like);

+		}

+

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

 	

-		return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;

+		return "DELETE FROM ".$table.$conditions.$limit;

 	}

 

 	// --------------------------------------------------------------------

diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php
new file mode 100644
index 0000000..1d79344
--- /dev/null
+++ b/system/database/drivers/odbc/odbc_forge.php
@@ -0,0 +1,236 @@
+<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

+/**

+ * CodeIgniter

+ *

+ * An open source application development framework for PHP 4.3.2 or newer

+ *

+ * @package		CodeIgniter

+ * @author		Rick Ellis

+ * @copyright	Copyright (c) 2006, EllisLab, Inc.

+ * @license		http://www.codeigniter.com/user_guide/license.html

+ * @link		http://www.codeigniter.com

+ * @since		Version 1.0

+ * @filesource

+ */

+

+// ------------------------------------------------------------------------

+

+/**

+ * ODBC Forge Class

+ *

+ * @category	Database

+ * @author		Rick Ellis

+ * @link		http://www.codeigniter.com/database/

+ */

+class CI_DB_odbc_forge extends CI_DB_forge {

+

+	/**

+	 * Create database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database()

+	{

+		// ODBC has no "create database" command since it's

+		// designed to connect to an existing database

+		if ($this->db->db_debug)

+		{

+			return $this->db->display_error('db_unsuported_feature');

+		}

+		return FALSE;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		// ODBC has no "drop database" command since it's

+		// designed to connect to an existing database		

+		if ($this->db->db_debug)

+		{

+			return $this->db->display_error('db_unsuported_feature');

+		}

+		return FALSE;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Create Table

+	 *

+	 * @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

+	 */

+	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)." (";

+		$current_field_count = 0;

+

+		foreach ($fields as $field=>$attributes)

+		{

+			// Numeric field names aren't allowed in databases, so if the key is

+			// numeric, we know it was assigned by PHP and the developer manually

+			// entered the field information, so we'll simply add it to the list

+			if (is_numeric($field))

+			{

+				$sql .= "\n\t$attributes";

+			}

+			else

+			{

+				$attributes = array_change_key_case($attributes, CASE_UPPER);

+				

+				$sql .= "\n\t".$this->db->_protect_identifiers($field);

+				

+				$sql .=  ' '.$attributes['TYPE'];

+	

+				if (array_key_exists('CONSTRAINT', $attributes))

+				{

+					$sql .= '('.$attributes['CONSTRAINT'].')';

+				}

+	

+				if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)

+				{

+					$sql .= ' UNSIGNED';

+				}

+	

+				if (array_key_exists('DEFAULT', $attributes))

+				{

+					$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';

+				}

+	

+				if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)

+				{

+					$sql .= ' NULL';

+				}

+				else

+				{

+					$sql .= ' NOT NULL';			

+				}

+	

+				if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)

+				{

+					$sql .= ' AUTO_INCREMENT';

+				}

+			}

+			

+			// don't add a comma on the end of the last field

+			if (++$current_field_count < count($fields))

+			{

+				$sql .= ',';

+			}

+		}

+

+		if (count($primary_keys) > 0)

+		{

+			$primary_keys = $this->db->_protect_identifiers($primary_keys);

+			$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";

+		}

+

+		if (is_array($keys) && count($keys) > 0)

+		{

+			$keys = $this->db->_protect_identifiers($keys);

+			foreach ($keys as $key)

+			{

+				$sql .= ",\n\tFOREIGN KEY ($key)";

+			}

+		}

+

+		$sql .= "\n)";

+

+		return $sql;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop Table

+	 *

+	 * @access	private

+	 * @return	bool

+	 */

+	function _drop_table($table)

+	{

+		// Not a supported ODBC feature	

+		if ($this->db->db_debug)

+		{

+			return $this->db->display_error('db_unsuported_feature');

+		}

+		return FALSE;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Alter table query

+	 *

+	 * Generates a platform-specific query so that a table can be altered

+	 * Called by add_column(), drop_column(), and column_alter(),

+	 *

+	 * @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	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 = '')

+	{

+		$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);

+

+		// DROP has everything it needs now.

+		if ($alter_type == 'DROP')

+		{

+			return $sql;

+		}

+

+		$sql .= " $column_definition";

+

+		if ($default_value != '')

+		{

+			$sql .= " DEFAULT \"$default_value\"";

+		}

+

+		if ($null === NULL)

+		{

+			$sql .= ' NULL';

+		}

+		else

+		{

+			$sql .= ' NOT NULL';

+		}

+

+		if ($after_field != '')

+		{

+			$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);

+		}

+		

+		return $sql;

+		

+	}

+

+}

+?>
\ No newline at end of file
diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php
index e909fd7..53c3173 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -192,7 +192,6 @@
 	 * @access	private

 	 * @return	object

 	 */

-

 	function _odbc_fetch_object(& $odbc_result) {

 		$rs = array();

 		$rs_obj = false;

@@ -215,7 +214,6 @@
 	 * @access	private

 	 * @return	array

 	 */

-

 	function _odbc_fetch_array(& $odbc_result) {

 		$rs = array();

 		$rs_assoc = false;

diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php
index 97e950f..d64d15a 100644
--- a/system/database/drivers/odbc/odbc_utility.php
+++ b/system/database/drivers/odbc/odbc_utility.php
@@ -24,47 +24,6 @@
  */

 class CI_DB_odbc_utility extends CI_DB_utility {

 

-

-	/**

-	 * Create database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _create_database()

-	{

-		// ODBC has no "create database" command since it's

-		// designed to connect to an existing database

-		if ($this->db->db_debug)

-		{

-			return $this->db->display_error('db_unsuported_feature');

-		}

-		return FALSE;

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

-	 * Drop database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _drop_database($name)

-	{

-		// ODBC has no "drop database" command since it's

-		// designed to connect to an existing database		

-		if ($this->db->db_debug)

-		{

-			return $this->db->display_error('db_unsuported_feature');

-		}

-		return FALSE;

-	}

-

-	// --------------------------------------------------------------------

-

 	/**

 	 * List databases

 	 *

@@ -84,24 +43,6 @@
 	// --------------------------------------------------------------------

 

 	/**

-	 * Drop Table

-	 *

-	 * @access	private

-	 * @return	bool

-	 */

-	function _drop_table($table)

-	{

-		// Not a supported ODBC feature	

-		if ($this->db->db_debug)

-		{

-			return $this->db->display_error('db_unsuported_feature');

-		}

-		return FALSE;

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

 	 * Optimize table query

 	 *

 	 * Generates a platform-specific query so that a table can be optimized

@@ -155,7 +96,51 @@
 		// Currently unsupported

 		return $this->db->display_error('db_unsuported_feature');

 	}

+	

+	/**

+	 *

+	 * The functions below have been deprecated as of 1.6, and are only here for backwards

+	 * compatibility.  They now reside in dbforge().  The use of dbutils for database manipulation

+	 * is STRONGLY discouraged in favour if using dbforge.

+	 *

+	 */

 

+	/**

+	 * Create database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database()

+	{

+		// ODBC has no "create database" command since it's

+		// designed to connect to an existing database

+		if ($this->db->db_debug)

+		{

+			return $this->db->display_error('db_unsuported_feature');

+		}

+		return FALSE;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		// ODBC has no "drop database" command since it's

+		// designed to connect to an existing database		

+		if ($this->db->db_debug)

+		{

+			return $this->db->display_error('db_unsuported_feature');

+		}

+		return FALSE;

+	}

 }

-

 ?>
\ No newline at end of file
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 88f08b2..63a72f5 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -35,7 +35,7 @@
 	 * database engines, so this string appears in each driver and is

 	 * used for the count_all() and count_all_results() functions.

 	 */

-	var $_count_string = "SELECT COUNT(*) AS numrows ";

+	var $_count_string = "SELECT COUNT(*) AS ";

 	var $_random_keyword = ' RANDOM()'; // database specific random keyword

 

 	/**

@@ -83,6 +83,22 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Set client character set

+	 *

+	 * @access	public

+	 * @param	string

+	 * @param	string

+	 * @return	resource

+	 */

+	function db_set_charset($charset, $collation)

+	{

+		// TODO - add support if needed

+		return TRUE;

+	}

+

+	// --------------------------------------------------------------------

+	

+	/**

 	 * Version number query string

 	 *

 	 * @access	public

@@ -305,11 +321,19 @@
 	 * Generates a platform-specific query string so that the table names can be fetched

 	 *

 	 * @access	private

+	 * @param	boolean

 	 * @return	string

 	 */

-	function _list_tables()

+	function _list_tables($prefix_limit = FALSE)

 	{	

-		return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";	

+		$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";	

+		

+		if ($prefix_limit !== FALSE AND $this->dbprefix != '')

+		{

+			$sql .= " AND table_name LIKE '".$this->dbprefix."%'";

+		}

+		

+		return $sql;

 	}

 	

 	// --------------------------------------------------------------------

@@ -395,6 +419,58 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Protect Identifiers

+	 *

+	 * This function adds backticks if appropriate based on db type

+	 *

+	 * @access	private

+	 * @param	mixed	the item to escape

+	 * @param	boolean	only affect the first word

+	 * @return	mixed	the item with backticks

+	 */

+	function _protect_identifiers($item, $first_word_only = FALSE)

+	{

+		if (is_array($item))

+		{

+			$escaped_array = array();

+

+			foreach($item as $k=>$v)

+			{

+				$escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only);

+			}

+

+			return $escaped_array;

+		}	

+

+		// This function may get "item1 item2" as a string, and so

+		// we may need ""item1" "item2"" and not ""item1 item2""

+		if (strpos($item, ' ') !== FALSE)

+		{

+			// This function may get "field >= 1", and need it to return ""field" >= 1"

+			if ($first_word_only === TRUE)

+			{

+				return '"'.preg_replace('/ /', '" ', $item, 1);

+			}

+

+			$item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item);

+		}

+

+		$exceptions = array('AS', '/', '-', '%', '+', '*');

+		

+		foreach ($exceptions as $exception)

+		{

+			if (stristr($item, " "{$exception}" ") !== FALSE)

+			{

+				$item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item);

+			}

+		}

+		

+		return $item;

+	}

+			

+	// --------------------------------------------------------------------

+

+	/**

 	 * Insert statement

 	 *

 	 * Generates a platform-specific insert string from the supplied data

@@ -421,9 +497,11 @@
 	 * @param	string	the table name

 	 * @param	array	the update data

 	 * @param	array	the where clause

+	 * @param	array	the orderby clause

+	 * @param	array	the limit clause

 	 * @return	string

 	 */

-	function _update($table, $values, $where, $limit = FALSE)

+	function _update($table, $values, $where, $orderby = array(), $limit = FALSE)

 	{

 		foreach($values as $key => $val)

 		{

@@ -431,8 +509,29 @@
 		}

 		

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

+		

+		$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';

 	

-		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;

+		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit;

+	}

+

+	

+	// --------------------------------------------------------------------

+

+	/**

+	 * Truncate statement

+	 *

+	 * Generates a platform-specific truncate string from the supplied data

+	 * If the database does not support the truncate() command

+	 * This function maps to "DELETE FROM table"

+	 *

+	 * @access	public

+	 * @param	string	the table name

+	 * @return	string

+	 */	

+	function _truncate($table)

+	{

+		return "TRUNCATE ".$this->_escape_table($table);

 	}

 	

 	// --------------------------------------------------------------------

@@ -445,17 +544,31 @@
 	 * @access	public

 	 * @param	string	the table name

 	 * @param	array	the where clause

+	 * @param	string	the limit clause

 	 * @return	string

 	 */	

-	function _delete($table, $where, $limit = FALSE)

+	function _delete($table, $where = array(), $like = array(), $limit = FALSE)

 	{

+		$conditions = '';

+

+		if (count($where) > 0 || count($like) > 0)

+		{

+			$conditions = "\nWHERE ";

+			$conditions .= implode("\n", $this->ar_where);

+

+			if (count($where) > 0 && count($like) > 0)

+			{

+				$conditions .= " AND ";

+			}

+			$conditions .= implode("\n", $like);

+		}

+

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

 	

-		return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;

+		return "DELETE FROM ".$table.$conditions.$limit;

 	}

 

 	// --------------------------------------------------------------------

-

 	/**

 	 * Limit string

 	 *

diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php
new file mode 100644
index 0000000..34bbe88
--- /dev/null
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -0,0 +1,219 @@
+<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

+/**

+ * CodeIgniter

+ *

+ * An open source application development framework for PHP 4.3.2 or newer

+ *

+ * @package		CodeIgniter

+ * @author		Rick Ellis

+ * @copyright	Copyright (c) 2006, EllisLab, Inc.

+ * @license		http://www.codeigniter.com/user_guide/license.html

+ * @link		http://www.codeigniter.com

+ * @since		Version 1.0

+ * @filesource

+ */

+

+// ------------------------------------------------------------------------

+

+/**

+ * Postgre Forge Class

+ *

+ * @category	Database

+ * @author		Rick Ellis

+ * @link		http://www.codeigniter.com/user_guide/database/

+ */

+class CI_DB_postgre_forge extends CI_DB_forge {

+

+	/**

+	 * Create database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database($name)

+	{

+		return "CREATE DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		return "DROP DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Create Table

+	 *

+	 * @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

+	 */

+	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)." (";

+		$current_field_count = 0;

+

+		foreach ($fields as $field=>$attributes)

+		{

+			// Numeric field names aren't allowed in databases, so if the key is

+			// numeric, we know it was assigned by PHP and the developer manually

+			// entered the field information, so we'll simply add it to the list

+			if (is_numeric($field))

+			{

+				$sql .= "\n\t$attributes";

+			}

+			else

+			{

+				$attributes = array_change_key_case($attributes, CASE_UPPER);

+				

+				$sql .= "\n\t".$this->db->_protect_identifiers($field);

+				

+				$sql .=  ' '.$attributes['TYPE'];

+	

+				if (array_key_exists('CONSTRAINT', $attributes))

+				{

+					$sql .= '('.$attributes['CONSTRAINT'].')';

+				}

+	

+				if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)

+				{

+					$sql .= ' UNSIGNED';

+				}

+	

+				if (array_key_exists('DEFAULT', $attributes))

+				{

+					$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';

+				}

+	

+				if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)

+				{

+					$sql .= ' NULL';

+				}

+				else

+				{

+					$sql .= ' NOT NULL';			

+				}

+	

+				if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)

+				{

+					$sql .= ' AUTO_INCREMENT';

+				}

+			}

+			

+			// don't add a comma on the end of the last field

+			if (++$current_field_count < count($fields))

+			{

+				$sql .= ',';

+			}

+		}

+

+		if (count($primary_keys) > 0)

+		{

+			$primary_keys = $this->db->_protect_identifiers($primary_keys);

+			$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";

+		}

+

+		if (is_array($keys) && count($keys) > 0)

+		{

+			$keys = $this->db->_protect_identifiers($keys);

+			foreach ($keys as $key)

+			{

+				$sql .= ",\n\tFOREIGN KEY ($key)";

+			}

+		}

+

+		$sql .= "\n);";

+

+		return $sql;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop Table

+	 *

+	 * @access	private

+	 * @return	bool

+	 */

+	function _drop_table($table)

+	{

+		return "DROP TABLE ".$this->db->_escape_table($table)." CASCADE";

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Alter table query

+	 *

+	 * Generates a platform-specific query so that a table can be altered

+	 * Called by add_column(), drop_column(), and column_alter(),

+	 *

+	 * @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	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 = '')

+	{

+		$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);

+

+		// DROP has everything it needs now.

+		if ($alter_type == 'DROP')

+		{

+			return $sql;

+		}

+

+		$sql .= " $column_definition";

+

+		if ($default_value != '')

+		{

+			$sql .= " DEFAULT \"$default_value\"";

+		}

+

+		if ($null === NULL)

+		{

+			$sql .= ' NULL';

+		}

+		else

+		{

+			$sql .= ' NOT NULL';

+		}

+

+		if ($after_field != '')

+		{

+			$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);

+		}

+		

+		return $sql;

+		

+	}

+

+}

+?>
\ No newline at end of file
diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php
index fa5960e..a706d95 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -24,35 +24,6 @@
  */

 class CI_DB_postgre_utility extends CI_DB_utility {

 

-	

-	/**

-	 * Create database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _create_database($name)

-	{

-		return "CREATE DATABASE ".$name;

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

-	 * Drop database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _drop_database($name)

-	{

-		return "DROP DATABASE ".$name;

-	}

-

-	// --------------------------------------------------------------------

-

 	/**

 	 * List databases

 	 *

@@ -67,19 +38,6 @@
 	// --------------------------------------------------------------------

 

 	/**

-	 * Drop Table

-	 *

-	 * @access	private

-	 * @return	bool

-	 */

-	function _drop_table($table)

-	{

-		return "DROP TABLE ".$this->db->_escape_table($table)." CASCADE";

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

 	 * Optimize table query

 	 *

 	 * Is table optimization supported in Postgre?

@@ -124,6 +82,41 @@
 		return $this->db->display_error('db_unsuported_feature');

 	}

 

+	/**

+	 *

+	 * The functions below have been deprecated as of 1.6, and are only here for backwards

+	 * compatibility.  They now reside in dbforge().  The use of dbutils for database manipulation

+	 * is STRONGLY discouraged in favour if using dbforge.

+	 *

+	 */

+

+	/**

+	 * Create database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database($name)

+	{

+		return "CREATE DATABASE ".$name;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		return "DROP DATABASE ".$name;

+	}

+

+

 }

 

 ?>
\ 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 6189b1f..2d0ca15 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -37,7 +37,7 @@
 	 * database engines, so this string appears in each driver and is

 	 * used for the count_all() and count_all_results() functions.

 	 */

-	var $_count_string = "SELECT COUNT(*) AS numrows ";

+	var $_count_string = "SELECT COUNT(*) AS ";

 	var $_random_keyword = ' Random()'; // database specific random keyword

 

 	/**

@@ -104,6 +104,22 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Set client character set

+	 *

+	 * @access	public

+	 * @param	string

+	 * @param	string

+	 * @return	resource

+	 */

+	function db_set_charset($charset, $collation)

+	{

+		// TODO - add support if needed

+		return TRUE;

+	}

+

+	// --------------------------------------------------------------------

+	

+	/**

 	 * Version number query string

 	 *

 	 * @access	public

@@ -299,11 +315,18 @@
 	 * Generates a platform-specific query string so that the table names can be fetched

 	 *

 	 * @access	private

+	 * @param	boolean

 	 * @return	string

 	 */

-	function _list_tables()

+	function _list_tables($prefix_limit = FALSE)

 	{

-		return "SELECT name from sqlite_master WHERE type='table'";

+		$sql = "SELECT name from sqlite_master WHERE type='table'";

+

+		if ($prefix_limit !== FALSE AND $this->dbprefix != '')

+		{

+			$sql .= " AND 'name' LIKE '".$this->dbprefix."%'";

+		}

+		return $sql;

 	}

 

 	// --------------------------------------------------------------------

@@ -390,6 +413,58 @@
 	// --------------------------------------------------------------------

 

 	/**

+	 * Protect Identifiers

+	 *

+	 * This function adds backticks if appropriate based on db type

+	 *

+	 * @access	private

+	 * @param	mixed	the item to escape

+	 * @param	boolean	only affect the first word

+	 * @return	mixed	the item with backticks

+	 */

+	function _protect_identifiers($item, $first_word_only = FALSE)

+	{

+		if (is_array($item))

+		{

+			$escaped_array = array();

+

+			foreach($item as $k=>$v)

+			{

+				$escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only);

+			}

+

+			return $escaped_array;

+		}	

+

+		// This function may get "item1 item2" as a string, and so

+		// we may need "`item1` `item2`" and not "`item1 item2`"

+		if (strpos($item, ' ') !== FALSE)

+		{

+			// This function may get "field >= 1", and need it to return "`field` >= 1"

+			if ($first_word_only === TRUE)

+			{

+				return '`'.preg_replace('/ /', '` ', $item, 1);

+			}

+

+			$item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item);

+		}

+

+		$exceptions = array('AS', '/', '-', '%', '+', '*');

+		

+		foreach ($exceptions as $exception)

+		{

+			if (stristr($item, " `{$exception}` ") !== FALSE)

+			{

+				$item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item);

+			}

+		}

+		

+		return $item;

+	}

+			

+	// --------------------------------------------------------------------

+

+	/**

 	 * Insert statement

 	 *

 	 * Generates a platform-specific insert string from the supplied data

@@ -416,9 +491,11 @@
 	 * @param	string	the table name

 	 * @param	array	the update data

 	 * @param	array	the where clause

+	 * @param	array	the orderby clause

+	 * @param	array	the limit clause

 	 * @return	string

 	 */

-	function _update($table, $values, $where, $limit = FALSE)

+	function _update($table, $values, $where, $orderby = array(), $limit = FALSE)

 	{

 		foreach($values as $key => $val)

 		{

@@ -426,8 +503,29 @@
 		}

 		

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

+		

+		$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';

 	

-		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;

+		return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit;

+	}

+

+	

+	// --------------------------------------------------------------------

+

+	/**

+	 * Truncate statement

+	 *

+	 * Generates a platform-specific truncate string from the supplied data

+	 * If the database does not support the truncate() command

+	 * This function maps to "DELETE FROM table"

+	 *

+	 * @access	public

+	 * @param	string	the table name

+	 * @return	string

+	 */	

+	function _truncate($table)

+	{

+		return $this->_delete($table);

 	}

 	

 	// --------------------------------------------------------------------

@@ -440,15 +538,30 @@
 	 * @access	public

 	 * @param	string	the table name

 	 * @param	array	the where clause

+	 * @param	string	the limit clause

 	 * @return	string

 	 */	

-	function _delete($table, $where, $limit = FALSE)

+	function _delete($table, $where = array(), $like = array(), $limit = FALSE)

 	{

+		$conditions = '';

+

+		if (count($where) > 0 || count($like) > 0)

+		{

+			$conditions = "\nWHERE ";

+			$conditions .= implode("\n", $this->ar_where);

+

+			if (count($where) > 0 && count($like) > 0)

+			{

+				$conditions .= " AND ";

+			}

+			$conditions .= implode("\n", $like);

+		}

+

 		$limit = (!$limit) ? '' : ' LIMIT '.$limit;

 	

-		return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;

+		return "DELETE FROM ".$table.$conditions.$limit;

 	}

-

+	

 	// --------------------------------------------------------------------

 

 	/**

diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php
new file mode 100644
index 0000000..54b6598
--- /dev/null
+++ b/system/database/drivers/sqlite/sqlite_forge.php
@@ -0,0 +1,233 @@
+<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

+/**

+ * CodeIgniter

+ *

+ * An open source application development framework for PHP 4.3.2 or newer

+ *

+ * @package		CodeIgniter

+ * @author		Rick Ellis

+ * @copyright	Copyright (c) 2006, EllisLab, Inc.

+ * @license		http://www.codeigniter.com/user_guide/license.html

+ * @link		http://www.codeigniter.com

+ * @since		Version 1.0

+ * @filesource

+ */

+

+// ------------------------------------------------------------------------

+

+/**

+ * SQLite Forge Class

+ *

+ * @category	Database

+ * @author		Rick Ellis

+ * @link		http://www.codeigniter.com/user_guide/database/

+ */

+class CI_DB_sqlite_forge extends CI_DB_forge {

+

+	/**

+	 * Create database

+	 *

+	 * @access	public

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database()

+	{

+		// In SQLite, a database is created when you connect to the database.

+		// We'll return TRUE so that an error isn't generated

+		return TRUE;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database))

+		{

+			if ($this->db->db_debug)

+			{

+				return $this->db->display_error('db_unable_to_drop');

+			}

+			return FALSE;

+		}

+		return TRUE;

+	}

+	// --------------------------------------------------------------------

+

+	/**

+	 * Create Table

+	 *

+	 * @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

+	 */

+	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)." (";

+		$current_field_count = 0;

+

+		foreach ($fields as $field=>$attributes)

+		{

+			// Numeric field names aren't allowed in databases, so if the key is

+			// numeric, we know it was assigned by PHP and the developer manually

+			// entered the field information, so we'll simply add it to the list

+			if (is_numeric($field))

+			{

+				$sql .= "\n\t$attributes";

+			}

+			else

+			{

+				$attributes = array_change_key_case($attributes, CASE_UPPER);

+				

+				$sql .= "\n\t".$this->db->_protect_identifiers($field);

+				

+				$sql .=  ' '.$attributes['TYPE'];

+	

+				if (array_key_exists('CONSTRAINT', $attributes))

+				{

+					$sql .= '('.$attributes['CONSTRAINT'].')';

+				}

+	

+				if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)

+				{

+					$sql .= ' UNSIGNED';

+				}

+	

+				if (array_key_exists('DEFAULT', $attributes))

+				{

+					$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';

+				}

+	

+				if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)

+				{

+					$sql .= ' NULL';

+				}

+				else

+				{

+					$sql .= ' NOT NULL';			

+				}

+	

+				if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)

+				{

+					$sql .= ' AUTO_INCREMENT';

+				}

+			}

+			

+			// don't add a comma on the end of the last field

+			if (++$current_field_count < count($fields))

+			{

+				$sql .= ',';

+			}

+		}

+

+		if (count($primary_keys) > 0)

+		{

+			$primary_keys = $this->db->_protect_identifiers($primary_keys);

+			$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";

+		}

+

+		if (count($keys) > 0)

+		{

+			$keys = $this->db->_protect_identifiers($keys);

+			$sql .= ",\n\tUNIQUE (" . implode(', ', $keys) . ")";

+		}

+

+		$sql .= "\n)";

+

+		return $sql;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop Table

+	 *

+	 *  Unsupported feature in SQLite

+	 *

+	 * @access	private

+	 * @return	bool

+	 */

+	function _drop_table($table)

+	{

+		if ($this->db->db_debug)

+		{

+			return $this->db->display_error('db_unsuported_feature');

+		}

+		return array();

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Alter table query

+	 *

+	 * Generates a platform-specific query so that a table can be altered

+	 * Called by add_column(), drop_column(), and column_alter(),

+	 *

+	 * @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	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 = '')

+	{

+		$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);

+

+		// DROP has everything it needs now.

+		if ($alter_type == 'DROP')

+		{

+			// SQLite does not support dropping columns

+			// http://www.sqlite.org/omitted.html

+			// http://www.sqlite.org/faq.html#q11

+			return FALSE;

+		}

+

+		$sql .= " $column_definition";

+

+		if ($default_value != '')

+		{

+			$sql .= " DEFAULT \"$default_value\"";

+		}

+

+		if ($null === NULL)

+		{

+			$sql .= ' NULL';

+		}

+		else

+		{

+			$sql .= ' NOT NULL';

+		}

+

+		if ($after_field != '')

+		{

+			$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);

+		}

+		

+		return $sql;

+		

+	}

+}

+?>
\ No newline at end of file
diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php
index caa1678..0939c87 100644
--- a/system/database/drivers/sqlite/sqlite_result.php
+++ b/system/database/drivers/sqlite/sqlite_result.php
@@ -167,7 +167,14 @@
 		}

 		else

 		{

-			return $this->_fetch_assoc();

+			$arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC);

+			if (is_array($arr))

+			{

+				$obj = (object) $arr;

+				return $obj;

+			} else {

+				return NULL;

+			} 

 		}

 	}

 

diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php
index 85e74d0..1c78c54 100644
--- a/system/database/drivers/sqlite/sqlite_utility.php
+++ b/system/database/drivers/sqlite/sqlite_utility.php
@@ -24,45 +24,6 @@
  */

 class CI_DB_sqlite_utility extends CI_DB_utility {

 

-

-	/**

-	 * Create database

-	 *

-	 * @access	public

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _create_database()

-	{

-		// In SQLite, a database is created when you connect to the database.

-		// We'll return TRUE so that an error isn't generated

-		return TRUE;

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

-	 * Drop database

-	 *

-	 * @access	private

-	 * @param	string	the database name

-	 * @return	bool

-	 */

-	function _drop_database($name)

-	{

-		if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database))

-		{

-			if ($this->db->db_debug)

-			{

-				return $this->db->display_error('db_unable_to_drop');

-			}

-			return FALSE;

-		}

-		return TRUE;

-	}

-

-	// --------------------------------------------------------------------

-

 	/**

 	 * List databases

 	 *

@@ -86,25 +47,6 @@
 	// --------------------------------------------------------------------

 

 	/**

-	 * Drop Table

-	 *

-	 *  Unsupported feature in SQLite

-	 *

-	 * @access	private

-	 * @return	bool

-	 */

-	function _drop_table($table)

-	{

-		if ($this->db->db_debug)

-		{

-			return $this->db->display_error('db_unsuported_feature');

-		}

-		return array();

-	}

-

-	// --------------------------------------------------------------------

-

-	/**

 	 * Optimize table query

 	 *

 	 * Is optimization even supported in SQLite?

@@ -149,6 +91,49 @@
 		return $this->db->display_error('db_unsuported_feature');

 	}

 

-}

+	/**

+	 *

+	 * The functions below have been deprecated as of 1.6, and are only here for backwards

+	 * compatibility.  They now reside in dbforge().  The use of dbutils for database manipulation

+	 * is STRONGLY discouraged in favour if using dbforge.

+	 *

+	 */

 

+	/**

+	 * Create database

+	 *

+	 * @access	public

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _create_database()

+	{

+		// In SQLite, a database is created when you connect to the database.

+		// We'll return TRUE so that an error isn't generated

+		return TRUE;

+	}

+

+	// --------------------------------------------------------------------

+

+	/**

+	 * Drop database

+	 *

+	 * @access	private

+	 * @param	string	the database name

+	 * @return	bool

+	 */

+	function _drop_database($name)

+	{

+		if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database))

+		{

+			if ($this->db->db_debug)

+			{

+				return $this->db->display_error('db_unable_to_drop');

+			}

+			return FALSE;

+		}

+		return TRUE;

+	}

+

+}

 ?>
\ No newline at end of file