From: cryo28 at rbcmail dot ru
Operating system: Win2000
PHP version: 5.0.3
PHP Bug Type: InterBase related
Bug description: handling NULL parameters in ibase_prepare/ibase_execute
Description:
------------
Requesting feature is ability to pass null parameters with
ibase_prepare/execute. At this moment, a didn't found any way for
selecting rows by sql statement containing param in where_clause which
values can be null.
A similar work is done, for example, in FibPlus components for delphi by
autoconverting "WHERE FIELD=:param" to "WHERE FIELD IS NULL" if
:param=NULL.
Reproduce code:
---------------
CREATE TABLE TESTTABLE (
ID INTEGER NOT NULL,
NULLFIELD INTEGER
);
INSERT INTO TESTTABLE (ID, NULLFIELD) VALUES (1, NULL);
INSERT INTO TESTTABLE (ID, NULLFIELD) VALUES (2, NULL);
INSERT INTO TESTTABLE (ID, NULLFIELD) VALUES (3, 1);
INSERT INTO TESTTABLE (ID, NULLFIELD) VALUES (4, 1);
COMMIT WORK;
<?php
$db = ibase_connect('localhost:d:\inet\bases\wwwcat.gdb', 'SYSDBA',
'masterkey', 'win1251', null, 3);
$q_sql_1 = 'SELECT ID FROM TESTTABLE WHERE NULLFIELD IS NULL';
$q_sql_2 = 'SELECT ID FROM TESTTABLE WHERE NULLFIELD = 1';
$st_sql_1 ='SELECT ID FROM TESTTABLE WHERE NULLFIELD = ?';
$st_sql_2 ='SELECT ID FROM TESTTABLE WHERE NULLFIELD IS ?';
//PHPDocument1 string 10 - ibase_prepare() [<a
href='function.ibase-prepare'>function.ibase-prepare</a>]: Dynamic SQL
Error SQL error code = -104 Token unknown - line 1, char 45 ?
$st1 = ibase_prepare($db, $st_sql_1);
$st2 = ibase_prepare($db, $st_sql_2);
echo $q_sql_1."\r\n";
$q1 = ibase_query($q_sql_1);
while ($r1 = ibase_fetch_object($q1)) var_dump($r1);
echo "\r\n".'-----------------------'."\r\n";
echo $q_sql_2."\r\n";
$q2 = ibase_query($q_sql_2);
while ($r2 = ibase_fetch_object($q2)) var_dump($r2);
echo "\r\n".'-----------------------'."\r\n";
echo $st_sql_1.' param = 1'."\n\r";
$q4 = ibase_execute($st1, 1);
while ($r4 = ibase_fetch_object($q4)) var_dump($r4);
echo "\r\n".'-----------------------'."\r\n";
echo $st_sql_1.' param = NULL'."\n\r";
$q3 = ibase_execute($st1, NULL);
while ($r3 = ibase_fetch_object($q3)) var_dump($r3);
echo "\r\n".'-----------------------'."\r\n";
echo $st_sql_2.' param = NULL'."\n\r";
$q5 = ibase_execute($st2, NULL);
while ($r5 = ibase_fetch_object($q5)) var_dump($r5);
echo "\r\n".'-----------------------'."\r\n";
?>
Expected result:
----------------
Expected result is ability to pass NULL params to ibase_execute and get
right value as if query was WHERE NULLFIELD IS NULL
Actual result:
--------------
Content-type: text/html
X-Powered-By: PHP/5.0.3
SELECT ID FROM TESTTABLE WHERE NULLFIELD IS NULL
object(stdClass)#1 (1) {
["ID"]=>
int(1)
}
object(stdClass)#2 (1) {
["ID"]=>
int(2)
}
-----------------------
SELECT ID FROM TESTTABLE WHERE NULLFIELD = 1
object(stdClass)#2 (1) {
["ID"]=>
int(3)
}
object(stdClass)#1 (1) {
["ID"]=>
int(4)
}
-----------------------
SELECT ID FROM TESTTABLE WHERE NULLFIELD = ? param = 1
object(stdClass)#1 (1) {
["ID"]=>
int(3)
}
object(stdClass)#2 (1) {
["ID"]=>
int(4)
}
-----------------------
SELECT ID FROM TESTTABLE WHERE NULLFIELD = ? param = NULL
-----------------------
SELECT ID FROM TESTTABLE WHERE NULLFIELD IS ? param = NULL
-----------------------
--
Edit bug report at http://bugs.php.net/?id=32298&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32298&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=32298&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=32298&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=32298&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=32298&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=32298&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=32298&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=32298&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=32298&r=support
Expected behavior: http://bugs.php.net/fix.php?id=32298&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=32298&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=32298&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=32298&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32298&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=32298&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=32298&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=32298&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=32298&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=32298&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=32298&r=mysqlcfg