Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Extra quotes doing SQL insert from Perl to CSV.

by poj (Abbot)
on Oct 10, 2019 at 16:26 UTC ( [id://11107316]=note: print w/replies, xml ) Need Help??


in reply to Extra quotes doing SQL insert from Perl to CSV.

Use placeholders and always_quote option

#!/usr/bin/perl use strict; use DBI; my $dbh = DBI->connect("dbi:CSV:", "", "",{ 'RaiseError' => 1 } ); $dbh->{'csv_tables'}->{'MyTable'} = { 'file' => 'data1.csv', 'col_names' => ["num","id"], 'always_quote' => 1, }; my $num = '0123'; my $id = '0124'; my $sql = "INSERT INTO MyTable VALUES (?,?)"; my $result = $dbh->do($sql,undef,$num,$id);
poj

Replies are listed 'Best First'.
Re^2: Extra quotes doing SQL insert from Perl to CSV.
by JamieJ (Novice) on Oct 10, 2019 at 18:46 UTC
    poj, Excellent! That did the trick, particularly 'always_quote' => 1 Thank you so much! -JJ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-25 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found