summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/cubrid
diff options
context:
space:
mode:
Diffstat (limited to 'system/database/drivers/cubrid')
-rw-r--r--system/database/drivers/cubrid/cubrid_driver.php36
-rw-r--r--system/database/drivers/cubrid/cubrid_result.php14
2 files changed, 34 insertions, 16 deletions
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index 839413951..21994b093 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -397,16 +397,40 @@ class CI_DB_cubrid_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 $table
- * @return string
+ * @return array
*/
- protected function _field_data($table)
+ public function field_data($table = '')
{
- return 'SELECT * FROM '.$table.' LIMIT 1';
+ if ($table === '')
+ {
+ return ($this->db_debug) ? $this->display_error('db_field_param_missing') : 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++)
+ {
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = $query[$i]->Field;
+
+ sscanf($query[$i]->Type, '%[a-z](%d)',
+ $retval[$i]->type,
+ $retval[$i]->max_length
+ );
+
+ $retval[$i]->default = $query[$i]->Default;
+ $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
+ }
+
+ return $retval;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php
index 30aed38d9..130eea212 100644
--- a/system/database/drivers/cubrid/cubrid_result.php
+++ b/system/database/drivers/cubrid/cubrid_result.php
@@ -88,20 +88,14 @@ class CI_DB_cubrid_result extends CI_DB_result {
public function field_data()
{
$retval = array();
- $i = 0;
- while ($field = cubrid_fetch_field($this->result_id))
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
{
$retval[$i] = new stdClass();
- $retval[$i]->name = $field->name;
- // CUBRID returns type as e.g. varchar(100),
- // so we need to remove all digits and brackets.
- $retval[$i]->type = preg_replace('/[\d()]/', '', $field->type);
- $retval[$i]->default = $field->def;
- // Use CUBRID's native API to obtain column's max_length,
- // otherwise $field->max_length has incorrect info
+ $retval[$i]->name = cubrid_field_name($this->result_id, $i);
+ $retval[$i]->type = cubrid_field_type($this->result_id, $i);
$retval[$i]->max_length = cubrid_field_len($this->result_id, $i);
- $retval[$i++]->primary_key = $field->primary_key;
+ $retval[$i]->primary_key = (int) (strpos(cubrid_field_flags($this->result_id, $i), 'primary_key') !== FALSE);
}
return $retval;