diff options
Diffstat (limited to 'system/database/drivers/sqlsrv')
-rw-r--r-- | system/database/drivers/sqlsrv/sqlsrv_driver.php | 37 | ||||
-rw-r--r-- | system/database/drivers/sqlsrv/sqlsrv_result.php | 14 |
2 files changed, 35 insertions, 16 deletions
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index a3d3177f7..1e182958c 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -325,22 +325,45 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ protected function _list_columns($table = '') { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; + return "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; } // -------------------------------------------------------------------- /** - * 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 TOP 1 * FROM '.$this->protect_identifiers($table); + if ($table === '') + { + return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; + } + + $sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT + FROM INFORMATION_SCHEMA.Columns + WHERE TABLE_NAME = '.$this->escape($table); + + if (($query = $this->query($sql)) === 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]->COLUMN_NAME; + $retval[$i]->type = $query[$i]->DATA_TYPE; + $retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->NUMERIC_PRECISION : $query[$i]->CHARACTER_MAXIMUM_LENGTH; + $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + } + + return $retval; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php index 6d24cc995..b084b84cd 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_result.php +++ b/system/database/drivers/sqlsrv/sqlsrv_result.php @@ -94,16 +94,12 @@ class CI_DB_sqlsrv_result extends CI_DB_result { public function field_data() { $retval = array(); - foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field) + foreach (sqlsrv_field_metadata($this->result_id) as $i => $field) { - $F = new stdClass(); - $F->name = $field['Name']; - $F->type = $field['Type']; - $F->max_length = $field['Size']; - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; + $retval[$i] = new stdClass(); + $retval[$i]->name = $field['Name']; + $retval[$i]->type = $field['Type']; + $retval[$i]->max_length = $field['Size']; } return $retval; |