Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Inserting Apostrophes into SQL

by jfroebe (Parson)
on Nov 16, 2011 at 19:50 UTC ( #938452=note: print w/replies, xml ) Need Help??

in reply to Inserting Apostrophes into SQL

Another, less elegant IMHO, option would be to use $query = sprintf "insert into da_table values (%s)", $dbh->quote("kjasdfkj'asdflkjasef'sadfhasdfsadf'asdfhasfd'");

Jason L. Froebe

Blog, Tech Blog

Replies are listed 'Best First'.
Re^2: Inserting Apostrophes into SQL
by chromatic (Archbishop) on Nov 16, 2011 at 22:54 UTC

    Sure, but it's slower and more complicated than placeholders, and easier to get wrong. Why even suggest it? Is there a case where you can't use placeholders?

    Improve your skills with Modern Perl: the free book.

      Actually I did run into a Sybase bug a few years ago where the placeholders resulted in the connection being dropped.

      Jason L. Froebe

      Blog, Tech Blog

        a Sybase bug

        I hope that's fixed, but say no more. I've had to work around my share of Sybase weirdnesses.

        Improve your skills with Modern Perl: the free book.

      Sybase can only have one active statement handle, but will transparently clone a database handle when necessary (unless you set the "I don't want that" flag).

      This means you may run into issues like deadlocks if you're, e.g., inserting in the same loop that you're selecting and fetching in (or other strangeness from having two separate sessions).

      And then I also ran into a bug where the cloned database handle didn't have the same client character set as the original (reported on the DBI mailing list).

      Update: And I just noticed that the OP doesn't mention Sybase this point may be moot anyway...

        Just a small clarification - it's not Sybase that clones the connection handle - it's DBD::Sybase that does this to try to provide the behavior that DBI expects.


Re^2: Inserting Apostrophes into SQL
by ikegami (Pope) on Nov 16, 2011 at 22:15 UTC
    I remember being unable to do that for a numeric field. Do I remember incorrectly?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://938452]
[mark4]: thanks. I installed "PAR-packager" and pp is working. BTW, it is pp.bat that was needed.
[mark4]: Sorry, There was a typo in my last message. I installed "PAR-Packer" and I now have a pp.bat and all is working well. Thanks again for your help.

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2018-01-19 21:29 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (223 votes). Check out past polls.