Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Escaping Apostrophe

by haukex (Archbishop)
on Oct 20, 2017 at 13:49 UTC ( [id://1201750]=note: print w/replies, xml ) Need Help??


in reply to Escaping Apostrophe

My first suggestion is to not re-invent the wheel, see for example SQL::Abstract (Update: example).

Also, you should always use placeholders wherever possible - see Bobby Tables!

DBI provides quote and quote_identifier, but I'd consider those a last resort if the above is not applicable for whatever unlikely reason.

Replies are listed 'Best First'.
Re^2: Escaping Apostrophe
by perl_gvenk (Initiate) on Oct 20, 2017 at 14:02 UTC
    Not trying to reinvent the wheel. But this is the code we have in just one of many places, using abstract or anything else will require a lot of changes through the code. All I need is a quick and dirty solution with what I have.

      Quick, dirty — and, per other replies, kinda crazy (and also untested):

      my ($row_sub_i_esc_sq = $row[$idx]) =~ s{ ' }{\\}xmsg; $updstmt .= $hdr[$idx]." = '". $row_sub_i_esc_sq ."' \r\n";
      And BTW: It looks like you're dealing with single-quote characters, not apostrophes.

      Update: Oops... Meant to write  s{ (?= ') }{\\}xmsg; and the substitute-on-assignment expression is also wrong, so finally (I think):

      (my $row_sub_i_esc_sq = $row[$idx]) =~ s{ (?= ') }{\\}xmsg; $updstmt .= $hdr[$idx]." = '". $row_sub_i_esc_sq ."' \r\n";
      Thanks choroba. Of course, that's what always happens when I post untested stuff.


      Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

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

    No recent polls found