-
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
Saved php types with metadata when fetching #1049
Merged
Merged
Changes from 1 commit
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
81 changes: 81 additions & 0 deletions
81
test/functional/pdo_sqlsrv/pdo_569_query_varcharmax_ae.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,81 @@ | ||
--TEST-- | ||
GitHub issue #569 - direct query on varchar max fields results in function sequence error (Always Encrypted) | ||
--DESCRIPTION-- | ||
This is similar to pdo_569_query_varcharmax.phpt but is not limited to testing the Always Encrypted feature in Windows only. | ||
--ENV-- | ||
PHPT_EXEC=true | ||
--SKIPIF-- | ||
<?php require('skipif_mid-refactor.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsCommon_mid-refactor.inc"); | ||
|
||
try { | ||
$conn = connect(); | ||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
|
||
$tableName = 'pdoTestTable_569_ae'; | ||
createTable($conn, $tableName, array(new ColumnMeta("int", "id", "IDENTITY"), "c1" => "nvarchar(max)")); | ||
|
||
$input = array(); | ||
|
||
$input[0] = 'some very large string'; | ||
$input[1] = '1234567890.1234'; | ||
$input[2] = 'über über'; | ||
|
||
$numRows = 3; | ||
$tsql = "INSERT INTO $tableName (c1) VALUES (?)"; | ||
|
||
$stmt = $conn->prepare($tsql); | ||
for ($i = 0; $i < $numRows; $i++) { | ||
$stmt->bindParam(1, $input[$i]); | ||
$stmt->execute(); | ||
} | ||
|
||
$tsql = "SELECT id, c1 FROM $tableName ORDER BY id"; | ||
$stmt = $conn->prepare($tsql); | ||
$stmt->execute(); | ||
|
||
// Fetch one row each time with different pdo type and/or encoding | ||
$result = $stmt->fetch(PDO::FETCH_NUM); | ||
if ($result[1] !== $input[0]) { | ||
echo "Expected $input[0] but got: "; | ||
var_dump($result[0]); | ||
} | ||
|
||
$stmt->bindColumn(2, $value, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_SYSTEM); | ||
$result = $stmt->fetch(PDO::FETCH_BOUND); | ||
if (!$result || $value !== $input[1]) { | ||
echo "Expected $input[1] but got: "; | ||
var_dump($result); | ||
} | ||
|
||
$stmt->bindColumn(2, $value, PDO::PARAM_STR); | ||
$result = $stmt->fetch(PDO::FETCH_BOUND); | ||
if (!$result || $value !== $input[2]) { | ||
echo "Expected $input[2] but got: "; | ||
var_dump($value); | ||
} | ||
|
||
// Fetch again but all at once | ||
$stmt->execute(); | ||
$rows = $stmt->fetchall(PDO::FETCH_ASSOC); | ||
for ($i = 0; $i < $numRows; $i++) { | ||
$i = $rows[$i]['id'] - 1; | ||
if ($rows[$i]['c1'] !== $input[$i]) { | ||
echo "Expected $input[$i] but got: "; | ||
var_dump($rows[$i]['c1']); | ||
} | ||
} | ||
|
||
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,97 @@ | ||
--TEST-- | ||
GitHub issue #569 - sqlsrv_query on varchar max fields results in function sequence error | ||
--DESCRIPTION-- | ||
This is similar to srv_569_query_varcharmax.phpt but is not limited to testing the Always Encrypted feature in Windows only. | ||
--ENV-- | ||
PHPT_EXEC=true | ||
--SKIPIF-- | ||
<?php require('skipif_versions_old.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once('MsCommon.inc'); | ||
|
||
$conn = AE\connect(array('CharacterSet'=>'UTF-8')); | ||
|
||
$tableName = 'srvTestTable_569_ae'; | ||
|
||
$columns = array(new AE\ColumnMeta('int', 'id', 'identity'), | ||
new AE\ColumnMeta('nvarchar(max)', 'c1')); | ||
AE\createTable($conn, $tableName, $columns); | ||
|
||
$input = array(); | ||
|
||
$input[0] = 'some very large string'; | ||
$input[1] = '1234567890.1234'; | ||
$input[2] = 'über über'; | ||
|
||
$numRows = 3; | ||
$isql = "INSERT INTO $tableName (c1) VALUES (?)"; | ||
for ($i = 0; $i < $numRows; $i++) { | ||
$stmt = sqlsrv_prepare($conn, $isql, array($input[$i])); | ||
$result = sqlsrv_execute($stmt); | ||
if (!$result) { | ||
fatalError("Failed to insert row $i into $tableName"); | ||
} | ||
} | ||
|
||
// Select all from test table | ||
$tsql = "SELECT id, c1 FROM $tableName ORDER BY id"; | ||
$stmt = sqlsrv_prepare($conn, $tsql); | ||
if (!$stmt) { | ||
fatalError("Failed to read from $tableName"); | ||
} | ||
$result = sqlsrv_execute($stmt); | ||
if (!$result) { | ||
fatalError("Failed to select data from $tableName"); | ||
} | ||
|
||
readline("Press ENTER to continue: "); | ||
// Fetch each row as an array | ||
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { | ||
$i = $row['id'] - 1; | ||
if ($row['c1'] !== $input[$i]) { | ||
echo "Expected $input[$i] but got: "; | ||
var_dump($fieldVal); | ||
} | ||
} | ||
|
||
// Fetch again, one field each time | ||
sqlsrv_execute($stmt); | ||
|
||
$i = 0; | ||
while ($i < $numRows) { | ||
sqlsrv_fetch($stmt); | ||
|
||
switch ($i) { | ||
case 0: | ||
$fieldVal = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR)); | ||
break; | ||
case 1: | ||
$stream = sqlsrv_get_field($stmt, 1); | ||
while (!feof( $stream)) { | ||
$fieldVal = fread($stream, 50); | ||
} | ||
break; | ||
default: | ||
$fieldVal = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING('utf-8')); | ||
break; | ||
} | ||
|
||
if ($fieldVal !== $input[$i]) { | ||
echo 'Expected $input[$i] but got: '; | ||
var_dump($fieldVal); | ||
} | ||
|
||
$i++; | ||
} | ||
|
||
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.
Did this cause problems with the new tests?
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.
As you can see in the pdo test, the user may choose different encoding or type for every single fetch of each row