Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Calling SQL with embedded quotes

by mpeppler (Vicar)
on May 21, 2002 at 16:04 UTC ( [id://168171]=note: print w/replies, xml ) Need Help??


in reply to Calling SQL with embedded quotes

Your sample above should work with the following:
$test = q/RunSql "delete sometable where strike like '%[A-Za-z]%'"/; $test =~ s/'/''/g; $sql = "update job set cmd='$test' where jobname='somejob'";
You use '' to quote the string that you set "cmd" to, so you just need to make sure that any ' quotes inside that string are doubled.

There are other methods as well - placeholders for example when using DBI or Sybase::CTlib as mentioned by others in this thread, but there are drawbacks to those as well - nothing's perfect :-)

Michael

Replies are listed 'Best First'.
Re: Re: Calling SQL with embedded quotes
by budman (Sexton) on May 22, 2002 at 02:26 UTC
    Thanks all for the advice on placeholders and the use of DBI, both I will further investigate and learn. :)

    The delete does work as indicated, but that delete statement is from a field already in an existing database. I'm just trying to read from one table, and store the field in another table. When I try to store the data, I always get an syntax error due to the inside single quotes. Sometimes there are backticks as well. I guess the real question was how do I stop Perl from interperting the command line as just text and not code that should be executed.

    I'll try Michael's suggestion to see if that works for me.

    Thanks again.
    budman
      That was quick...

      Just doubling the single quotes did the job!

      Thanks.
      budman

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found