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)" <[EMAIL PROTECTED]> 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:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com



-----Original Message-----
From: CAMPBELL, BRIAN D (BRIAN) [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 16, 2005 10:54 AM
To: NIPP, SCOTT V (SBCSI); Ronald J Kimball; [email protected]
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:[EMAIL PROTECTED]
Sent: Wednesday, March 16, 2005 9:18 AM
To: Ronald J Kimball; [email protected]
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.";



Reply via email to