summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/mysql
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-11-16 00:06:20 +0100
committerAndrey Andreev <narf@bofh.bg>2012-11-16 00:06:20 +0100
commit10ecc84a3215ca02c11855e399a211f4e5cb60b1 (patch)
treee5f55ee7d390007743cfa5b353f98aac18b47d00 /system/database/drivers/mysql
parentef758bd67c45eb63485fbd2ea2b1d24aa2db1104 (diff)
Improve DB field_data() for MySQL and CUBRID
Diffstat (limited to 'system/database/drivers/mysql')
-rw-r--r--system/database/drivers/mysql/mysql_driver.php17
-rw-r--r--system/database/drivers/mysql/mysql_result.php3
2 files changed, 12 insertions, 8 deletions
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index b1edc2925..1189f3077 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -410,7 +410,7 @@ class CI_DB_mysql_driver extends CI_DB {
* Returns an object with field data
*
* @param string $table
- * @return object
+ * @return array
*/
public function field_data($table = '')
{
@@ -419,19 +419,24 @@ class CI_DB_mysql_driver extends CI_DB {
return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
}
- $query = $this->query('DESCRIBE '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
+ if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
+ {
+ return 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];
+
+ sscanf($query[$i]->Type, '%[a-z](%d)',
+ $retval[$i]->type,
+ $retval[$i]->max_length
+ );
+
$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');
}
diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php
index 4bfa0ae35..a6dcde4e7 100644
--- a/system/database/drivers/mysql/mysql_result.php
+++ b/system/database/drivers/mysql/mysql_result.php
@@ -115,8 +115,7 @@ class CI_DB_mysql_result extends CI_DB_result {
$retval[$i]->name = mysql_field_name($this->result_id, $i);
$retval[$i]->type = mysql_field_type($this->result_id, $i);
$retval[$i]->max_length = mysql_field_len($this->result_id, $i);
- $retval[$i]->primary_key = (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') === FALSE) ? 0 : 1;
- $retval[$i]->default = '';
+ $retval[$i]->primary_key = (int) (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') !== FALSE);
}
return $retval;