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

170 lines
5 KiB
Plaintext
Raw Normal View History

2017-05-04 18:16:29 +02:00
--TEST--
error messages when trying to retrieve past the end of a result set and when no result set exists.
--SKIPIF--
2017-11-29 23:40:47 +01:00
<?php require('skipif_versions_old.inc'); ?>
2017-05-04 18:16:29 +02:00
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
2017-05-04 18:16:29 +02:00
require_once('MsCommon.inc');
2017-11-29 23:40:47 +01:00
$conn = AE\connect();
$tableName = 'test_params';
$columns = array(new AE\ColumnMeta('tinyint', 'id'),
new AE\ColumnMeta('char(10)', 'name'),
new AE\ColumnMeta('float', 'double'),
new AE\ColumnMeta('varchar(max)', 'stuff'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
2017-05-04 18:16:29 +02:00
}
$f1 = 1;
$f2 = "testtestte";
$f3 = 12.0;
$f4 = fopen("data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
2017-05-04 18:16:29 +02:00
2017-11-29 23:40:47 +01:00
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
if (!$stmt) {
var_dump(sqlsrv_errors());
die("sqlsrv_prepare failed.");
2017-05-04 18:16:29 +02:00
}
$success = sqlsrv_execute($stmt);
if (!$success) {
var_dump(sqlsrv_errors());
die("sqlsrv_execute failed.");
2017-05-04 18:16:29 +02:00
}
while ($success = sqlsrv_send_stream_data($stmt)) {
2017-05-04 18:16:29 +02:00
}
if (!is_null($success)) {
sqlsrv_cancel($stmt);
sqlsrv_free_stmt($stmt);
die("sqlsrv_send_stream_data failed.");
2017-05-04 18:16:29 +02:00
}
$result = sqlsrv_fetch($stmt);
if ($result !== false) {
die("sqlsrv_fetch should have failed.");
2017-05-04 18:16:29 +02:00
}
print_r(sqlsrv_errors());
2017-05-04 18:16:29 +02:00
$f1 = 2;
$f3 = 13.0;
$f4 = fopen("data://text/plain,This%20is%20some%20more%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
$success = sqlsrv_execute($stmt);
if (!$success) {
var_dump(sqlsrv_errors());
die("sqlsrv_execute failed.");
2017-05-04 18:16:29 +02:00
}
while ($success = sqlsrv_send_stream_data($stmt)) {
2017-05-04 18:16:29 +02:00
}
if (!is_null($success)) {
sqlsrv_cancel($stmt);
sqlsrv_free_stmt($stmt);
die("sqlsrv_send_stream_data failed.");
2017-05-04 18:16:29 +02:00
}
sqlsrv_free_stmt($stmt);
2017-05-04 18:16:29 +02:00
2017-11-29 23:40:47 +01:00
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM $tableName");
$success = sqlsrv_execute($stmt);
if (!$success) {
var_dump(sqlsrv_errors());
die("sqlsrv_execute failed.");
2017-05-04 18:16:29 +02:00
}
$textValues = array("This is some text meant to test binding parameters to streams",
"This is some more text meant to test binding parameters to streams");
$k = 0;
while (sqlsrv_fetch($stmt)) {
$id = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
2017-05-04 18:16:29 +02:00
echo "$id\n";
$double = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
2017-05-04 18:16:29 +02:00
echo "$double\n";
$name = sqlsrv_get_field($stmt, 2, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
2017-05-04 18:16:29 +02:00
echo "$name\n";
$stream = sqlsrv_get_field($stmt, 3, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
if (!$stream) {
2018-01-17 00:47:36 +01:00
fatalError('Fetching data stream failed!');
} else {
while (!feof($stream)) {
$str = fread($stream, 10000);
if ($str !== $textValues[$k++]) {
fatalError("Incorrect data: \'$str\'!\n");
}
}
2017-05-04 18:16:29 +02:00
}
echo "\n";
}
$result = sqlsrv_fetch($stmt);
if ($result !== false) {
die("sqlsrv_fetch should have failed.");
2017-05-04 18:16:29 +02:00
}
print_r(sqlsrv_errors());
2017-05-04 18:16:29 +02:00
$result = sqlsrv_next_result($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
2017-05-04 18:16:29 +02:00
}
$result = sqlsrv_next_result($stmt);
if ($result !== false) {
die("sqlsrv_next_result should have failed.");
2017-05-04 18:16:29 +02:00
}
print_r(sqlsrv_errors());
2017-05-04 18:16:29 +02:00
2017-12-05 22:43:53 +01:00
dropTable($conn, $tableName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
2017-05-04 18:16:29 +02:00
?>
--EXPECT--
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -28
[code] => -28
[2] => The active result for the query contains no fields.
[message] => The active result for the query contains no fields.
)
)
1
12.0
testtestte
2017-05-04 18:16:29 +02:00
2
13.0
testtestte
2017-05-04 18:16:29 +02:00
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -22
[code] => -22
[2] => There are no more rows in the active result set. Since this result set is not scrollable, no more data may be retrieved.
[message] => There are no more rows in the active result set. Since this result set is not scrollable, no more data may be retrieved.
)
)
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -26
[code] => -26
[2] => There are no more results returned by the query.
[message] => There are no more results returned by the query.
)
)