http://www.perlmonks.org?node_id=1014192


in reply to Problem with DBI, DBD::XBase

Hello Holger,

Running the following code I can see no problems with the years:

use strict; use warnings; use DBI; my $dbf_dir = '.'; my $dbh = DBI->connect("DBI:XBase:$dbf_dir") or die $DBI::errstr; my $def = "CREATE TABLE t_year (cal_year INTEGER)"; unlink 't_year.dbf'; $dbh->do($def); my $sth = $dbh->prepare('INSERT INTO t_year VALUES (?)'); while ( my $year = <DATA> ) { chomp $year; print "Inserting $year\n"; $sth->execute($year) or die $sth->errstr(); } my $sth2 = $dbh->prepare("select cal_year from t_year") or die $dbh->errstr(); $sth2->execute() or die $sth2->errstr(); while ( my @rec = $sth2->fetchrow_array() ) { print "Extracting @rec\n"; } $dbh->disconnect(); __END__ 1990 2000 2010

My output is as expected:

Inserting 1990 Inserting 2000 Inserting 2010 Extracting 1990 Extracting 2000 Extracting 2010

What is the structure of your table?

Regards, Stefan

Replies are listed 'Best First'.
Re^2: Problem with DBI, DBD::XBase
by hgtmp (Initiate) on Jan 21, 2013 at 08:54 UTC
    Hi Stefan.
    I can reproduce your small example and get the years too.
    So I think it is a problem with my DEF-file.
    The DEF-file is created by an external process.
    I am new here. Can I upload a small file?
    Many thanks for your comment, Holger

      Hi Holger,

      You can't upload, but if it's a text file, you can put it's contents here between code tags.

      Stefan

        Hi Stefan.
        I would like to upload the DBF-file which is a binary.
        Do you know a validator for DBF files?
        Thanks in advance, Holger