Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 wandering the Monastery: (5)
As of 2015-07-07 09:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls