diff --git a/test/functional/sqlsrv/sqlsrv_batch_query.phpt b/test/functional/sqlsrv/sqlsrv_batch_query.phpt index d3f6205d..cb388b7b 100644 --- a/test/functional/sqlsrv/sqlsrv_batch_query.phpt +++ b/test/functional/sqlsrv/sqlsrv_batch_query.phpt @@ -3,25 +3,44 @@ 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 +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-- 86, 'c2_tinyint'=>0, 'c3_smallint'=>4534, 'c4_bigint'=>-1, 'c5_bit'=>0), - array('c1_int'=>-217483648, 'c2_tinyint'=>31, 'c3_smallint'=>-212, 'c4_bigint'=>546098342985694, 'c5_bit'=>1), - array('c1_int'=>0, 'c2_tinyint'=>127, 'c3_smallint'=>32767, 'c4_bigint'=>9223372000000000000, 'c5_bit'=>0), - array('c1_int'=>-432987563, 'c2_tinyint'=>255, 'c3_smallint'=>0, 'c4_bigint'=>5115115115115115115, 'c5_bit'=>0), - array('c1_int'=>7, 'c2_tinyint'=>1, 'c3_smallint'=>7, 'c4_bigint'=>7, 'c5_bit'=>1), - ); - +$inputs = array(); + +// Generate the inputs for insertRow() +for ($i = 0; $i < $expectedRows; ++$i) +{ + $inputs[] = array(); + for ($j = 0; $j < $expectedResultSets; ++$j) + { + $inputs[$i][$colName[$j]] = $data[$j][$i]; + } +} + for ($i=0; $i < sizeof($inputs); ++$i) { $stmt = AE\insertRow($conn, $tableName, $inputs[$i]); sqlsrv_free_stmt($stmt); } -$query = "SELECT c1_int from batch_query_test; - SELECT c2_tinyint from batch_query_test; - SELECT c3_smallint from batch_query_test; - SELECT c4_bigint from batch_query_test; - SELECT c5_bit from batch_query_test;"; +$query = "SELECT c1_int from $tableName; + SELECT c2_tinyint from $tableName; + SELECT c3_smallint from $tableName; + SELECT c4_bigint from $tableName; + SELECT c5_bit from $tableName;"; // Test the batch query with different cursor types for ($i = 0; $i < sizeof($cursors); ++$i) { $cursor = $cursors[$i]; - echo "Testing with ".$cursor." cursor...\n"; + echo "Testing with $cursor cursor...\n"; $stmt = sqlsrv_prepare($conn, $query, array(), array("Scrollable"=>$cursor)); if (!$stmt) { - fatalError("Error preparing statement with ".$cursor." cursor\n"); + 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"); + 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 - // all results - checkColumnsAndRows($stmt, $cursor, $wrongCursor); - - while ($res = sqlsrv_fetch($stmt)) - { } - - checkColumnsAndRows($stmt, $cursor, $wrongCursor); - - $numResultSets = 1; - while ($next = sqlsrv_next_result($stmt)) { + // 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); - while ($res = sqlsrv_fetch($stmt)) - { } - + $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"); + fatalError("Unexpected number of result sets, expected $expectedResultedSets, got $numResultSets\n"); } // We expect an error if sqlsrv_next_result returns false, @@ -158,7 +183,7 @@ for ($i = 0; $i < sizeof($cursors); ++$i) if ($cursor == 'forward') { checkErrors($noNextResult); } else { - fatalError("sqlsrv_next_result failed with a ".$cursor." cursor\n"); + fatalError("sqlsrv_next_result failed with a $cursor cursor\n"); } }