Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: One Question about DBF

by jZed (Prior)
on Oct 18, 2007 at 17:22 UTC ( [id://645779]=note: print w/replies, xml ) Need Help??


in reply to One Question about DBF

As I explained to you in response to your last posting, that syntax is MySQL-specific. One way to go from Xbase (or any DBI accessible RDBMS) to CSV is to use DBD::AnyData DBD::CSV like this:
#!/usr/bin/perl use warnings; use strict; use DBI; my $dbhX = DBI->connect('dbi:XBase(RaiseError=1):'); my $dbhC = DBI->connect('dbi:CSV(RaiseError=1):'); my $select = $dbhX->prepare("SELECT * FROM inTable"); $select->execute(); $dbhC->do("CREATE TABLE outTable AS IMPORT(?)",{},$select); __END__

Update : replaced my bad code with a working example.

my $dbhX = DBI->connect ( Xbase connection info); my $dbhA = DBI->connect( 'dbi:AnyData:' ); $dbhA->ad_catalog('outfile','CSV',$output_filename); my $sth = $dbhX->prepare( Select SQL ); $sth->execute(); $dbhA->do("CREATE TABLE outfile AS SELECT * FROM ?",{}, $sth);

Replies are listed 'Best First'.
Re^2: One Question about DBF
by padawan_linuxero (Scribe) on Oct 18, 2007 at 18:43 UTC
    Hello jZed
    I try you code and put what a like to think are the correct parameters and did not work :o(
    Ok I am going very level with you I just need to get all data from a DBF table and put it in a CSV file
    here you can look at my code and please tell me what is wrong
    thanks
    use DBI; my $dbhX = DBI->connect("DBI:XBase:/proyecto"); my $dbhA = DBI->connect( 'dbi:AnyData:' ); my $sth = $dbhX->prepare("SELECT * FROM reg501"); $sth->execute(); $dbhA->do("CREATE TABLE etstx AS SELECT * FROM ?",{}, $sth);
    TIA
      Oh, sorry, yeah, after the $dbhA line put this:
      $dbhA->ad_catalog('etstx','CSV','etstx.csv');
      The first param is the table name to use in your SQL, the second the format of the file the table will be stored in, the third the path/filename of the file.

      update : added the missing ad_

        Hi jZed!
        I added the line as you told me but it gave me these error
        Can't locate object method "catalog" via package "DBI::db" at testdbf.pl line 5.
        This is the code
        use DBI; my $dbhX = DBI->connect("DBI:XBase:/proyecto"); my $dbhA = DBI->connect( 'dbi:AnyData:' ); $dbhA->catalog('etstx','CSV','etstx.csv'); my $sth = $dbhX->prepare("SELECT * FROM reg501"); $sth->execute(); $dbhA->do("CREATE TABLE etstx AS SELECT * FROM ?",{}, $sth);
Re^2: One Question about DBF
by padawan_linuxero (Scribe) on Oct 18, 2007 at 22:07 UTC
    jZed!!!
    YOU ARE MY HERO!!!!
    THANK YOU !!!!
    :o)
    IT WORK GREAT!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://645779]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-26 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found