Skip to content

Commit

Permalink
Merge pull request #55 from efcor/patch-2
Browse files Browse the repository at this point in the history
fix bug where 0 is inserted when null intended
  • Loading branch information
jfelder authored Feb 10, 2021
2 parents 90862cb + ac010a6 commit f931b07
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Jfelder/OracleDB/OCI_PDO/OCIStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions tests/OracleDBOCIStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
6 changes: 5 additions & 1 deletion tests/mocks/OCIFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$OCIExecuteStatus = true;
$OCIFetchStatus = true;
$OCIBindChangeStatus = false;
$OCIBindByNameTypeReceived = null;
}

namespace Jfelder\OracleDB\OCI_PDO {
Expand Down Expand Up @@ -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';
}
Expand Down

0 comments on commit f931b07

Please sign in to comment.