From e6df24caae0d96655ecbd76c223101d14ee3ddcf Mon Sep 17 00:00:00 2001 From: yitam Date: Wed, 27 Oct 2021 10:28:34 -0700 Subject: [PATCH] Added new test cases for Issue 1310 --- .../pdo_sqlsrv/pdo_1310_null_varchar.phpt | 88 +++++++++++++++++++ .../sqlsrv/srv_1310_null_varchar.phpt | 64 ++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 test/functional/pdo_sqlsrv/pdo_1310_null_varchar.phpt create mode 100644 test/functional/sqlsrv/srv_1310_null_varchar.phpt diff --git a/test/functional/pdo_sqlsrv/pdo_1310_null_varchar.phpt b/test/functional/pdo_sqlsrv/pdo_1310_null_varchar.phpt new file mode 100644 index 000000000..47d1b68fb --- /dev/null +++ b/test/functional/pdo_sqlsrv/pdo_1310_null_varchar.phpt @@ -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-- + +--FILE-- +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 + diff --git a/test/functional/sqlsrv/srv_1310_null_varchar.phpt b/test/functional/sqlsrv/srv_1310_null_varchar.phpt new file mode 100644 index 000000000..b701e3c6a --- /dev/null +++ b/test/functional/sqlsrv/srv_1310_null_varchar.phpt @@ -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-- + +--FILE-- + 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