From a7a86e42a310bfe4371eb7229965aaf9c79fbb7e Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Thu, 28 Apr 2011 21:46:56 -0400 Subject: [PATCH] Changes for fetch results. --- lib/Cake/Model/Datasource/Database/Mssql.php | 33 ++++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index 7bcefc2036b..2eb8b6c216c 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -406,19 +406,18 @@ function column($real) { } /** - * Enter description here... + * Builds a map of the columns contained in a result * - * @param unknown_type $results + * @param PDOStatement $results */ - function resultSet(&$results) { - $this->results =& $results; + function resultSet($results) { $this->map = array(); - $numFields = mssql_num_fields($results); + $numFields = $results->columnCount(); $index = 0; $j = 0; - while ($j < $numFields) { - $column = mssql_field_name($results, $j); + while ($numFields-- > 0) { + $column = $results->getColumnMeta($index); if (strpos($column, '__')) { if (isset($this->__fieldMappings[$column]) && strpos($this->__fieldMappings[$column], '.')) { @@ -536,22 +535,22 @@ function read($model, $queryData = array(), $recursive = null) { /** * Fetches the next row from the current result set * - * @return unknown + * @return mixed */ function fetchResult() { - if ($row = mssql_fetch_row($this->results)) { + if ($row = $this->_result->fetch()) { $resultRow = array(); - $i = 0; - - foreach ($row as $index => $field) { - list($table, $column) = $this->map[$index]; - $resultRow[$table][$column] = $row[$index]; - $i++; + foreach ($this->map as $col => $meta) { + list($table, $column, $type) = $meta; + $resultRow[$table][$column] = $row[$col]; + if ($type === 'boolean' && !is_null($row[$col])) { + $resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]); + } } return $resultRow; - } else { - return false; } + $this->_result->closeCursor(); + return false; } /**