Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
Need help

Need help

2007-10-19       - By Armando Gomez

 Back
I am working on getting data from a DBF and saving it on a CSV file and then
putting it on MySql

The program work great when it is only one but now I need to make the
program go look to a CSV file

And get from there the filenames this is the CSV file :



1458,juan armando,1458DATA,armano@(protected)

2500,Armando Guajardo,2500DATA,a5026@(protected)

3500,AAA,3500DATA,ar@(protected)

3700,Armando Juan ,3700DATA,armzg@(protected)

4500,padawan,4500DATA,padawan@(protected)



The filename is the 3rd Column

So I try to get them by an array



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) {    





but it give me an error message like this

DBD::CSV::db do failed: Can't call method "fetchrow_array" on unblessed
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 19.

DBD::CSV::db do failed: Can't call method "fetchrow_array" on unblessed
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 19.





This is complete code



#!/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) {





$dbhC->do("CREATE TABLE $row->[2].csv 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].csv'

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].csv")

{

               print "Advertencia el archivo existe iniciando el borrando
del mismo ";

        unlink ('c:/proyecto/$row->[2].csv');

}





}







Can someone help me?

Thanks