RE: NULL field matching problem...

From: Ian Harisay (imharisa_at_nuskin.com)
Date: 03/16/05


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



Relevant Pages

  • RE: NULL field matching problem...
    ... Subject: NULL field matching problem... ... I'm guessing that when a field is empty in your CSV file, ... to an undef before binding with bind_param. ...
    (perl.dbi.users)
  • RE: NULL field matching problem...
    ... Subject: NULL field matching problem... ... I'm guessing that when a field is empty in your CSV file, ... to an undef before binding with bind_param. ...
    (perl.dbi.users)
  • Possible problem with feof and/or fgets?
    ... I am reading in a csv into Matlab, and in the particular case we are ... having issues with the file is empty. ... Open strScenarioFile For Output As #iFileNumber ...
    (comp.soft-sys.matlab)
  • Re: Export to CSV
    ... Ok, No "I" don't have the text file open, I tried, creating an empty text file ... when I go thru the wizard to export data it prompts me for a DSN selection ... I honestly never had to export to a CSV before, I've always been in a position ... >> TIA ...
    (microsoft.public.sqlserver.dts)
  • Re: csv to phpmyadmin
    ... I don't know anything about SQL or PHP. ... Then I opened that .csv file in NotePad and it looked ok to me: ... I tried it again with all of column A empty and it still looked ok in the .csv ... > because I need it to auto-incrment in PHPMYADMIN afetr upload. ...
    (microsoft.public.excel.misc)