Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Problem with DBI, DBD::XBase

by hgtmp (Initiate)
on Jan 18, 2013 at 10:09 UTC ( #1014014=perlquestion: print w/replies, xml ) Need Help??
hgtmp has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks.
I would like to get in contact with your wisdom.
My Problem is:
I would like to read out a DBF-file with Perl. So I decide to install DBI and DBD::XBase.
I wonder what values I get on this way in comparison to 'Simple DBF Browser'

DBI, DBD::XBase Simple DBF Browser
3.64659971882507e-317 2012
3.77611606348848e-317 2013
3.90563240815189e-317 2014
4.0351487528153e-317 2015
4.1646650974787e-317 2016
4.29418144214211e-317 2017

I 'prefer' the values (years) 'Simple DBF Browser' returns because on a third way I get the same values.

My OS is Windows XP and I use Strawberry Perl 5.16.

I search the web for the problem, but found no hint.
Hope you can help me on!
Any hint will be great.

Thanks in advance, Holger

use DBI; my $dbf_dir = 'C:/Data/MoSes_Automatisierung/ws_test_orig/output/mcev/ +EEV12Q2/EEV_batchrun_1/'; my $tbl = 'EEV_DET_BATCHRUN_1~MAIN.DBF'; my $dbh = DBI->connect("DBI:XBase:".$dbf_dir) or die $DBI::errstr; # { my $sth = $dbh->prepare("select CAL_YEAR from $tbl") or die $dbh-> +errstr(); $sth->execute() or die $sth->errstr(); while (my @DATA = $sth->fetchrow_array()) { print join(',', @DATA), "\n"; } $sth->finish(); } $dbh->disconnect();

Replies are listed 'Best First'.
Re: Problem with DBI, DBD::XBase
by stefbv (Curate) on Jan 19, 2013 at 09:48 UTC

    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

      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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1014014]
Approved by vinoth.ree
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2018-06-19 09:24 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.