-
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
Feature request: support extended string types #1043
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e80a5d1
Feature request: support extended string types
yitam 3a18f9d
Cosmetic changes
yitam d6d1bbc
Used sql 2019 CTP3.2 for travis
yitam 2163f99
Corrected the logging of extended string types
yitam 03fed92
Added or modified comments as per review
yitam b5d9dea
Minor fix
yitam 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
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
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
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
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
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/pdo_sqlsrv/pdo_1018_emulate_prepare_natl_char.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 1018 - Test PDO::prepare() with the extended string types | ||
--DESCRIPTION-- | ||
This test verifies the extended string types, PDO::ATTR_DEFAULT_STR_PARAM, PDO::PARAM_STR_NATL and | ||
PDO::PARAM_STR_CHAR will affect "emulate prepared" statements. If the parameter encoding is specified, | ||
it also matters. The N'' prefix will be used when either it is PDO::PARAM_STR_NATL or the | ||
parameter encoding is UTF-8. | ||
--ENV-- | ||
PHPT_EXEC=true | ||
--SKIPIF-- | ||
<?php require('skipif_old_php.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsSetup.inc"); | ||
require_once("MsCommon_mid-refactor.inc"); | ||
|
||
$p = 'Ĉǽŋ'; | ||
$p1 = 'C??'; | ||
|
||
function toEmulatePrepare($conn, $pdoStrParam, $value, $testCase, $utf8 = false) | ||
{ | ||
global $p; | ||
|
||
$sql = 'SELECT :value'; | ||
$options = array(PDO::ATTR_EMULATE_PREPARES => true); | ||
$stmt = $conn->prepare($sql, $options); | ||
|
||
if ($utf8) { | ||
$stmt->bindParam(':value', $p, $pdoStrParam, 0, PDO::SQLSRV_ENCODING_UTF8); | ||
} else { | ||
$stmt->bindParam(':value', $p, $pdoStrParam); | ||
} | ||
$stmt->execute(); | ||
|
||
$result = $stmt->fetch(PDO::FETCH_NUM); | ||
trace("$testCase: expected $value and returned $result[0]\n"); | ||
if ($result[0] !== $value) { | ||
echo("$testCase: expected $value but returned:\n"); | ||
var_dump($result); | ||
} | ||
} | ||
|
||
try { | ||
$conn = connect(); | ||
|
||
// Test case 1: PDO::PARAM_STR_NATL | ||
$testCase = 'Test case 1: no default but specifies PDO::PARAM_STR_NATL'; | ||
toEmulatePrepare($conn, PDO::PARAM_STR | PDO::PARAM_STR_NATL, $p, $testCase); | ||
|
||
// Test case 2: PDO::PARAM_STR_CHAR | ||
$testCase = 'Test case 2: no default but specifies PDO::PARAM_STR_CHAR'; | ||
toEmulatePrepare($conn, PDO::PARAM_STR | PDO::PARAM_STR_CHAR, $p1, $testCase); | ||
|
||
// Test case 3: no extended string types | ||
$testCase = 'Test case 3: no default but no extended string types either'; | ||
toEmulatePrepare($conn, PDO::PARAM_STR, $p1, $testCase); | ||
|
||
// Test case 4: no extended string types but specifies UTF 8 encoding | ||
$testCase = 'Test case 4: no default but no extended string types but with UTF-8'; | ||
toEmulatePrepare($conn, PDO::PARAM_STR, $p, $testCase, true); | ||
|
||
//////////////////////////////////////////////////////////////////////// | ||
// NEXT tests: set the default string type: PDO::PARAM_STR_CHAR first | ||
$conn->setAttribute(PDO::ATTR_DEFAULT_STR_PARAM, PDO::PARAM_STR_CHAR); | ||
|
||
// Test case 5: overrides the default PDO::PARAM_STR_CHAR | ||
$testCase = 'Test case 5: overrides the default PDO::PARAM_STR_CHAR'; | ||
toEmulatePrepare($conn, PDO::PARAM_STR | PDO::PARAM_STR_NATL, $p, $testCase); | ||
|
||
// Test case 6: specifies PDO::PARAM_STR_CHAR directly | ||
$testCase = 'Test case 6: specifies PDO::PARAM_STR_CHAR, same as the default'; | ||
toEmulatePrepare($conn, PDO::PARAM_STR | PDO::PARAM_STR_CHAR, $p1, $testCase); | ||
|
||
// Test case 7: uses the default PDO::PARAM_STR_CHAR without specifying | ||
$testCase = 'Test case 7: no extended string types (uses the default)'; | ||
toEmulatePrepare($conn, PDO::PARAM_STR, $p1, $testCase); | ||
|
||
// Test case 8: uses the default PDO::PARAM_STR_CHAR without specifying | ||
$testCase = 'Test case 8: no extended string types (uses the default) but with UTF-8 '; | ||
toEmulatePrepare($conn, PDO::PARAM_STR, $p, $testCase, true); | ||
|
||
//////////////////////////////////////////////////////////////////////// | ||
// NEXT tests: set the default string type: PDO::PARAM_STR_NATL | ||
$conn->setAttribute(PDO::ATTR_DEFAULT_STR_PARAM, PDO::PARAM_STR_NATL); | ||
|
||
// Test case 9: overrides the default PDO::PARAM_STR_NATL | ||
$testCase = 'Test case 9: overrides the default PDO::PARAM_STR_NATL'; | ||
toEmulatePrepare($conn, PDO::PARAM_STR | PDO::PARAM_STR_CHAR, $p1, $testCase); | ||
|
||
// Test case 10: specifies PDO::PARAM_STR_NATL directly | ||
$testCase = 'Test case 10: specifies PDO::PARAM_STR_NATL, same as the default'; | ||
toEmulatePrepare($conn, PDO::PARAM_STR | PDO::PARAM_STR_NATL, $p, $testCase); | ||
|
||
// Test case 11: uses the default PDO::PARAM_STR_NATL without specifying | ||
$testCase = 'Test case 11: no extended string types (uses the default)'; | ||
toEmulatePrepare($conn, PDO::PARAM_STR, $p, $testCase); | ||
|
||
// Test case 12: uses the default PDO::PARAM_STR_NATL without specifying | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment too |
||
$testCase = 'Test case 12: no extended string types (uses the default) but with UTF-8'; | ||
toEmulatePrepare($conn, PDO::PARAM_STR, $p, $testCase, true); | ||
|
||
echo "Done\n"; | ||
} catch (PdoException $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
Done |
Oops, something went wrong.
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.
I think this comment is wrong? Should specify it's a utf-8 case.