RE: NULL field matching problem...
From: Ian Harisay (imharisa_at_nuskin.com)
Date: 03/16/05
- Next message: Jeff Zucker: "Re: NULLs in Text::CSV_XS and DBD::CSV"
- Previous message: Jeff Zucker: "Re: NULLs in Text::CSV_XS and DBD::CSV"
- Maybe in reply to: Scott V \ Nipp: "NULL field matching problem..."
- Next in thread: Greg Sabino Mullane: "RE: NULL field matching problem..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 16 Mar 2005 10:39:22 -0700 To: <dbi-users@perl.org>
after you populate @data you can do: (code is untested, but I think I
have it right)
foreach(@data){
$_ = undef if $_ =~ /^$/;
}
>>> "NIPP, SCOTT V (SBCSI)" <sn4265@sbc.com> 03/16/2005 9:57:03 AM >>>
That sounds good, but I am a little confused on exactly how to
achieve that. I'll start poking around, but... Thanks for the
pointer
at least.
Scott Nipp
Phone: (214) 858-1289
E-mail: sn4265@sbc.com
Web: http:\\ldsa.sbcld.sbc.com
-----Original Message-----
From: CAMPBELL, BRIAN D (BRIAN) [mailto:campbelb@lucent.com]
Sent: Wednesday, March 16, 2005 10:54 AM
To: NIPP, SCOTT V (SBCSI); Ronald J Kimball; dbi-users@perl.org
Subject: RE: NULL field matching problem...
I'm guessing that when a field is empty in your CSV file, then the
method $csv->fields puts an empty string value (e.g. "") in the
corresponding element in your @data array (not an undef value).
If so, you are going to have to detect for this condition and change
it
to an undef before binding with bind_param. Undef will cause a null
to
be inserted. In general, you would need to do this to all fields that
you want to represent as null, when they are represented as empty
fields
in the CSV input.
-----Original Message-----
From: NIPP, SCOTT V (SBCSI) [mailto:sn4265@sbc.com]
Sent: Wednesday, March 16, 2005 9:18 AM
To: Ronald J Kimball; dbi-users@perl.org
Subject: RE: NULL field matching problem...
I thought about that after I hit the send button. Here is the
INSERT code...
my $sth = $dbh->prepare("INSERT INTO AllMid_Data VALUES(?".(",?" x
21).")")
or print "Error with INSERT _prepare_ $DBI::errstr\n";
my $test = $dbh->prepare(qq{SELECT * FROM AllMid_Data WHERE CPU_DNS =
?
AND CPU_Hostname = ?});
while (my $file = <CSV>) {
# Next two lines parse the CSV data from AllMid
my $line = $csv->parse($file);
my @data = $csv->fields($file);
$test->execute ($data[4], $data[14]);
my $rows = $test->rows;
if ($rows == 0) {
# print "Entry not found. Inserting into database. \n"; #
Testing
line
$sth->bind_param(1, undef);
$sth->bind_param($_+2, $data[$_]) foreach 0..20;
$sth->execute() or print "Data insert failed.";
- Next message: Jeff Zucker: "Re: NULLs in Text::CSV_XS and DBD::CSV"
- Previous message: Jeff Zucker: "Re: NULLs in Text::CSV_XS and DBD::CSV"
- Maybe in reply to: Scott V \ Nipp: "NULL field matching problem..."
- Next in thread: Greg Sabino Mullane: "RE: NULL field matching problem..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|