Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: Need help escaping literal string

by mrras25 (Acolyte)
on Nov 15, 2012 at 01:47 UTC ( #1003915=note: print w/replies, xml ) Need Help??

in reply to Re: Need help escaping literal string
in thread Need help escaping literal string

Thank you for the reply

How exactly would I do it? Lets say I have a value of
while(@values = $sth->fetchrow_array) { print "$values[8]\n"; }
the return value of that is : /vol/enycmmcfl01b_ssd2_home_1b_a/CBirbigl$'s as you can see if I try and take that value and insert in to an insert statement to execute that through perl
my $insert = "insert into dbtable (vol) values ('$values[8]')";
the insert statement will now fail because it will look like
insert into dbtable (vol) valuse ('/vol/enycmmcfl01b_ssd2_home_1b_a/CB +irbigl$'s')
And well that wont work

Replies are listed 'Best First'.
Re^3: Need help escaping literal string
by roboticus (Chancellor) on Nov 15, 2012 at 02:34 UTC


    That's why davido mentioned placeholders. It's something like:

    # Prepare a statement... my $sth = $dbh->prepare("insert into dbtable (vol) values (?)"); my $funky_string = "/vol/enycmmcfl01b_ssd2_home_1b_a/CBirbigl$'s"; $sth->execute($funky_string);

    This way, you don't have to worry about the odd characters inside your statement. Building your own statements like you were trying to do just leads to the difficulties you're experiencing. That's why placeholders were invented.


    When your only tool is a hammer, all problems look like your thumb.

      OUTSTANDING folks thank you for getting back to me I will give that a whirl and see how that flows...

      Again thanks all

Re^3: Need help escaping literal string
by muba (Priest) on Nov 15, 2012 at 02:20 UTC

    Typically it would look a little like this.

    my $insert = "insert into table (vol) values (?)"; $dbh->do($insert, $values[8]);

    Generally, the notion is that you never directly put variables into SQL statements.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003915]
[erix]: and my solfège is a little rusty too
[stonecolddevin]: damn where's a working cblast? looks like several of them are out of commission
[erix]: Tanktalus home node has one
[stonecolddevin]: erix thanks mate
[stonecolddevin]: also lol @ "I stomped a crap"
[stonecolddevin]: Disciplus i was just amazed he's returned after the thorough stomp that BrowserUk and several other monks gave him for spreading crap info
[stonecolddevin]: i will admit i find the responses to his threads incredibly entertaining

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2017-06-22 20:42 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (529 votes). Check out past polls.