Skip to content

ext/pdo_firebird: Fixed GH-15604 Always make input parameters nullable #15605

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

Closed
wants to merge 6 commits into from
Closed
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
8 changes: 8 additions & 0 deletions ext/pdo_firebird/firebird_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,14 @@ static bool firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */
if (isc_dsql_describe_bind(H->isc_status, &s, PDO_FB_SQLDA_VERSION, S->in_sqlda)) {
break;
}

/* make all parameters nullable */
unsigned int i;
XSQLVAR* var;
for (i = 0, var = S->in_sqlda->sqlvar; i < S->in_sqlda->sqld; i++, var++) {
/* The low bit of sqltype indicates that the parameter can take a NULL value */
var->sqltype |= 1;
}
}

stmt->driver_data = S;
Expand Down
78 changes: 78 additions & 0 deletions ext/pdo_firebird/tests/bug_15604.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
--TEST--
Bug #15604 It is not possible to pass a NULL value as an input parameter if the field is marked as NOT NULL.
--EXTENSIONS--
pdo_firebird
--SKIPIF--
<?php require('skipif.inc'); ?>
--XLEAK--
A bug in firebird causes a memory leak when calling `isc_attach_database()`.
See https://github.com/FirebirdSQL/firebird/issues/7849
--FILE--
<?php
require_once 'testdb.inc';

$dbh = getDbConnection();

$dbh->exec('
recreate table t_bug_15604 (
id bigint not null,
a int not null,
b int,
constraint pk_bug_15604 primary key(id)
)
');

$dbh->exec('recreate sequence g_bug_15604');

$dbh->exec(<<<'SQL'
create or alter trigger t_bug_15604_bi0 for t_bug_15604
active before insert position 0
as
begin
if (new.id is null) then
new.id = next value for g_bug_15604;
end
SQL
);

$stmt = $dbh->prepare('insert into t_bug_15604(id, a, b) values(?, ?, ?)');
$stmt->execute([null, 1, 2]);
$stmt->execute([2, 2, null]);
unset($stmt);

$stmt2 = $dbh->prepare('SELECT id, a, b FROM t_bug_15604 WHERE id = ?');

$stmt2->execute([null]);
$data = $stmt2->fetch(\PDO::FETCH_ASSOC);
$stmt2->closeCursor();
var_dump($data);

$stmt2->execute([2]);
$data = $stmt2->fetch(\PDO::FETCH_ASSOC);
$stmt2->closeCursor();
var_dump($data);

unset($stmt2);

echo "\nOK\n";
?>
--CLEAN--
<?php
require_once 'testdb.inc';
$dbh = getDbConnection();
@$dbh->exec('drop table t_bug_15604');
@$dbh->exec('drop sequence g_bug_15604');
unset($dbh);
?>
--EXPECT--
bool(false)
array(3) {
["ID"]=>
int(2)
["A"]=>
int(2)
["B"]=>
NULL
}

OK
Loading