CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Trouble with Quote

 



pra_perl
Novice

Jun 8, 2015, 7:25 AM

Post #1 of 5 (2956 views)
Trouble with Quote Can't Post

Hi All,

I am using perl behind Vertica DB for the first time.
I am trying to pass a varchar.
if ($aID ne "") { $Where = $Where . "AND m.ALRT_ID IN ($aID) "; }
But in the resulting SQL it is passed as m.ALRT_ID IN (ADCB_l2642_20141002232000_26867) instead of ('ADCB_l2642_20141002232000_26867').

How to pass the single quote to this param?

Thanks,

pragov


FishMonger
Veteran / Moderator

Jun 8, 2015, 7:50 AM

Post #2 of 5 (2955 views)
Re: [pra_perl] Trouble with Quote [In reply to] Can't Post

$aID is a scalar and based on your code snippet, holds a string containing 1 value, so my first question would be "why use an IN clause instead of equality"?

The simplest solution for your posted snippet is to put single quotes around the var.

Code
if ($aID ne "") { $Where .= "AND m.ALRT_ID IN ('$aID') "; }


If $aID is a string of multiple values, then you'll need to split that string and rejoin it while adding single quotes around each value. The map function comes in handy for doing this adjustment.


pra_perl
Novice

Jun 8, 2015, 8:16 AM

Post #3 of 5 (2953 views)
Re: [FishMonger] Trouble with Quote [In reply to] Can't Post

You are correct. I was able to do it using



if ($aID ne "") { $Where .= "AND m.ALRT_ID = '$aID' "; }

Thanks


pra_perl
Novice

Jun 18, 2015, 10:02 AM

Post #4 of 5 (2253 views)
Re: [FishMonger] Trouble with Quote [In reply to] Can't Post

How would I use the LIKE parameter?

if m.ALRT_ID = 'abd-ef-c_gh_i' then
if ($aID ne "") { $Where .= "AND m.ALRT_ID IN ('$aID') "; } works.
But if m.ALRT_ID = 'abd-ef-c_gh_i;kbd-sf-t_ah_x' , I need to still get data.

Thanks


pra_perl
Novice

Jun 18, 2015, 12:39 PM

Post #5 of 5 (2245 views)
Re: [pra_perl] Trouble with Quote [In reply to] Can't Post

I was able to resolve this.
Just added a %age after quote
if ($aID ne "") { $Where .= "AND m.ALRT_ID LIKE ('%$aID%') "; }

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives