diff --git a/test/functional/sqlsrv/sqlsrv_batch_query.phpt b/test/functional/sqlsrv/sqlsrv_batch_query.phpt new file mode 100644 index 00000000..4cfa1445 --- /dev/null +++ b/test/functional/sqlsrv/sqlsrv_batch_query.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test a batch query with different cursor types +--DESCRIPTION-- +Verifies that batch queries don't work with dynamic, static, and keyset +server-side cursors, and checks that correct column and row counts are +returned otherwise. For information on the expected behaviour of cursors +with batch queries, see +https://docs.microsoft.com/en-us/previous-versions/visualstudio/aa266531(v=vs.60) +--SKIPIF-- + +--FILE-- +$cursor)); + if (!$stmt) { + fatalError("Error preparing statement with $cursor cursor\n"); + } + + if (!sqlsrv_execute($stmt)) { + if ($cursor == 'forward' or $cursor == 'buffered') { + fatalError("Statement execution failed unexpectedly with a $cursor cursor\n"); + } else { + checkErrors($noCursor); + continue; + } + } + + $numResultSets = 0; + + // Check the column and row count before and after running through + // each result set, because some cursor types may return the number + // of rows only after fetching all rows in the result set + do { + checkColumnsAndRows($stmt, $cursor, $wrongCursor); + + $row = 0; + while ($res = sqlsrv_fetch_array($stmt)) { + if ($res[0] != $data[$numResultSets][$row]) { + fatalError("Wrong result, expected ".$data[$numResultSets][$row].", got $res[0]\n"); + } + ++$row; + } + + checkColumnsAndRows($stmt, $cursor, $wrongCursor); + ++$numResultSets; + + } while ($next = sqlsrv_next_result($stmt)); + + if ($numResultSets != $expectedResultSets) { + fatalError("Unexpected number of result sets, expected $expectedResultedSets, got $numResultSets\n"); + } + + // We expect an error if sqlsrv_next_result returns false, + // but not if it returns null (i.e. if we are genuinely at + // the end of all the result sets with a buffered cursor) + if ($next === false) { + if ($cursor == 'forward') { + checkErrors($noNextResult); + } else { + fatalError("sqlsrv_next_result failed with a $cursor cursor\n"); + } + } + + sqlsrv_free_stmt($stmt); +} + +dropTable($conn, $tableName); +sqlsrv_close($conn); + +echo "Done.\n"; +?> +--EXPECT-- +Testing with forward cursor... +Testing with dynamic cursor... +Testing with static cursor... +Testing with keyset cursor... +Testing with buffered cursor... +Done.