Skip to content
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 test cases for Issue 1310 #1321

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions test/functional/pdo_sqlsrv/pdo_1310_null_varchar.phpt
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

64 changes: 64 additions & 0 deletions test/functional/sqlsrv/srv_1310_null_varchar.phpt
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