-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new test cases for Issue 1310 (#1321)
- Loading branch information
Showing
2 changed files
with
152 additions
and
0 deletions.
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,88 @@ | ||
--TEST-- | ||
GitHub issue 1310 - bind null field as varchar(max) if not binary | ||
--DESCRIPTION-- | ||
The test shows null fields are no longer bound as char(1) if not binary such that it solves both issues 1310 and 1102. | ||
--ENV-- | ||
PHPT_EXEC=true | ||
--SKIPIF-- | ||
<?php require('skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsSetup.inc"); | ||
require_once("MsCommon_mid-refactor.inc"); | ||
|
||
try { | ||
$conn = connect(); | ||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
|
||
// Issue 1310 | ||
$query = "SELECT CAST(ISNULL(:K, -1) AS INT) AS K"; | ||
$k = null; | ||
|
||
$stmt = $conn->prepare($query); | ||
$stmt->bindParam(':K', $k, PDO::PARAM_NULL); | ||
$stmt->execute(); | ||
|
||
$row = $stmt->fetchAll(PDO::FETCH_ASSOC); | ||
var_dump($row); | ||
|
||
$stmt->bindParam(':K', $k, PDO::PARAM_INT); | ||
$stmt->execute(); | ||
|
||
$row = $stmt->fetchAll(PDO::FETCH_NUM); | ||
var_dump($row); | ||
|
||
// Issue 1102 | ||
$query = "DECLARE @d DATETIME = ISNULL(:K, GETDATE()); SELECT @d AS D;"; | ||
$k = null; | ||
|
||
$stmt = $conn->prepare($query); | ||
$stmt->bindParam(':K', $k, PDO::PARAM_NULL); | ||
$stmt->execute(); | ||
|
||
$row = $stmt->fetchAll(PDO::FETCH_NUM); | ||
var_dump($row); | ||
|
||
$stmt->bindParam(':K', $k, PDO::PARAM_INT); | ||
$stmt->execute(); | ||
|
||
$row = $stmt->fetchAll(PDO::FETCH_ASSOC); | ||
var_dump($row); | ||
|
||
echo "Done\n"; | ||
} catch (PdoException $e) { | ||
echo $e->getMessage(); | ||
} | ||
|
||
?> | ||
--EXPECTREGEX-- | ||
array\(1\) { | ||
\[0\]=> | ||
array\(1\) { | ||
\["K"\]=> | ||
string\(2\) "-1" | ||
} | ||
} | ||
array\(1\) { | ||
\[0\]=> | ||
array\(1\) { | ||
\[0\]=> | ||
string\(2\) "-1" | ||
} | ||
} | ||
array\(1\) { | ||
\[0\]=> | ||
array\(1\) { | ||
\[0\]=> | ||
string\(23\) "20[0-9]{2}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:00.000" | ||
} | ||
} | ||
array\(1\) { | ||
\[0\]=> | ||
array\(1\) { | ||
\["D"\]=> | ||
string\(23\) "20[0-9]{2}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:00.000" | ||
} | ||
} | ||
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,64 @@ | ||
--TEST-- | ||
GitHub issue 1310 - bind null field as varchar(max) if not binary | ||
--DESCRIPTION-- | ||
The test shows null fields are no longer bound as char(1) if not binary such that it solves both issues 1310 and 1102. | ||
--ENV-- | ||
PHPT_EXEC=true | ||
--SKIPIF-- | ||
<?php require('skipif_versions_old.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once('MsCommon.inc'); | ||
|
||
$conn = AE\connect(); | ||
|
||
// Issue 1310 | ||
$query = "SELECT CAST(ISNULL(?, -1) AS INT) AS K"; | ||
$k = null; | ||
$params = array($k); | ||
|
||
$stmt = sqlsrv_prepare($conn, $query, $params); | ||
if (!$stmt) { | ||
fatalError("Failed to prepare statement (1)."); | ||
} | ||
if (!sqlsrv_execute($stmt)) { | ||
fatalError("Failed to execute query (1)."); | ||
} | ||
|
||
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { | ||
var_dump($row); | ||
} | ||
|
||
sqlsrv_free_stmt($stmt); | ||
|
||
// Issue 1102 | ||
$query = "DECLARE @d DATETIME = ISNULL(?, GETDATE()); SELECT @d AS D;"; | ||
$k = null; | ||
$params = array($k, null, null, null); | ||
|
||
$options = array('ReturnDatesAsStrings'=> true); | ||
$stmt = sqlsrv_query($conn, $query, $params, $options); | ||
if (!$stmt) { | ||
fatalError("Failed to query statement (2)."); | ||
} | ||
|
||
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { | ||
var_dump($row); | ||
} | ||
|
||
sqlsrv_free_stmt($stmt); | ||
sqlsrv_close($conn); | ||
|
||
echo "Done\n"; | ||
|
||
?> | ||
--EXPECTREGEX-- | ||
array\(1\) { | ||
\["K"\]=> | ||
int\(-1\) | ||
} | ||
array\(1\) { | ||
\["D"\]=> | ||
string\(23\) "20[0-9]{2}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:00.000" | ||
} | ||
Done |