Interbase feature request
| From: | Jeffery Cann | Date: | Thu, 02 Nov 2000 04:52:22 +0000 |
| Subject: | Interbase feature request | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-23313@lists.php.net to get a copy of this message | ||
Greetings.
I would sincerely appreciate if I could send the NULL value to a DATE
column within an interbase database using a BIND variable. I know that
the native interbase driver supports binding of variables in prepared
statements. There are workarounds for this lack of support of the
NULL value, however, they are rather annoying.
For example suppose I have created the following table:
c1 integer not null
c2 string
c3 number
c4 date
In php, the workarounds to send the NULL value to the database are:
For c2, I can insert a NULL using this sql stmt -> 'insert into table
(c1,c2) values ( 1, 'null' );'
For c3, I can insert a NULL using this sql stmt -> 'insert into table
(c1, c3) values (1, null );'
For c3, I can insert a NULL using this sql stmt -> 'insert into table
(c1, c4) values (1, null);'
The annoying part occurs in the case of DATE columns. Notice in the
third example, the only acceptable value to the database is the
non-quoted null. If you quote it, you will get a string conversion
error. This is because Interbase will automagically convert a
recognizable date string into the internal numeric date storage.
Unfortunately, Interbase does not recognize 'null' for a date column to
be the NULL value, you have to send the word null without single quotes
(just like a numeric column).
Suppose I have a php script with an optional date field. When there is
a value in the field (from the form), my php code is like:
...
$date = '12-31-2000'
$sql = 'insert into table (c1,c4) values ( 1, '$date' )
but if date is null, my sql statement must be
$sql = 'insert into table (c1,c4) values ( 1, $date ) <----- notice the
missing single quotes
Because the PHP interbase native driver only seems to support string
literal sql statements (i.e., there is no functional ibase_bind()
function), I have to write literal sql statements based on the value of
optional date fields. BTW - the usual database convention is to bind
stmt placeholders to variables. If you have a table with more than one
optional date field, then you have to write logic to create string
literals for all the possible combinations of the optional date fields.
You can imagine how ridiculous this can become.
If there is some other place to request PHP features, I would appreciate
a link or more info. If someone has a better idea than my relatively
lame workaround of NULL into interbase date columns, I would appreciate
suggestions.
Thanks
Jeff
--
jccann [at] home [dot] com