Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Problem with MySql SELECT

by padawan_linuxero (Scribe)
on Oct 19, 2007 at 22:29 UTC ( [id://646100]=perlquestion: print w/replies, xml ) Need Help??

padawan_linuxero has asked for the wisdom of the Perl Monks concerning the following question:

hello again!!
I have right now a problem I have a program to pick up data from a DBF and then convert all data to CSV,
and then with the data on a CSV put it in a table in MySql
but the problem facing right now is this :
DBD::CSV::db do failed: Can't call method "fetchrow_array" on unblesse +d reference at C:/Perl/site/lib/SQL/Statement/Functions.pm line 560. Can't use an undefined value as an ARRAY reference at C:/Perl/site/lib +/SQL/Statement.pm line 264. [for Statement "SELECT * FROM IMPORT (?)"] at testdbf4.pl line 20. DBD::CSV::db do failed: Can't call method "fetchrow_array" on unblesse +d reference at C:/Perl/site/lib/SQL/Statement/Functions.pm line 560. Can't use an undefined value as an ARRAY reference at C:/Perl/site/lib +/SQL/Statement.pm line 264. [for Statement "SELECT * FROM IMPORT (?)"] at testdbf4.pl line 20.
And this is where the program stops everytime :
while ( my $row = $sth->fetch) { print "data es $row->[2].csv\n"; $dbhC->do("CREATE TABLE $row->[2] AS IMPORT(?)",{},$select);
this is the full code of the program :
#!/usr/bin/perl use warnings; use strict; use DBI; #---- This part conects to my 2 databases one CSV and one XBase ----- my $dbhX = DBI->connect('dbi:XBase(RaiseError=1):'); my $dbhC = DBI->connect('dbi:CSV(RaiseError=1):'); my $select = $dbhX->prepare("SELECT * FROM reg501"); $select->execute(); #--- This one to the table on CSV where I have the data ------ my $dbh = DBI->connect("DBI:CSV:f_dir=/Proyecto/") or die "Cannot connect: " . $DBI::errstr; my $sth = $dbh->prepare("SELECT * from patentes.csv") or die "Cannot prepare: " . $dbh->errstr(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); while ( my $row = $sth->fetch) { print "data es $row->[2].csv\n"; $dbhC->do("CREATE TABLE $row->[2] AS IMPORT(?)",{},$select); my $mysql_dbh = DBI->connect("DBI:mysql:database=test;host=localhost", "root", "xyz123", {'RaiseError' => 1}); #---- Here I empty the table in MySql ------ $mysql_dbh->do("TRUNCATE TABLE $row->[2]"); #---- Here I load all the data ------- my $sql = "LOAD DATA LOCAL INFILE 'c:/proyecto/$row->[2]' INTO TABLE $row->[2] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'"; my $sth = $mysql_dbh->prepare($sql); $sth->execute (); if (-e "c:/proyecto/$row->[2]") { print "Advertencia el archivo existe iniciando el borrando del mis +mo "; unlink ('c:/proyecto/$row->[2].csv'); } }
This a very important program for me I hope you can help me
Thanks :o)

Replies are listed 'Best First'.
Re: Problem with MySql SELECT
by jasonk (Parson) on Oct 20, 2007 at 00:40 UTC

    You need to make sure your connects succeed, you are getting those errors because $dbhC is undef, because you didn't specify which CSV to open.


    We're not surrounded, we're in a target-rich environment!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2026-04-22 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.