-
Notifications
You must be signed in to change notification settings - Fork 375
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 issue 569 #951
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--TEST-- | ||
GitHub issue #569 - direct query on varchar max fields results in function sequence error | ||
--DESCRIPTION-- | ||
Verifies that the problem is no longer reproducible. | ||
--ENV-- | ||
PHPT_EXEC=true | ||
--SKIPIF-- | ||
<?php require('skipif_mid-refactor.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsSetup.inc"); | ||
require_once("MsCommon_mid-refactor.inc"); | ||
|
||
try { | ||
$connectionInfo = "ColumnEncryption = Enabled;"; | ||
$conn = new PDO("sqlsrv:server = $server; database=$databaseName; $connectionInfo", $uid, $pwd); | ||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
|
||
$tableName = 'pdoTestTable_569'; | ||
dropTable($conn, $tableName); | ||
|
||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { | ||
$tsql = "CREATE TABLE $tableName ([c1] varchar(max) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = AEColumnKey))"; | ||
} else { | ||
$tsql = "CREATE TABLE $tableName ([c1] varchar(max))"; | ||
} | ||
$conn->exec($tsql); | ||
|
||
$input = 'some very large string'; | ||
$tsql = "INSERT INTO $tableName (c1) VALUES (?)"; | ||
$stmt = $conn->prepare($tsql); | ||
$param = array($input); | ||
$stmt->execute($param); | ||
|
||
$tsql = "SELECT * FROM $tableName"; | ||
try { | ||
$stmt = $conn->prepare($tsql); | ||
$stmt->execute(); | ||
} catch (PDOException $e) { | ||
echo ("Failed to read from $tableName\n"); | ||
echo $e->getMessage(); | ||
} | ||
|
||
$row = $stmt->fetch(PDO::FETCH_NUM); | ||
if ($row[0] !== $input) { | ||
echo "Expected $input but got: "; | ||
var_dump($row[0]); | ||
} | ||
|
||
$tsql2 = "DELETE FROM $tableName"; | ||
$rows = $conn->exec($tsql2); | ||
if ($rows !== 1) { | ||
echo 'Expected 1 row affected but got: '; | ||
var_dump($rows); | ||
} | ||
|
||
// Fetch from the empty table | ||
try { | ||
$stmt = $conn->prepare($tsql); | ||
$stmt->execute(); | ||
} catch (PDOException $e) { | ||
echo ("Failed to read $tableName, now empty\n"); | ||
echo $e->getMessage(); | ||
} | ||
|
||
$result = $stmt->fetch(PDO::FETCH_NUM); | ||
if ($result !== false) { | ||
echo 'Expected bool(false) when fetching an empty table but got: '; | ||
var_dump($result); | ||
} | ||
|
||
// Fetch the same table but using client cursor | ||
$stmt = $conn->prepare($tsql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); | ||
$stmt->execute(); | ||
|
||
$result = $stmt->fetch(); | ||
if ($result !== false) { | ||
echo 'Expected bool(false) when fetching an empty table but got: '; | ||
var_dump($result); | ||
} | ||
|
||
dropTable($conn, $tableName); | ||
|
||
unset($stmt); | ||
unset($conn); | ||
} catch (PDOException $e) { | ||
echo $e->getMessage(); | ||
} | ||
|
||
echo "Done\n"; | ||
|
||
?> | ||
--EXPECT-- | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--TEST-- | ||
GitHub issue #569 - sqlsrv_query on varchar max fields results in function sequence error | ||
--DESCRIPTION-- | ||
Verifies that the problem is no longer reproducible. | ||
--ENV-- | ||
PHPT_EXEC=true | ||
--SKIPIF-- | ||
<?php require('skipif_versions_old.inc'); ?> | ||
--FILE-- | ||
<?php | ||
|
||
function verifyFetchError() | ||
{ | ||
$expected = 'A row must be retrieved with sqlsrv_fetch before retrieving data with sqlsrv_get_field.'; | ||
if (strpos(sqlsrv_errors()[0]['message'], $expected) === false) { | ||
print_r(sqlsrv_errors()); | ||
} | ||
} | ||
|
||
require_once('MsCommon.inc'); | ||
|
||
$connectionOptions = array("Database" => $database, "UID" => $userName, "PWD" => $userPassword, "ColumnEncryption" => "Enabled"); | ||
$conn = sqlsrv_connect($server, $connectionOptions); | ||
if ($conn === false) { | ||
fatalError("Failed to connect to $server."); | ||
} | ||
|
||
$tableName = 'srvTestTable_569'; | ||
|
||
dropTable($conn, $tableName); | ||
|
||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { | ||
$tsql = "CREATE TABLE $tableName ([c1] varchar(max) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = AEColumnKey))"; | ||
} else { | ||
$tsql = "CREATE TABLE $tableName ([c1] varchar(max))"; | ||
} | ||
|
||
$stmt = sqlsrv_query($conn, $tsql); | ||
if (!$stmt) { | ||
fatalError("Failed to create $tableName"); | ||
} | ||
|
||
$input = 'some very large string'; | ||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1) VALUES (?)", array($input)); | ||
sqlsrv_execute($stmt); | ||
|
||
$tsql = "SELECT * FROM $tableName"; | ||
$stmt = sqlsrv_query($conn, $tsql); | ||
if (!$stmt) { | ||
fatalError("Failed to read from $tableName"); | ||
} | ||
|
||
sqlsrv_fetch($stmt); | ||
$fieldVal = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR)); | ||
|
||
if ($fieldVal !== $input) { | ||
echo "Expected $input but got: "; | ||
var_dump($fieldVal); | ||
} | ||
|
||
$tsql2 = "DELETE FROM $tableName"; | ||
$stmt = sqlsrv_query($conn, $tsql2); | ||
if (!$stmt) { | ||
fatalError("Failed to delete rows from $tableName"); | ||
} | ||
|
||
$stmt = sqlsrv_query($conn, $tsql); | ||
if (!$stmt) { | ||
fatalError("Failed to read $tableName, now empty"); | ||
} | ||
|
||
$result = sqlsrv_fetch($stmt); | ||
if (!is_null($result)) { | ||
echo 'Expected null when fetching an empty table but got: '; | ||
var_dump($result); | ||
} | ||
|
||
$fieldVal = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR)); | ||
verifyFetchError(); | ||
if ($fieldVal !== false) { | ||
echo 'Expected bool(false) but got: '; | ||
var_dump($fieldVal); | ||
} | ||
|
||
$stmt = sqlsrv_query($conn, $tsql, array(), array("Scrollable"=>"buffered")); | ||
$result = sqlsrv_fetch($stmt); | ||
if (!is_null($result)) { | ||
echo 'Expected null when fetching an empty table but got: '; | ||
var_dump($result); | ||
} | ||
|
||
$fieldVal = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR)); | ||
verifyFetchError(); | ||
if ($fieldVal !== false) { | ||
echo 'Expected bool(false) but got: '; | ||
var_dump($fieldVal); | ||
} | ||
|
||
|
||
dropTable($conn, $tableName); | ||
|
||
echo "Done\n"; | ||
|
||
sqlsrv_free_stmt($stmt); | ||
sqlsrv_close($conn); | ||
|
||
?> | ||
--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.
Is there any particular reason we're restricting this to Windows?
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.
Because
COLUMN_ENCRYPTION_KEY = AEColumnKey
is only available in WindowsOutside Windows we have to use Azure Key Vault