From 69a744d808b7376e37623a213c99236b5c5ffe98 Mon Sep 17 00:00:00 2001 From: v-dareck Date: Wed, 25 Jan 2017 13:37:48 -0800 Subject: [PATCH] Issue 228. Don't allow 0 for sqlsrv ClientBufferMaxKBSize. Add new tests for sqlsrv and pdo. --- source/sqlsrv/util.cpp | 2 +- ...28_setAttribute_clientbuffermaxkbsize.phpt | 58 +++++++++++++ .../srv_228_sqlsrv_clientbuffermaxkbsize.phpt | 81 +++++++++++++++++++ 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 test/pdo_sqlsrv/pdo_228_setAttribute_clientbuffermaxkbsize.phpt create mode 100644 test/sqlsrv/srv_228_sqlsrv_clientbuffermaxkbsize.phpt diff --git a/source/sqlsrv/util.cpp b/source/sqlsrv/util.cpp index c2b2123bf..4457659bb 100644 --- a/source/sqlsrv/util.cpp +++ b/source/sqlsrv/util.cpp @@ -592,7 +592,7 @@ PHP_FUNCTION( sqlsrv_configure ) zend_long buffered_query_limit = Z_LVAL_P( value_z ); - CHECK_CUSTOM_ERROR( buffered_query_limit < 0, error_ctx, SQLSRV_ERROR_INVALID_BUFFER_LIMIT, _FN_ ) { + CHECK_CUSTOM_ERROR( buffered_query_limit <= 0, error_ctx, SQLSRV_ERROR_INVALID_BUFFER_LIMIT, _FN_ ) { throw ss::SSException(); } diff --git a/test/pdo_sqlsrv/pdo_228_setAttribute_clientbuffermaxkbsize.phpt b/test/pdo_sqlsrv/pdo_228_setAttribute_clientbuffermaxkbsize.phpt new file mode 100644 index 000000000..4d240b966 --- /dev/null +++ b/test/pdo_sqlsrv/pdo_228_setAttribute_clientbuffermaxkbsize.phpt @@ -0,0 +1,58 @@ +--TEST-- +sqlsrv_has_rows() using a forward and scrollable cursor +--SKIPIF-- +--FILE-- +setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); + +// Create database +$conn->query("CREATE DATABASE ". $dbName); +// Create table +$stmt = $conn->query("CREATE TABLE ".$dbName.".[dbo].[php_test_table_1] ([c1_int] int, [c2_varchar] varchar(1000))"); +$query = "INSERT INTO ".$dbName.".[dbo].[php_test_table_1] (c1_int, c2_varchar) VALUES ((990021574), ('>vh~Ö.bÐ*äß/ÄAabýZâOüzr£ðAß+|~|OU¢a|U<ßrv.uCB.ÐÜh_î+ãå@üðöã,U+ßvuU:/ý_Öãî/ð|bB|_Zbua©r++BA¢z£.üî¢öåäözÜ¢ßb:aöCrÄ~ýZ¢uªÐö.hhßð*zÜÜß*ãüåýãÄ+åýüüaߢÃÐBî@~AZöÃOßC@äoÃuCÜ,ÐÄa:îäÄÖý:h*ouªuåvUz_ArßAªãaãvÐåAUüAB:¢Äz|öub<üZvößüå:ãÄ@r/ZAÄðÄÄvzîv~C/£|ýýbüÖ~£|Öå<Üa~/v@åAz©¢£U_ßhbaÃß,zz<ã¢|<ä©>öAuövÖ>abu,zå,+ß/ü/ª_bbB:ÃC~£ü/O©O©ªAª_,|a¢~ýý/b>ßC@/böîöh>~£ð+Bßr©ÄÐÖßã:bA@:>B:UAbããîÜ~uÜ£îCöÖ£©_ÜßzÐ+ÖýZb,A:<z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>åBã_ý*ah¢rOĪ,ßo¢¢a|BÖäzU£.B£@Ü,ßAÃ>,ðßß+ßÜ©|Ðr©bCðТüãz>AßðåÃ>bÄåÄ|Z~äÃ/Cb*£bð_/Ða@~AÜãO+ý*CîîÃzÄöÃa©+@vuz>î>©.Cv>hÃý>©Bä,ö~@~@r,AðCu@Ü,@U*ÐvöÃêuã.Öa*uZªoZ/ðÖ©ßv_<ÖvåÜÐÜOÐoðßðÃUýZÐB:+ÄÃã£'))"; +$stmt = $conn->query($query); + +$stmt = $conn->query("CREATE TABLE ".$dbName.".[dbo].[php_test_table_2] ([c1_int] int, [c2_varchar] varchar(max))"); +$query = "INSERT INTO ".$dbName.".[dbo].[php_test_table_2] (c1_int, c2_varchar) VALUES ((990021574), ('>vh~Ö.bÐ*äß/ÄAabýZâOüzr£ðAß+|~|OU¢a|U<ßrv.uCB.ÐÜh_î+ãå@üðöã,U+ßvuU:/ý_Öãî/ð|bB|_Zbua©r++BA¢z£.üî¢öåäözÜ¢ßb:aöCrÄ~ýZ¢uªÐö.hhßð*zÜÜß*ãüåýãÄ+åýüüaߢÃÐBî@~AZöÃOßC@äoÃuCÜ,ÐÄa:îäÄÖý:h*ouªuåvUz_ArßAªãaãvÐåAUüAB:¢Äz|öub<üZvößüå:ãÄ@r/ZAÄðÄÄvzîv~C/£|ýýbüÖ~£|Öå<Üa~/v@åAz©¢£U_ßhbaÃß,zz<ã¢|<ä©>öAuövÖ>abu,zå,+ß/ü/ª_bbB:ÃC~£ü/O©O©ªAª_,|a¢~ýý/b>ßC@/böîöh>~£ð+Bßr©ÄÐÖßã:bA@:>B:UAbããîÜ~uÜ£îCöÖ£©_ÜßzÐ+ÖýZb,A:<z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>åBã_ý*ah¢rOĪ,ßo¢¢a|BÖäzU£.B£@Ü,ßAÃ>,ðßß+ßÜ©|Ðr©bCðТüãz>AßðåÃ>bÄåÄ|Z~äÃ/Cb*£bð_/Ða@~AÜãO+ý*CîîÃzÄöÃa©+@vuz>î>©.Cv>hÃý>©Bä,ö~@~@r,AðCu@Ü,@U*ÐvöÃêuã.Öa*uZªoZ/ðÖ©ßv_<ÖvåÜÐÜOÐoðßðÃUýZÐB:+ÄÃã£'))"; +$stmt = $conn->query($query); + +$size = 2; +$stmt = $conn->prepare("SELECT * FROM ".$dbName.".[dbo].[php_test_table_1]", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED,PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE=> $size)); +$attr = $stmt->getAttribute(constant('PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE')); +echo("Client Buffer Size in KB: $attr\n"); +$stmt->execute(); +$numRows = 0; +while ($result = $stmt->fetch()) + $numRows++; + +echo ("Number of rows: $numRows\n"); + +$size = 3; +$stmt = $conn->prepare("SELECT * FROM ".$dbName.".[dbo].[php_test_table_2]", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED,PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE=> $size)); +$attr = $stmt->getAttribute(constant('PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE')); +echo("Client Buffer Size in KB: $attr\n"); +$stmt->execute(); +$numRows = 0; +while ($result = $stmt->fetch()) + $numRows++; + +echo ("Number of rows: $numRows\n"); + +// DROP database +$conn->query("DROP DATABASE ". $dbName) ?: die(); +$stmt=null; +$conn=null; +print "Done" +?> + +--EXPECT-- +Client Buffer Size in KB: 2 +Number of rows: 1 +Client Buffer Size in KB: 3 +Number of rows: 1 +Done diff --git a/test/sqlsrv/srv_228_sqlsrv_clientbuffermaxkbsize.phpt b/test/sqlsrv/srv_228_sqlsrv_clientbuffermaxkbsize.phpt new file mode 100644 index 000000000..d047ed033 --- /dev/null +++ b/test/sqlsrv/srv_228_sqlsrv_clientbuffermaxkbsize.phpt @@ -0,0 +1,81 @@ +--TEST-- +sqlsrv_has_rows() using a forward and scrollable cursor +--SKIPIF-- +--FILE-- +"buffered")); + $attr = sqlsrv_get_config('ClientBufferMaxKBSize'); + echo("ClientBufferMaxKBSize is $attr\n"); + + sqlsrv_execute($stmt); + $rows = sqlsrv_has_rows($stmt); + var_dump($rows); + + sqlsrv_execute($stmt); + $numRowsFetched = 0; + while ($row = sqlsrv_fetch_array($stmt)) + { + $numRowsFetched++; + } + echo("Number of rows fetched: $numRowsFetched\n"); +} + +// Connect +$conn = sqlsrv_connect( $serverName, $connectionInfo); +if( !$conn ) { die( print_r( sqlsrv_errors(), true)); } + +// Create database +sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die(); +// Create table +$stmt = sqlsrv_query($conn, "CREATE TABLE ".$dbName.".[dbo].[php_test_table_1] ([c1_int] int, [c2_varchar_max] varchar(max))"); +$stmt = sqlsrv_query($conn, "CREATE TABLE ".$dbName.".[dbo].[php_test_table_2] ([c1_int] int, [c2_varchar_1036] varchar(1036))"); +// insert > 1KB into c2_varchar_max & c2_varchar_1036 (1036 characters). +$stmt = sqlsrv_query($conn, "INSERT INTO ".$dbName.".[dbo].[php_test_table_1] (c1_int, c2_varchar_max) VALUES (1, 'This is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a test')"); +$stmt = sqlsrv_query($conn, "INSERT INTO ".$dbName.".[dbo].[php_test_table_2] (c1_int, c2_varchar_1036) VALUES (1, 'This is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a test')"); + +// set client buffer size to 0KB returns false +$ret = sqlsrv_configure('ClientBufferMaxKBSize', 0); +var_dump($ret); +// set client buffer size to 1KB +$size = 1; +fetchData($conn, $dbName.".[dbo].[php_test_table_1]", $size); // this should return 0 rows. +fetchData($conn, $dbName.".[dbo].[php_test_table_2]", $size); // this should return 0 rows. +// set client buffer size to 2KB +$size = 2; +fetchData($conn, $dbName.".[dbo].[php_test_table_1]", $size); // this should return 1 row. +fetchData($conn, $dbName.".[dbo].[php_test_table_2]", $size); // this should return 1 row. + +// DROP database +$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName); +sqlsrv_free_stmt($stmt); +sqlsrv_close($conn); +print "Done" +?> + +--EXPECT-- +bool(false) +bool(true) +ClientBufferMaxKBSize is 1 +bool(false) +Number of rows fetched: 0 +bool(true) +ClientBufferMaxKBSize is 1 +bool(false) +Number of rows fetched: 0 +bool(true) +ClientBufferMaxKBSize is 2 +bool(true) +Number of rows fetched: 1 +bool(true) +ClientBufferMaxKBSize is 2 +bool(true) +Number of rows fetched: 1 +Done