Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: SQL quoting problem

by cadfael (Friar)
on Oct 16, 2000 at 20:39 UTC ( [id://36954]=note: print w/replies, xml ) Need Help??


in reply to SQL quoting problem

For what it is worth, Sybase (related to SQL Server) will tolerate both single and double quotes in sql queries. You need to be consistent, though.

I am using Sybase ASE 12.0 and DBD::Sybase to allow users to query a full-text server that joins with another database.

I put my queries into variables and escape any embedded quotes. This permits me to employ nested quotes in certain situations:

$query = "select col_a, col_b, col_c from tablea, tableb where tablea..pkey = tableb..fkey and tablea..column_x = '$fts'";
The $fts string must be enclosed in single quotes, and may contain literals, which need to be enclosed in double quotes:
$fts = "(seedling \<or\> kernel \<or\> embryo) \<and\> \"viab*\" ";
Note that the only time I actually need to escape the quotes are when a double quote is employed within a string variable.

The final form of the query passed to the Sybase server is:

select a,b,c from tablea, tableb
where tablea..pkey = tableb..fkey
and tablea..column_x = '(kernel <or> embryo) <and> "viab*"'

-----
"Computeri non cogitant, ergo non sunt"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-23 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found