From 534431edc2614b5eff6f510064cbaab29293c8b7 Mon Sep 17 00:00:00 2001 From: Travis Tegen Date: Mon, 8 Feb 2021 15:55:40 -0500 Subject: [PATCH 1/2] fix bug where 0 is inserted when null intended --- src/Jfelder/OracleDB/OCI_PDO/OCIStatement.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Jfelder/OracleDB/OCI_PDO/OCIStatement.php b/src/Jfelder/OracleDB/OCI_PDO/OCIStatement.php index 6aea247..238350c 100644 --- a/src/Jfelder/OracleDB/OCI_PDO/OCIStatement.php +++ b/src/Jfelder/OracleDB/OCI_PDO/OCIStatement.php @@ -34,7 +34,8 @@ class OCIStatement extends \PDOStatement */ protected $datatypes = [ \PDO::PARAM_BOOL => \SQLT_INT, - \PDO::PARAM_NULL => \SQLT_INT, + // there is no SQLT_NULL, but oracle will insert a null value if it receives an empty string + \PDO::PARAM_NULL => \SQLT_CHR, \PDO::PARAM_INT => \SQLT_INT, \PDO::PARAM_STR => \SQLT_CHR, \PDO::PARAM_INPUT_OUTPUT => \SQLT_CHR, From ac010a637a672ea1a42243e1177407b08cbd0922 Mon Sep 17 00:00:00 2001 From: Travis Tegen Date: Tue, 9 Feb 2021 16:15:34 -0500 Subject: [PATCH 2/2] add test for prev bugfix --- tests/OracleDBOCIStatementTest.php | 7 +++++++ tests/mocks/OCIFunctions.php | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/OracleDBOCIStatementTest.php b/tests/OracleDBOCIStatementTest.php index 749785f..19d208e 100644 --- a/tests/OracleDBOCIStatementTest.php +++ b/tests/OracleDBOCIStatementTest.php @@ -181,6 +181,13 @@ public function testBindValueWithValidDataType() $this->assertTrue($this->stmt->bindValue('param', 'hello')); } + public function testBindValueWithNullDataType() + { + global $OCIBindByNameTypeReceived; + $this->assertTrue($this->stmt->bindValue('param', null, \PDO::PARAM_NULL)); + $this->assertSame(\SQLT_CHR, $OCIBindByNameTypeReceived); + } + /** * @expectedException \InvalidArgumentException */ diff --git a/tests/mocks/OCIFunctions.php b/tests/mocks/OCIFunctions.php index c956a2f..15e1bc7 100644 --- a/tests/mocks/OCIFunctions.php +++ b/tests/mocks/OCIFunctions.php @@ -7,6 +7,7 @@ $OCIExecuteStatus = true; $OCIFetchStatus = true; $OCIBindChangeStatus = false; + $OCIBindByNameTypeReceived = null; } namespace Jfelder\OracleDB\OCI_PDO { @@ -79,7 +80,10 @@ function get_resource_type($a = '') if (! function_exists("Jfelder\OracleDB\OCI_PDO\oci_bind_by_name")) { function oci_bind_by_name($a = '', $b = '', &$c, $d = '', $e = '') { - global $OCIStatementStatus, $OCIBindChangeStatus; + global $OCIStatementStatus, $OCIBindChangeStatus, $OCIBindByNameTypeReceived; + + $OCIBindByNameTypeReceived = $e; + if ($OCIBindChangeStatus) { $c = 'oci_bind_by_name'; }