Mac OSX 10.3 - DBI:CSV - after select executes statement handle says rows !=0, but all values undefined

From: Thuan-Jin Kee (kee_at_wehi.EDU.AU)
Date: 11/29/04

  • Next message: Thuan-Jin Kee: "Update: Mac OSX 10.3 - DBI:CSV - after select undefined values in rows seems to have something to do with the eol character"
    Date: Mon, 29 Nov 2004 16:53:07 +1100 (EST)
    To: dbi-users@perl.org
    
    

    Hi everyone,

    I've got another newbie question -

    I'm able to grab the correct number of rows out of the csv file no
    problems now, but the actual values in the rows are blank.

    If I have the following file
    # this comment not part of the csv file
    custID,family,given^M

    1,adams,mortica^M

    1,adams,gomez^M

    1,golden,gollum^M

    1,greedy,grover^M

    #this comment not part of the csv file either

    and the following code

    #!/usr/bin/perl -Wall
    use strict;
    use DBI;

    my($dbh, $sth);
    my($key, @row);

    $dbh = DBI->connect("DBI:CSV:f_dir=./")
                or die "Cannot connect: " . $DBI::errstr;

    $sth = $dbh->prepare("select custID,family,given from customer")
                 or die "Cannot prepare: " . $dbh->errstr();

    $sth->execute() or die "Cannot execute: " . $sth->errstr();

    print "number of rows found: ". $sth->rows;
    while(@row = $sth->fetchrow_array())
    {
            print join("-",@row);
    }
    $sth->finish();
    $dbh->disconnect() or die "Can't disconnect ". $dbh->errstr();
    #end code that sort of works

    I get the following output

    $ ./selectcsvfile.pl
    number of rows found: 5
    Use of uninitialized value in join or string at ./selectcsvfile.pl line 19.
    Use of uninitialized value in join or string at ./selectcsvfile.pl line 19.

    --
    Use of uninitialized value in join or string at ./selectcsvfile.pl line 19.
    Use of uninitialized value in join or string at ./selectcsvfile.pl line 19.
    --
    Use of uninitialized value in join or string at ./selectcsvfile.pl line 19.
    Use of uninitialized value in join or string at ./selectcsvfile.pl line 19.
    --
    Use of uninitialized value in join or string at ./selectcsvfile.pl line 19.
    Use of uninitialized value in join or string at ./selectcsvfile.pl line 19.
    --
    Use of uninitialized value in join or string at ./selectcsvfile.pl line 19.
    Use of uninitialized value in join or string at ./selectcsvfile.pl line 19.
    --
    end of output
    which says to me that I'm retrieving all five rows, and getting the right
    number of columns in each row. but each of the values in the actual array
    are undefined.
    To my eye, I can't tell the difference between my code and the code up on
    here
    http://ironbark.bendigo.latrobe.edu.au/subjects/int32we/lectures/w09.d/Lect18.html
    on the first example of the section called SELECT subtleties.
    Please tell me what I'm missing?
    Yours
    Jin
    

  • Next message: Thuan-Jin Kee: "Update: Mac OSX 10.3 - DBI:CSV - after select undefined values in rows seems to have something to do with the eol character"

    Relevant Pages

    • Re: Inconsistency of Export to a CSV file.
      ... A CSV file is a txt file with a different extension. ... >>Public Sub ExportDelim(strTable As String, ... >> Dim varData As Variant ... >> Dim intFileNum As Integer ...
      (microsoft.public.access.externaldata)
    • Re: type conversion error
      ... Take a look to the missing data in your csv file so you can understand why ... ByVal HDR As Boolean) As String ... Dim strFolder As String ... Dim strFileName As String ...
      (microsoft.public.access.modulesdaovba)
    • Re: How to open a .CSV file ?
      ... I'm really having trouble understanding why you feel the need to insult ... I suppose by your reasoning every file is just a big long string and we ... I assume when you said "parse at the comma" you meant string.split. ... If I save the .CSV file to an .XLS file, ...
      (microsoft.public.dotnet.languages.vb)
    • Re: How to ignore extra or missing columns?
      ... the best approach would be to parse the CSV file ... Function Make20(Line As String, NFields As Long) As String ... John Nurick [Microsoft Access MVP] ...
      (microsoft.public.access.externaldata)
    • Re: How to open a .CSV file ?
      ... I suppose by your reasoning every file is just a big long string and we should all be using the string manipulation functions to work with them. ... programming possibilites. ... I assume when you said "parse at the comma" you meant string.split. ... If I save the .CSV file to an .XLS file, ...
      (microsoft.public.dotnet.languages.vb)