Re: MySQL data matching error...
From: Amonotod (amonotod_at_charter.net)
Date: 09/20/04
- Next message: Amonotod: "DBD::CSV and large files..."
- Previous message: Vahe - NC Sarkissian: "RE: String truncation in insert to SQL Server with DBD::ADO and p lace holders"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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____________________________________
_____|_____|_____|_____|_____|_____|_____|_____|
- Next message: Amonotod: "DBD::CSV and large files..."
- Previous message: Vahe - NC Sarkissian: "RE: String truncation in insert to SQL Server with DBD::ADO and p lace holders"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|