Re: MySQL data matching error...

From: Amonotod (amonotod_at_charter.net)
Date: 09/20/04


To: "NIPP, SCOTT V (SBCSI)" <sn4265@sbc.com>, <dbi-users@perl.org>
Date: Mon, 20 Sep 2004 16:09:29 +0000


> From: "NIPP, SCOTT V \(SBCSI\)" <sn4265@sbc.com>
> Date: 2004/09/16 Thu PM 07:22:25 GMT
>
> I am having a problem in that if a field is blank, it is getting
> put into the database as a '0' rather than 'NULL'. The table is setup
> to both allow NULL values in this field as well as NULL being the
> default value. The problem is that on a few entries the field is
> actually empty, but the database is entering the value into the table as
> a '0' as mentioned above. Does this problem sound familiar to anyone?

I've seen it before. You need to check the value, and if it's not
a "valid" value, do one of two things:

  1) if you're using place-holders, assign undef() to the value, and
the DBI *should* convert it to NULL.

   if (
       ($myVal) #Is it defined?
       &
       (($myVal eq '') or ($myVal eq ' ') ) #But blank?
       )
       { $myVal = "NULL"; }

  2) But, if you're building the full insert statement with the values,
just set it to "NULL" before passing it in...

   if (
        (
         ($myVal) #Is it defined?
         &
         (($myVal eq '') or ($myVal eq ' ') ) #But blank?
        ) or (
         (!$myVal) #Or maybe it's undefined...?
        )
       )
       { $myVal = "NULL"; }

I'm sure you could build the second part of the compare with m//, perhaps
like m/\A\s+\Z/ or something similar, but I pretty much suck at regex's,
so I dunno...

> Scott Nipp

HTH,
amonotod

--
    `\|||/         amonotod@    | sun|perl|windows
      (@@)         charter.net  | sysadmin|dba
  ooO_(_)_Ooo____________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Relevant Pages

  • Priority Queue implemented as LinkedList api class java
    ... LinkedList class found in the api. ... iterator to step through all entries in the PQ and return the one with the ... I am thinking store the first entry in a temp variable and compare the rest ... When the minimum key is ...
    (comp.lang.java.help)
  • Re: user-level security
    ... >To use their login and compare it to table entries, ... >CurrentUser() function. ...
    (microsoft.public.access.security)
  • Re: scaling fxn unique to dataset
    ... Daniel Boone wrote: ... all entries are saved as "data". ... compare the uniqueto wordlist to return the number ... If data and wordlist are cell strings, ...
    (comp.soft-sys.matlab)
  • Re: user-level security
    ... To use their login and compare it to table entries, ... CurrentUser() function. ...
    (microsoft.public.access.security)
  • Re: Java algorithm (diff) question.
    ... The entries in each file are not ... My requirement is only to compare if lines with the same key in file1 ... Does digest-64 guarantee that two different strings always hash to ...
    (comp.lang.java.programmer)