summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-03-05 12:43:25 +0100
committerAndrey Andreev <narf@bofh.bg>2012-03-05 12:43:25 +0100
commit193ec9693b642cf53a8ff7c2679f6a3c433abbb8 (patch)
tree6c9519bf9207dcbbd18e336a1a5dfb5252339220 /system/database
parent8741dda98f2cf4be982ce0cb4f6f798d2b53c0a9 (diff)
parent2baae203864cecd6f7c92b244c28dd18e0051d2c (diff)
Merge branch 'develop' of github.com:EllisLab/CodeIgniter into develop-issue-499
Diffstat (limited to 'system/database')
-rw-r--r--system/database/DB_driver.php12
-rw-r--r--system/database/drivers/mysql/mysql_driver.php31
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php31
3 files changed, 56 insertions, 18 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 15195b20a..e403efb9f 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -293,6 +293,12 @@ class CI_DB_driver {
$sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql);
}
+ // Compile binds if needed
+ if ($binds !== FALSE)
+ {
+ $sql = $this->compile_binds($sql, $binds);
+ }
+
// Is query caching enabled? If the query is a "read type"
// we will load the caching class and return the previously
// cached query if it exists
@@ -308,12 +314,6 @@ class CI_DB_driver {
}
}
- // Compile binds if needed
- if ($binds !== FALSE)
- {
- $sql = $this->compile_binds($sql, $binds);
- }
-
// Save the query for debugging
if ($this->save_queries == TRUE)
{
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index 84f7791c7..7fd08a6ed 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -404,16 +404,35 @@ class CI_DB_mysql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Field data query
- *
- * Generates a platform-specific query so that the column data can be retrieved
+ * Returns an object with field data
*
* @param string the table name
- * @return string
+ * @return object
*/
- public function _field_data($table)
+ public function field_data($table = '')
{
- return 'DESCRIBE '.$table;
+ if ($table == '')
+ {
+ return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
+ }
+
+ $query = $this->query('DESCRIBE '.$this->_protect_identifiers($table, TRUE, NULL, FALSE));
+ $query = $query->result_object();
+
+ $retval = array();
+ for ($i = 0, $c = count($query); $i < $c; $i++)
+ {
+ preg_match('/([a-z]+)(\(\d+\))?/', $query[$i]->Type, $matches);
+
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = $query[$i]->Field;
+ $retval[$i]->type = empty($matches[1]) ? NULL : $matches[1];
+ $retval[$i]->default = $query[$i]->Default;
+ $retval[$i]->max_length = empty($matches[2]) ? NULL : preg_replace('/[^\d]/', '', $matches[2]);
+ $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
+ }
+
+ return $retval;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index 19353944d..25b6ceca1 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -405,16 +405,35 @@ class CI_DB_mysqli_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Field data query
- *
- * Generates a platform-specific query so that the column data can be retrieved
+ * Returns an object with field data
*
* @param string the table name
- * @return string
+ * @return object
*/
- protected function _field_data($table)
+ public function field_data($table = '')
{
- return 'DESCRIBE '.$table;
+ if ($table == '')
+ {
+ return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
+ }
+
+ $query = $this->query('DESCRIBE '.$this->_protect_identifiers($table, TRUE, NULL, FALSE));
+ $query = $query->result_object();
+
+ $retval = array();
+ for ($i = 0, $c = count($query); $i < $c; $i++)
+ {
+ preg_match('/([a-z]+)(\(\d+\))?/', $query[$i]->Type, $matches);
+
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = $query[$i]->Field;
+ $retval[$i]->type = empty($matches[1]) ? NULL : $matches[1];
+ $retval[$i]->default = $query[$i]->Default;
+ $retval[$i]->max_length = empty($matches[2]) ? NULL : preg_replace('/[^\d]/', '', $matches[2]);
+ $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
+ }
+
+ return $retval;
}
// --------------------------------------------------------------------