Re: NULL value question



On Jul 31, 9:04 pm, Jim James <j...@xxxxxxxxxxxxx> wrote:
I'm coding my first web site using a mysql
database and DBI.

I can fetch records from the database
with no problem, but I'm having trouble
testing NULL values. If I load the value
of a date field into a variable ($dateadded),
how should the IF condition be written?

if ( $dateadded = NULL ) {

The single "=" is the assignment operator which does not test
anything, to test numerical equality use "==", to test stringwise
equality use "eq" (see perldoc perlop, equality operators).

I don't know anything about DBI, but I assume that NULL is a constant
string or number in DBI. Depending on whether it is a number or a
string, use '==' or 'eq'.

On the other hand, I would guess that DBI returns NULL values as
undefined scalars, in this case, neither "==", nor "eq" work as
expected. You should better use the defined function (see perldoc -f
defined)

if ( ! defined($dateadded) ) {

--
Klaus

.



Relevant Pages

  • RE: Accessing MS Access through the DBI ODBC
    ... I tried removing the user and the pwd from the ODBC connect string but I am still getting 'Unable to connect to database'. ... It will take in a reason for failure as a string and append the DBI ...
    (perl.dbi.users)
  • RE: fetchrow_array performance
    ... I agree - set RasieError. ... it is impossible to tell what is going on in the database without a 10046 trace. ... You aren't error checking your dbi statements - do you have RaiseError ... sender of the delivery error by replying to this message, or notify us by ...
    (perl.dbi.users)
  • Re: Evaluated "require $database" not found.
    ... DBI Error 1046: No database selected ... What I have found is that if the spaceare removed as per the correct syntax, then the DBI_errorhandler will trap and report a connection failure if a non-existent database is specified, as per this example: ... This requires that you first have an installation of mysql setup on a host ...
    (perl.dbi.users)
  • Re: Cant call method "prepare" on an undefined value
    ... Somehow you managed to have an undefined value instead of a DBI database handle in front of ->prepare, which is burried deep inside Oraperl.pm. ... Oracle HTTP Server at Server B. Both server are Solaris server. ... I have installed DBI and DBD into Server B and setup the oraperl in my perl script. ...
    (perl.dbi.users)
  • Balasan: RE: Balasan: RE: Balasan: RE: Balasan: RE: cant execute "use $database"
    ... dictionary of the each database of my MSSQL. ... to load it -- DBI will load it for you. ... Subject: Balasan: RE: Balasan: RE: Balasan: RE: ...
    (perl.dbi.users)