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.";

Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com



-----Original Message-----
From: Ronald J Kimball [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 16, 2005 10:14 AM
To: NIPP, SCOTT V (SBCSI); [email protected]
Subject: RE: NULL field matching problem...




NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED] wrote:
 
>       I am working on a script that parses a csv file.  The actual
> field delimiters in the file are pipes |.  The problem I am running
into
> is that if the field is empty, then the database is getting a '0'
rather
> than 'NULL' as it should.  The column is setup properly with NULLs
> allowed and the default value of NULL.  Here is a sample of the file
> being parsed...
> 
>
SANDBOX|0|750|0.0|junk|N|0.0|9000/800/RP7410|Unknown|B.11.11|junk|junk|s
> erial number|Sandbox|hostname|0||CHTSAN|UNKNOWN|ROBERT C|JONES SR.|
> 
>       The problem on this line is the field between '0' and 'CHTSAN'.
> This ends up as a zero in the database.  When I parse the file again
to
> compare the values, this comes up as a mismatch when it should
actually
> be a match.  How do I fix this?  Thanks in advance for any help.  Here
> is the pertinent code.

You need to figure out how the value in the database is getting set to 0
rather than to NULL.  You should be looking at the code that parses the
file
and inserts into the database, not the code that compares the values
later.

Ronald


Reply via email to