mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
test function for MSSQL
This commit is contained in:
parent
a67b9a77f9
commit
a8650e3366
@ -167,7 +167,7 @@ class MSSQLDatabase extends Database {
|
|||||||
$starttime = microtime(true);
|
$starttime = microtime(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo 'sql: ' . $sql . '<br>';
|
//echo 'sql: ' . $sql . '<br>';
|
||||||
//Debug::backtrace();
|
//Debug::backtrace();
|
||||||
|
|
||||||
//$funcName=$this->funcPrefix . '_query';
|
//$funcName=$this->funcPrefix . '_query';
|
||||||
@ -663,7 +663,7 @@ class MSSQLDatabase extends Database {
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function tableList() {
|
public function tableList() {
|
||||||
foreach($this->query("EXEC sp_tables") as $record) {
|
foreach($this->query('EXEC sp_tables;') as $record) {
|
||||||
$table = strtolower($record['TABLE_NAME']);
|
$table = strtolower($record['TABLE_NAME']);
|
||||||
$tables[$table] = $table;
|
$tables[$table] = $table;
|
||||||
}
|
}
|
||||||
@ -1124,18 +1124,40 @@ class MSSQLQuery extends Query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function numRecords() {
|
public function numRecords() {
|
||||||
|
if($this->funcPrefix=='mssql')
|
||||||
$funcName=$this->funcPrefix . '_num_rows';
|
$funcName=$this->funcPrefix . '_num_rows';
|
||||||
|
else {
|
||||||
|
$funcName=$this->funcPrefix . '_rows_affected';
|
||||||
|
while ($result=sqlsrv_fetch_array($this->handle)){ }
|
||||||
|
}
|
||||||
|
|
||||||
return $funcName($this->handle);
|
return $funcName($this->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nextRecord() {
|
public function nextRecord() {
|
||||||
// Coalesce rather than replace common fields.
|
// Coalesce rather than replace common fields.
|
||||||
$fetch_row=$this->funcPrefix . '_fetch_row';
|
if($this->funcPrefix=='mssql'){
|
||||||
$field_name=$this->funcPrefix . '_field_name';
|
if($data = mssql_fetch_row($this->handle)) {
|
||||||
|
|
||||||
if($data = $fetch_row($this->handle)) {
|
|
||||||
foreach($data as $columnIdx => $value) {
|
foreach($data as $columnIdx => $value) {
|
||||||
$columnName = $field_name($this->handle, $columnIdx);
|
$columnName = mssql_field_name($this->handle, $columnIdx);
|
||||||
|
// $value || !$ouput[$columnName] means that the *last* occurring value is shown
|
||||||
|
// !$ouput[$columnName] means that the *first* occurring value is shown
|
||||||
|
if(isset($value) || !isset($output[$columnName])) {
|
||||||
|
$output[$columnName] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//Data returns true or false, NOT the actual row
|
||||||
|
if($data = sqlsrv_fetch($this->handle)) {
|
||||||
|
//Now we need to get each row as a stream
|
||||||
|
foreach($data as $columnIdx => $value) {
|
||||||
|
//while($row=sqlsrv_get_field(DB::$lastQuery)){
|
||||||
|
$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
|
||||||
if(isset($value) || !isset($output[$columnName])) {
|
if(isset($value) || !isset($output[$columnName])) {
|
||||||
@ -1147,6 +1169,7 @@ class MSSQLQuery extends Query {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user