Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Why does this script die?

by dws (Chancellor)
on Sep 11, 2003 at 16:19 UTC ( [id://290737]=note: print w/replies, xml ) Need Help??


in reply to Why does this script die?

It appears to die on a line that contains a single quote:

You have a variable that holds a string that contains an embedded quote. You then interpolate that variable into another string, which holds the beginning of an SQL query. You end up with extra quotes in the SQL, rendering it syntactically invalid. The execute() fails, which you aren't detected because you're not checking. Since it returns undef, the code is going to blow a few lines later.

The solution to this is really simple. It's already in your code. Use query parameters, and pass the values you want to bind to the parameters to execute(), which will automagically escape any embedded single quotes (or other characters that need escaping). Check() does this. Why doesn't Insert()?

Add some error checking while you're at it.

Replies are listed 'Best First'.
Re: Re: Why does this script die?
by Notromda (Pilgrim) on Sep 11, 2003 at 16:55 UTC
    Doh! I always use placeholders! Why didn't that have place holders? I'm at a loss for words... that's just not my usual programming style.

    Don't I feel stupid. Thanks for pointing that out. Funny how you can stare at something and miss the obvious.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://290737]
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: (3)
As of 2024-04-25 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found