mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
Sqlsrv now returns false
This commit is contained in:
parent
36c4145ffe
commit
058466ea87
@ -183,6 +183,7 @@ class MSSQLDatabase extends Database {
|
|||||||
Debug::message("\n$sql\n{$endtime}ms\n", false);
|
Debug::message("\n$sql\n{$endtime}ms\n", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
echo 'handle for this query: ' . $handle . '<br>';
|
||||||
DB::$lastQuery=$handle;
|
DB::$lastQuery=$handle;
|
||||||
|
|
||||||
if(!$handle && $errorLevel) $this->databaseError("Couldn't run query: $sql", $errorLevel);
|
if(!$handle && $errorLevel) $this->databaseError("Couldn't run query: $sql", $errorLevel);
|
||||||
@ -1119,35 +1120,35 @@ class MSSQLQuery extends Query {
|
|||||||
$funcName($this->handle);
|
$funcName($this->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Please see the comments below for numRecords
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function seek($row) {
|
public function seek($row) {
|
||||||
if($this->funcPrefix=='mssql')
|
if($this->funcPrefix=='mssql')
|
||||||
return mssql_data_seek($this->handle, $row);
|
return mssql_data_seek($this->handle, $row);
|
||||||
else {
|
else
|
||||||
$count=0;
|
return false;
|
||||||
while ($result=sqlsrv_fetch_array($this->handle)){
|
|
||||||
if($count==$row)
|
|
||||||
break;
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we're running the sqlsrv set of functions, then the dataobject set is a forward-only curser
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* For this function, and seek() (above), we will be returning false.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function numRecords() {
|
public function numRecords() {
|
||||||
if($this->funcPrefix=='mssql')
|
if($this->funcPrefix=='mssql')
|
||||||
$funcName=$this->funcPrefix . '_num_rows';
|
return mssql_num_rows($this->handle);
|
||||||
else {
|
else
|
||||||
$funcName=$this->funcPrefix . '_rows_affected';
|
return false;
|
||||||
while ($result=sqlsrv_fetch_array($this->handle)){ }
|
|
||||||
}
|
|
||||||
|
|
||||||
return $funcName($this->handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nextRecord() {
|
public function nextRecord() {
|
||||||
echo 'running nextRecord<br>';
|
//echo 'running nextRecord<br>';
|
||||||
// Coalesce rather than replace common fields.
|
// Coalesce rather than replace common fields.
|
||||||
if($this->funcPrefix=='mssql'){
|
if($this->funcPrefix=='mssql'){
|
||||||
if($data = mssql_fetch_row($this->handle)) {
|
if($data = mssql_fetch_row($this->handle)) {
|
||||||
@ -1159,12 +1160,12 @@ class MSSQLQuery extends Query {
|
|||||||
$output[$columnName] = $value;
|
$output[$columnName] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo 'output from nextRecord (MSSQL):<pre>';
|
//echo 'output from nextRecord (MSSQL):<pre>';
|
||||||
print_r($output);
|
//print_r($output);
|
||||||
echo '</pre>';
|
//echo '</pre>';
|
||||||
return $output;
|
return $output;
|
||||||
} else {
|
} else {
|
||||||
echo 'nothing to return from nextRecord<br>';
|
//echo 'nothing to return from nextRecord<br>';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1172,8 +1173,8 @@ class MSSQLQuery extends Query {
|
|||||||
//Data returns true or false, NOT the actual row
|
//Data returns true or false, NOT the actual row
|
||||||
if($data = sqlsrv_fetch($this->handle)) {
|
if($data = sqlsrv_fetch($this->handle)) {
|
||||||
//Now we need to get each row as a stream
|
//Now we need to get each row as a stream
|
||||||
foreach($data as $columnIdx => $value) {
|
//foreach($data as $columnIdx => $value) {
|
||||||
//while($row=sqlsrv_get_field(DB::$lastQuery)){
|
while($row=sqlsrv_get_field(DB::$lastQuery)){
|
||||||
$columnName = sqlsrv_field_name($this->handle, $columnIdx);
|
$columnName = sqlsrv_field_name($this->handle, $columnIdx);
|
||||||
// $value || !$ouput[$columnName] means that the *last* occurring value is shown
|
// $value || !$ouput[$columnName] means that the *last* occurring value is shown
|
||||||
// !$ouput[$columnName] means that the *first* occurring value is shown
|
// !$ouput[$columnName] means that the *first* occurring value is shown
|
||||||
@ -1181,12 +1182,12 @@ class MSSQLQuery extends Query {
|
|||||||
$output[$columnName] = $value;
|
$output[$columnName] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo 'output from nextRecord (SQLSRV):<pre>';
|
//echo 'output from nextRecord (SQLSRV):<pre>';
|
||||||
print_r($output);
|
//print_r($output);
|
||||||
echo '</pre>';
|
//echo '</pre>';
|
||||||
return $output;
|
return $output;
|
||||||
} else {
|
} else {
|
||||||
echo 'nothing to return from nextRecord<br>';
|
//echo 'nothing to return from nextRecord<br>';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user