-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new tests for setting client buffer size related to issue 228 #920
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
test/functional/pdo_sqlsrv/pdo_228_setConnAttribute_clientbuffermaxkbsize.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--TEST-- | ||
GitHub issue #228 - how max client buffer size affects the fetching of data | ||
--DESCRIPTION-- | ||
A pdo_sqlsrv variation of the example in GitHub issue 228, using PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE the connection attribute. | ||
--SKIPIF-- | ||
<?php require('skipif_mid-refactor.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsCommon_mid-refactor.inc"); | ||
|
||
function testErrors($conn, $size, $error) | ||
{ | ||
try { | ||
$conn->setAttribute(PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE, $size); | ||
} catch (PDOException $e) { | ||
if (strpos($e->getMessage(), $error) === false) { | ||
echo $e->getMessage() . "\n"; | ||
} | ||
} | ||
} | ||
|
||
try { | ||
// Connect | ||
$conn = connect(); | ||
|
||
$error = 'The PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE attribute is not a number or the number is not positive. Only positive numbers are valid for this attribute.'; | ||
testErrors($conn, 0, $error); | ||
testErrors($conn, 2.99, $error); | ||
|
||
// Create 2 tables | ||
$tableName1 = 'pdo_228_1'; | ||
$tableName2 = 'pdo_228_2'; | ||
|
||
createTable($conn,$tableName1, array("c1_int" => "int", "c2_varchar" => "varchar(1000)")); | ||
insertRow($conn, $tableName1, array("c1_int" => 990021574, "c2_varchar" => ">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:+ÄÃã£")); | ||
|
||
createTable($conn,$tableName2, array("c1_int" => "int", "c2_varchar" => "varchar(max)")); | ||
insertRow($conn, $tableName2, array("c1_int" => 990021574, "c2_varchar" => ">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:+ÄÃã£")); | ||
|
||
$size = 2; | ||
$conn->setAttribute(PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE, $size); | ||
$stmt = $conn->prepare("SELECT * FROM $tableName1", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); | ||
$attr = $conn->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; | ||
$conn->setAttribute(PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE, $size); | ||
$stmt = $conn->prepare("SELECT * FROM $tableName2", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); | ||
$attr = $conn->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 = 1; | ||
$conn->setAttribute(PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE, $size); | ||
$stmt = $conn->prepare("SELECT * FROM $tableName2", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); | ||
$attr = $conn->getAttribute(constant('PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE')); | ||
echo("Client Buffer Size in KB: $attr\n"); | ||
try { | ||
$stmt->execute(); | ||
echo "Expect this to fail!!\n"; | ||
} catch (PDOException $e) { | ||
var_dump($e->getMessage()); | ||
} | ||
|
||
dropTable($conn, $tableName1); | ||
dropTable($conn, $tableName2); | ||
unset($stmt); | ||
unset($conn); | ||
print "Done"; | ||
} catch (PDOException $e) { | ||
var_dump($e->errorInfo); | ||
} | ||
?> | ||
|
||
--EXPECT-- | ||
Client Buffer Size in KB: 2 | ||
Number of rows: 1 | ||
Client Buffer Size in KB: 3 | ||
Number of rows: 1 | ||
Client Buffer Size in KB: 1 | ||
string(65) "SQLSTATE[IMSSP]: Memory limit of 1 KB exceeded for buffered query" | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
test/functional/sqlsrv/srv_228_sqlsrv_clientbuffermaxkbsize_option.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--TEST-- | ||
GitHub issue #228 - how ClientBufferMaxKBSize affects sqlsrv_has_rows and sqlsrv_fetch_array | ||
--DESCRIPTION-- | ||
A variation of the example in GitHub issue 228, using ClientBufferMaxKBSize the statement option. | ||
--SKIPIF-- | ||
<?php require('skipif_versions_old.inc'); ?> | ||
--FILE-- | ||
<?php | ||
|
||
require_once('MsCommon.inc'); | ||
|
||
function testErrors($conn, $table, $error) | ||
{ | ||
$query = "SELECT * FROM $table"; | ||
|
||
// set client buffer size to 0KB | ||
$stmt = sqlsrv_prepare($conn, $query, array(), array("Scrollable"=>"buffered", "ClientBufferMaxKBSize" => 0)); | ||
if ($stmt !== false) { | ||
echo("Setting client buffer size to 0KB should have failed\n"); | ||
} else { | ||
if (strpos(sqlsrv_errors()[0]['message'], $error) === false) { | ||
print_r(sqlsrv_errors()); | ||
} | ||
} | ||
|
||
// set client buffer size to 0.99KB | ||
$stmt = sqlsrv_prepare($conn, $query, array(), array("Scrollable"=>"buffered", "ClientBufferMaxKBSize" => 0.99)); | ||
if ($stmt !== false) { | ||
echo("Setting client buffer size to 0.99KB should have failed\n"); | ||
} else { | ||
if (strpos(sqlsrv_errors()[0]['message'], $error) === false) { | ||
print_r(sqlsrv_errors()); | ||
} | ||
} | ||
} | ||
|
||
function fetchData($conn, $table, $size) | ||
{ | ||
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $table", array(), array("Scrollable"=>"buffered", "ClientBufferMaxKBSize" => $size)); | ||
|
||
$numRowsExpected = ($size > 1) ? 1 : 0; | ||
$res = sqlsrv_execute($stmt); | ||
if ($res && $size < 2) { | ||
echo "Expect this to fail\n"; | ||
} else { | ||
$error = 'Memory limit of 1 KB exceeded for buffered query'; | ||
if (strpos(sqlsrv_errors()[0]['message'], $error) === false) { | ||
print_r(sqlsrv_errors()); | ||
} | ||
} | ||
|
||
$rows = sqlsrv_has_rows($stmt); | ||
if ($numRowsExpected && !$rows) { | ||
fatalError("sqlsrv_has_rows failed\n"); | ||
} | ||
|
||
$numRowsFetched = 0; | ||
while ($row = sqlsrv_fetch_array($stmt)) { | ||
$numRowsFetched++; | ||
} | ||
if ($numRowsExpected != $numRowsFetched) { | ||
echo("Expected $numRowsExpected but number of rows fetched is $numRowsFetched\n"); | ||
} | ||
} | ||
|
||
// connect | ||
$conn = AE\connect(); | ||
|
||
$tableName1 = 'php_test_table_1'; | ||
$tableName2 = 'php_test_table_2'; | ||
|
||
// Create tables | ||
$columns = array(new AE\ColumnMeta('int', 'c1_int'), | ||
new AE\ColumnMeta('varchar(max)', 'c2_varchar_max')); | ||
$stmt = AE\createTable($conn, $tableName1, $columns); | ||
|
||
unset($columns); | ||
$columns = array(new AE\ColumnMeta('int', 'c1_int'), | ||
new AE\ColumnMeta('varchar(1050)', 'c2_varchar_1050')); | ||
$stmt = AE\createTable($conn, $tableName2, $columns); | ||
|
||
// insert > 1KB into c2_varchar_max & c2_varchar_1050 (1050 characters). | ||
$longString = str_repeat('This is a test', 75); | ||
|
||
$stmt = AE\insertRow($conn, $tableName1, array('c1_int' => 1, 'c2_varchar_max' => $longString)); | ||
$stmt = AE\insertRow($conn, $tableName2, array('c1_int' => 1, 'c2_varchar_1050' => $longString)); | ||
sqlsrv_free_stmt($stmt); | ||
|
||
$error = 'Setting for ClientBufferMaxKBSize was non-int or non-positive'; | ||
testErrors($conn, $tableName1, $error); | ||
|
||
// set client buffer size to 1KB | ||
$size = 1; | ||
fetchData($conn, $tableName1, $size); // this should return 0 rows. | ||
fetchData($conn, $tableName2, $size); // this should return 0 rows. | ||
// set client buffer size to 2KB | ||
$size = 2; | ||
fetchData($conn, $tableName1, $size); // this should return 1 row. | ||
fetchData($conn, $tableName2, $size); // this should return 1 row. | ||
|
||
dropTable($conn, $tableName1); | ||
dropTable($conn, $tableName2); | ||
|
||
sqlsrv_close($conn); | ||
print "Done" | ||
?> | ||
|
||
--EXPECT-- | ||
Done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message is not the same as the one in the PDO tests above. Is this correct? It looks like it's the same error, just the message is slightly different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes they are different. The error messages have always been there just no tests for checking them.