php-sqlsrv/test/functional/sqlsrv/TC42_FetchField.phpt

87 lines
2 KiB
Plaintext
Raw Normal View History

2017-05-04 01:00:31 +02:00
--TEST--
Fetch Field Test
--DESCRIPTION--
Verifies the ability to successfully retrieve field data via "sqlsrv_get_field" by
retrieving fields from a table including rows with all supported SQL types (28 types).
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php
require('skipif_versions_old.inc');
?>
2017-05-04 01:00:31 +02:00
--FILE--
<?php
require_once('MsCommon.inc');
2017-05-04 01:00:31 +02:00
function fetchFields()
2017-05-04 01:00:31 +02:00
{
setup();
$tableName = 'TC42test';
if (useUTF8Data()) {
$conn1 = AE\connect(array('CharacterSet'=>'UTF-8'));
} else {
$conn1 = AE\connect();
}
AE\createTestTable($conn1, $tableName);
2017-05-04 01:00:31 +02:00
$noRows = 10;
$noRowsInserted = AE\insertTestRows($conn1, $tableName, $noRows);
2017-05-04 01:00:31 +02:00
$stmt1 = AE\selectFromTable($conn1, $tableName);
2017-05-04 01:00:31 +02:00
$numFields = sqlsrv_num_fields($stmt1);
trace("Retrieving $noRowsInserted rows with $numFields fields each ...");
for ($i = 0; $i < $noRowsInserted; $i++) {
2017-05-04 01:00:31 +02:00
$row = sqlsrv_fetch($stmt1);
if ($row === false) {
fatalError("Row $i is missing", true);
2017-05-04 01:00:31 +02:00
}
for ($j = 0; $j < $numFields; $j++) {
2017-05-04 01:00:31 +02:00
$fld = sqlsrv_get_field($stmt1, $j);
$col = $j+1;
if ($fld === false) {
2018-01-17 00:47:36 +01:00
fatalError("Field $j of Row $i is missing\n", true);
2017-05-04 01:00:31 +02:00
}
}
}
sqlsrv_free_stmt($stmt1);
trace(" completed successfully.\n");
dropTable($conn1, $tableName);
2017-05-04 01:00:31 +02:00
sqlsrv_close($conn1);
}
2017-05-04 01:00:31 +02:00
// locale must be set before 1st connection
2018-01-02 23:42:08 +01:00
setUSAnsiLocale();
$testName = "Fetch - Field";
// test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above)
startTest($testName);
if (isLocaleSupported()) {
try {
setUTF8Data(false);
fetchFields();
} catch (Exception $e) {
echo $e->getMessage();
}
}
endTest($testName);
// test utf8
startTest($testName);
try {
setUTF8Data(true);
2018-01-04 17:53:20 +01:00
resetLocaleToDefault();
fetchFields();
} catch (Exception $e) {
echo $e->getMessage();
2017-05-04 01:00:31 +02:00
}
endTest($testName);
2017-05-04 01:00:31 +02:00
?>
--EXPECT--
Test "Fetch - Field" completed successfully.
Test "Fetch - Field" completed successfully.