summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
Diffstat (limited to 'system/database')
-rw-r--r--system/database/DB_utility.php114
-rw-r--r--system/database/drivers/mssql/mssql_result.php23
-rw-r--r--system/database/drivers/mssql/mssql_utility.php31
-rw-r--r--system/database/drivers/mysql/mysql_result.php21
-rw-r--r--system/database/drivers/mysql/mysql_utility.php33
-rw-r--r--system/database/drivers/mysqli/mysqli_result.php23
-rw-r--r--system/database/drivers/mysqli/mysqli_utility.php31
-rw-r--r--system/database/drivers/oci8/oci8_result.php21
-rw-r--r--system/database/drivers/oci8/oci8_utility.php32
-rw-r--r--system/database/drivers/odbc/odbc_result.php23
-rw-r--r--system/database/drivers/odbc/odbc_utility.php41
-rw-r--r--system/database/drivers/postgre/postgre_result.php23
-rw-r--r--system/database/drivers/postgre/postgre_utility.php32
-rw-r--r--system/database/drivers/sqlite/sqlite_result.php23
-rw-r--r--system/database/drivers/sqlite/sqlite_utility.php31
15 files changed, 454 insertions, 48 deletions
diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php
index 36d74c5b3..950db7dfd 100644
--- a/system/database/DB_utility.php
+++ b/system/database/DB_utility.php
@@ -65,6 +65,30 @@ class CI_DB_utility {
// --------------------------------------------------------------------
/**
+ * Primary
+ *
+ * Retrieves the primary key. It assumes that the row in the first
+ * position is the primary key
+ *
+ * @access public
+ * @param string the table name
+ * @return string
+ */
+ function primary($table = '')
+ {
+ $fields = $this->field_names($table);
+
+ if ( ! is_array($fields))
+ {
+ return FALSE;
+ }
+
+ return current($fields);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Returns an array of table names
*
* @access public
@@ -188,39 +212,15 @@ class CI_DB_utility {
// --------------------------------------------------------------------
/**
- * Primary
- *
- * Retrieves the primary key. It assumes that the row in the first
- * position is the primary key
- *
- * @access public
- * @param string the table name
- * @return string
- */
- function primary($table = '')
- {
- $fields = $this->field_names($table);
-
- if ( ! is_array($fields))
- {
- return FALSE;
- }
-
- return current($fields);
- }
-
- // --------------------------------------------------------------------
-
- /**
* Create database
*
* @access public
* @param string the database name
* @return bool
*/
- function create_database($name)
+ function create_database($db_name)
{
- $sql = $this->_create_database($name);
+ $sql = $this->_create_database($db_name);
if (is_bool($sql))
{
@@ -239,9 +239,9 @@ class CI_DB_utility {
* @param string the database name
* @return bool
*/
- function drop_database($name)
+ function drop_database($db_name)
{
- $sql = $this->_drop_database($name);
+ $sql = $this->_drop_database($db_name);
if (is_bool($sql))
{
@@ -273,48 +273,76 @@ class CI_DB_utility {
return $dbs;
}
-
+
// --------------------------------------------------------------------
/**
- * Drop Table
+ * Optimize Table
*
* @access public
* @param string the table name
* @return bool
*/
- function drop_table($name)
+ function optimize_table($table_name)
{
- $sql = $this->_drop_table($name);
+ $sql = $this->_optimize_table($table_name);
if (is_bool($sql))
{
return $sql;
}
- return $this->db->query($sql);
+ $query = $this->db->query($sql);
+ return current($query->result_array());
}
+ // --------------------------------------------------------------------
-
- function alter_table()
+ /**
+ * Optimize Table
+ *
+ * @access public
+ * @param string the table name
+ * @return bool
+ */
+
+ function repair_table($table_name)
{
- }
+ $sql = $this->_repair_table($table_name);
+
+ if (is_bool($sql))
+ {
+ return $sql;
+ }
- function create_index()
- {
+ $query = $this->db->query($sql);
+ return current($query->result_array());
}
-
- function drop_index()
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop Table
+ *
+ * @access public
+ * @param string the table name
+ * @return bool
+ */
+ function drop_table($table_name)
{
- }
+ $sql = $this->_drop_table($table_name);
+
+ if (is_bool($sql))
+ {
+ return $sql;
+ }
- function optimize()
- {
+ return $this->db->query($sql);
}
+
}
?> \ No newline at end of file
diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php
index a8a8e2006..53b7832d9 100644
--- a/system/database/drivers/mssql/mssql_result.php
+++ b/system/database/drivers/mssql/mssql_result.php
@@ -49,7 +49,28 @@ class CI_DB_mssql_result extends CI_DB_result {
{
return @mssql_num_fields($this->result_id);
}
-
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch Field Names
+ *
+ * Generates an array of column names
+ *
+ * @access public
+ * @return array
+ */
+ function field_names()
+ {
+ $field_names = array();
+ while ($field = mssql_fetch_field($this->result_id))
+ {
+ $field_names[] = $field->name;
+ }
+
+ return $field_names;
+ }
+
// --------------------------------------------------------------------
/**
diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php
index b85a420e7..cf15104c6 100644
--- a/system/database/drivers/mssql/mssql_utility.php
+++ b/system/database/drivers/mssql/mssql_utility.php
@@ -138,6 +138,37 @@ class CI_DB_mssql_utility extends CI_DB_utility {
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Optimize table query
+ *
+ * Generates a platform-specific query so that a table can be optimized
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _optimize_table($table)
+ {
+ return FALSE; // Is this supported in MS SQL?
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Repair table query
+ *
+ * Generates a platform-specific query so that a table can be repaired
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _repair_table($table)
+ {
+ return return FALSE; // Is this supported in MS SQL?
+ }
}
diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php
index e540489bb..91c4af12c 100644
--- a/system/database/drivers/mysql/mysql_result.php
+++ b/system/database/drivers/mysql/mysql_result.php
@@ -53,6 +53,27 @@ class CI_DB_mysql_result extends CI_DB_result {
// --------------------------------------------------------------------
/**
+ * Fetch Field Names
+ *
+ * Generates an array of column names
+ *
+ * @access public
+ * @return array
+ */
+ function field_names()
+ {
+ $field_names = array();
+ while ($field = mysql_fetch_field($this->result_id))
+ {
+ $field_names[] = $field->name;
+ }
+
+ return $field_names;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Field data
*
* Generates an array of objects containing field meta-data
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index a0c746207..800a90c7a 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -136,6 +136,39 @@ class CI_DB_mysql_utility extends CI_DB_utility {
return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1";
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Optimize table query
+ *
+ * Generates a platform-specific query so that a table can be optimized
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _optimize_table($table)
+ {
+ return "OPTIMIZE TABLE ".$this->db->_escape_table($table);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Repair table query
+ *
+ * Generates a platform-specific query so that a table can be repaired
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _repair_table($table)
+ {
+ return "REPAIR TABLE ".$this->db->_escape_table($table);
+ }
+
+
}
diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php
index b0db6c106..2eca68ff5 100644
--- a/system/database/drivers/mysqli/mysqli_result.php
+++ b/system/database/drivers/mysqli/mysqli_result.php
@@ -49,7 +49,28 @@ class CI_DB_mysqli_result extends CI_DB_result {
{
return @mysqli_num_fields($this->result_id);
}
-
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch Field Names
+ *
+ * Generates an array of column names
+ *
+ * @access public
+ * @return array
+ */
+ function field_names()
+ {
+ $field_names = array();
+ while ($field = mysql_fetch_field($this->result_id))
+ {
+ $field_names[] = $field->name;
+ }
+
+ return $field_names;
+ }
+
// --------------------------------------------------------------------
/**
diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php
index 328661866..8c9e1e960 100644
--- a/system/database/drivers/mysqli/mysqli_utility.php
+++ b/system/database/drivers/mysqli/mysqli_utility.php
@@ -136,6 +136,37 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1";
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Optimize table query
+ *
+ * Generates a platform-specific query so that a table can be optimized
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _optimize_table($table)
+ {
+ return "OPTIMIZE TABLE ".$this->db->_escape_table($table);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Repair table query
+ *
+ * Generates a platform-specific query so that a table can be repaired
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _repair_table($table)
+ {
+ return "REPAIR TABLE ".$this->db->_escape_table($table);
+ }
}
diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php
index d2354a1c6..59adda76b 100644
--- a/system/database/drivers/oci8/oci8_result.php
+++ b/system/database/drivers/oci8/oci8_result.php
@@ -74,6 +74,27 @@ class CI_DB_oci8_result extends CI_DB_result {
return $count;
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch Field Names
+ *
+ * Generates an array of column names
+ *
+ * @access public
+ * @return array
+ */
+ function field_names()
+ {
+ $field_names = array();
+ $fieldCount = $this->num_fields();
+ for ($c = 1; $c <= $fieldCount; $c++)
+ {
+ $field_names[] = ocicolumnname($this->stmt_id, $c);
+ }
+ return $field_names;
+ }
+
// --------------------------------------------------------------------
/**
diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php
index 9c3059f41..011e971d9 100644
--- a/system/database/drivers/oci8/oci8_utility.php
+++ b/system/database/drivers/oci8/oci8_utility.php
@@ -138,6 +138,38 @@ class CI_DB_oci8_utility extends CI_DB_utility {
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Optimize table query
+ *
+ * Generates a platform-specific query so that a table can be optimized
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _optimize_table($table)
+ {
+ return FALSE; // Is this supported in Oracle?
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Repair table query
+ *
+ * Generates a platform-specific query so that a table can be repaired
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _repair_table($table)
+ {
+ return return FALSE; // Is this supported in Oracle?
+ }
+
}
?> \ 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 49e5e9012..385209c56 100644
--- a/system/database/drivers/odbc/odbc_result.php
+++ b/system/database/drivers/odbc/odbc_result.php
@@ -49,7 +49,28 @@ class CI_DB_odbc_result extends CI_DB_result {
{
return @odbc_num_fields($this->result_id);
}
-
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch Field Names
+ *
+ * Generates an array of column names
+ *
+ * @access public
+ * @return array
+ */
+ function field_names()
+ {
+ $field_names = array();
+ for ($i = 0; $i < $this->num_fields(); $i++)
+ {
+ $field_names[] = odbc_field_name($this->result_id, $i);
+ }
+
+ return $field_names;
+ }
+
// --------------------------------------------------------------------
/**
diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php
index 5b4558f68..2932da874 100644
--- a/system/database/drivers/odbc/odbc_utility.php
+++ b/system/database/drivers/odbc/odbc_utility.php
@@ -159,6 +159,47 @@ class CI_DB_odbc_utility extends CI_DB_utility {
return "SELECT TOP 1 FROM ".$this->db->_escape_table($table);
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Optimize table query
+ *
+ * Generates a platform-specific query so that a table can be optimized
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _optimize_table($table)
+ {
+ // Not a supported ODBC feature
+ if ($this->db_debug)
+ {
+ return $this->display_error('db_unsuported_feature');
+ }
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Repair table query
+ *
+ * Generates a platform-specific query so that a table can be repaired
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _repair_table($table)
+ {
+ // Not a supported ODBC feature
+ if ($this->db_debug)
+ {
+ return $this->display_error('db_unsuported_feature');
+ }
+ return FALSE;
+ }
}
diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php
index 6af7f94f2..ee838b450 100644
--- a/system/database/drivers/postgre/postgre_result.php
+++ b/system/database/drivers/postgre/postgre_result.php
@@ -49,7 +49,28 @@ class CI_DB_postgre_result extends CI_DB_result {
{
return @pg_num_fields($this->result_id);
}
-
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch Field Names
+ *
+ * Generates an array of column names
+ *
+ * @access public
+ * @return array
+ */
+ function field_names()
+ {
+ $field_names = array();
+ for ($i = 0; $i < $this->num_fields(); $i++)
+ {
+ $Ffield_names[] = pg_field_name($this->result_id, $i);
+ }
+
+ return $field_names;
+ }
+
// --------------------------------------------------------------------
/**
diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php
index b31609aea..b2fdd5fd4 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -137,6 +137,38 @@ class CI_DB_postgre_utility extends CI_DB_utility {
return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1";
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Optimize table query
+ *
+ * Generates a platform-specific query so that a table can be optimized
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _optimize_table($table)
+ {
+ return FALSE; // Is this supported in Postgre?
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Repair table query
+ *
+ * Generates a platform-specific query so that a table can be repaired
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _repair_table($table)
+ {
+ return return FALSE; // Is this supported in Postgre?
+ }
+
}
diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php
index f30a8cfdf..7f48ce8aa 100644
--- a/system/database/drivers/sqlite/sqlite_result.php
+++ b/system/database/drivers/sqlite/sqlite_result.php
@@ -49,7 +49,28 @@ class CI_DB_sqlite_result extends CI_DB_result {
{
return @sqlite_num_fields($this->result_id);
}
-
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch Field Names
+ *
+ * Generates an array of column names
+ *
+ * @access public
+ * @return array
+ */
+ function field_names()
+ {
+ $field_names = array();
+ for ($i = 0; $i < $this->num_fields(); $i++)
+ {
+ $Ffield_names[] = sqlite_field_name($this->result_id, $i);
+ }
+
+ return $field_names;
+ }
+
// --------------------------------------------------------------------
/**
diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php
index 754a755e4..e9f4eb64e 100644
--- a/system/database/drivers/sqlite/sqlite_utility.php
+++ b/system/database/drivers/sqlite/sqlite_utility.php
@@ -155,6 +155,37 @@ class CI_DB_sqlite_utility extends CI_DB_utility {
return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1";
}
+ // --------------------------------------------------------------------
+
+ /**
+ * Optimize table query
+ *
+ * Generates a platform-specific query so that a table can be optimized
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _optimize_table($table)
+ {
+ return FALSE; // Is this supported SQLite?
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Repair table query
+ *
+ * Generates a platform-specific query so that a table can be repaired
+ *
+ * @access private
+ * @param string the table name
+ * @return object
+ */
+ function _repair_table($table)
+ {
+ return return FALSE; // Is this supported in SQLite?
+ }
}