From ab245adc60f6cc9e967f670aa802ed09d205a2a3 Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Tue, 2 Jun 2009 21:01:15 +0000 Subject: [PATCH] FEATURE semi-numRows support on SQLSRV --- code/MSSQLDatabase.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/code/MSSQLDatabase.php b/code/MSSQLDatabase.php index 994a1e7..68ddf0e 100644 --- a/code/MSSQLDatabase.php +++ b/code/MSSQLDatabase.php @@ -1193,7 +1193,7 @@ class MSSQLQuery extends Query { if($this->mssql) { mssql_free_result($this->handle); } else { - sqsrv_free_stmt($this->handle); + sqlsrv_free_stmt($this->handle); } } @@ -1214,6 +1214,9 @@ class MSSQLQuery extends Query { * Therefore, we do not have access to the number of rows that this result contains * This is (usually) called from Database::rewind(), which in turn seems to be called when a foreach... * is started on a recordset + * + * If you are using SQLSRV, this functon will just return a true or false based on whether you got + * /ANY/ rows. * * For this function, and seek() (above), we will be returning false. * @@ -1222,7 +1225,8 @@ class MSSQLQuery extends Query { if($this->mssql) { return mssql_num_rows($this->handle); } else { - user_error("MSSQLQuery::numRecords() sqlserv doesn't support numRecords.", E_USER_WARNING); + $this->firstRecord = $this->nextRecord(); + return count($this->firstRecord) ? true : false; } } @@ -1245,6 +1249,11 @@ class MSSQLQuery extends Query { } } else { + if isset($this->firstRecord) && $this->firstRecord) { + $toReturn = $this->firstRecord; + $this->firstRecord = false; + return $toReturn; + } if($data = sqlsrv_fetch_array($this->handle, SQLSRV_FETCH_NUMERIC)) { $output = array(); $fields = sqlsrv_field_metadata($this->handle);