Issue 228. Don't allow 0 for sqlsrv ClientBufferMaxKBSize.

Add new tests for sqlsrv and pdo.
This commit is contained in:
v-dareck 2017-01-25 13:37:48 -08:00
Родитель 428a6db317
Коммит 69a744d808
3 изменённых файлов: 140 добавлений и 1 удалений

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -0,0 +1,58 @@
--TEST--
sqlsrv_has_rows() using a forward and scrollable cursor
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
// Connect
$conn = new PDO( "sqlsrv:server=$serverName" , $username, $password);
$conn->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</üöîã,ZbOhߢAåb*öî:r>: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:<<AA*¢ã@Uî:B<öBîÐ>z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>å<býUrAA©r£@üÄb_:ãZß_/ou@|ªåü~ACãUO<£îßÄîäbßöhßO©ZvßOBü:Zä<ĪobbO@ÃÐ_~î|a~ð©+,v+Ð/rÃzuöÖZÐOß/CCÖßý¢:<b£B,ÐߢoZbð~BüOö,Üö~ð:ß,CCî<Oä,Öãî£ÜCZ~/z~ý©vuzoöß/u©å|£ãÐv¢îhý:ÄoÐrz.ßbr_U*<hCîßÖ_+:hbü*að.Aö_Oª_öB>Bã_ý*ah¢rOĪ,ßo¢¢a|BÖäz</bUabÖðOA.Ðîý,Bhö*Cßuߣo,|ü_,ýÐu_b|ZÜh|<U@~übU¢Uð/o/Ð>U£.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</üöîã,ZbOhߢAåb*öî:r>: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:<<AA*¢ã@Uî:B<öBîÐ>z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>å<býUrAA©r£@üÄb_:ãZß_/ou@|ªåü~ACãUO<£îßÄîäbßöhßO©ZvßOBü:Zä<ĪobbO@ÃÐ_~î|a~ð©+,v+Ð/rÃzuöÖZÐOß/CCÖßý¢:<b£B,ÐߢoZbð~BüOö,Üö~ð:ß,CCî<Oä,Öãî£ÜCZ~/z~ý©vuzoöß/u©å|£ãÐv¢îhý:ÄoÐrz.ßbr_U*<hCîßÖ_+:hbü*að.Aö_Oª_öB>Bã_ý*ah¢rOĪ,ßo¢¢a|BÖäz</bUabÖðOA.Ðîý,Bhö*Cßuߣo,|ü_,ýÐu_b|ZÜh|<U@~übU¢Uð/o/Ð>U£.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

Просмотреть файл

@ -0,0 +1,81 @@
--TEST--
sqlsrv_has_rows() using a forward and scrollable cursor
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
function fetchData($conn, $table, $size)
{
$ret = sqlsrv_configure('ClientBufferMaxKBSize', $size);
var_dump($ret);
$stmt = sqlsrv_prepare($conn, "SELECT * FROM ".$table, array(), array("Scrollable"=>"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