Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Mysql and Perl Module

by Anonymous Monk
on Jun 14, 2012 at 09:26 UTC ( #976160=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Mysql and Perl Module
in thread Mysql and Perl Module

See this example program Re: Open multiple file handles?

You can easily create a module with a function like this

sub IntoDbImportCSV { my( $dbiconn, # dbi connection string $colnames, # column names $csvfile, # path to csv file $csvargs, # Text::CSV->new options hash ) = @_; my $dbh = DBI->connect( $dbiconn, undef, undef, { RaiseError => 1, PrintError => 1, }, ); open my($infh), '<', $csvfile ... my $csv_in = ... $dbh->begin_work; my $sth = $dbh->prepare($sql); while ( my $row = $csv_in->getline( $infh ) ) { $sth->execute( @{ $row } ); } $dbh->commit; $dbh->disconnect; } IntoDbImportCSV( 'dbi:SQLite:dbname=temp.test.sqlite', '/path/to/foo.cvs', ['ro', 'sham', 'bo' ], { quote_char => '"', sep_char => ',', allow_loose_escapes => 1, empty_is_undef => 1, binary => 1, auto_diag => 1, }, );


Comment on Re^3: Mysql and Perl Module
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-09-18 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (126 votes), past polls