Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: using sequences with dbi

by BigJoe (Curate)
on Oct 04, 2001 at 00:36 UTC ( #116564=note: print w/ replies, xml ) Need Help??


in reply to using sequences with dbi

idunno,

You don't even need the ? like people are suggesting. You can do it very quickly:

$sth = $dbh->prepare("insert into table (blah_key, blah_name) values ( +blah_seq.nextval, '$blah_name')");
In "standard SQL" make sure if it is a non-number put single quotes around it. Sequence.nextval & Sequence.currval are like SYSDATE they are functions in the Database so you don't single quote them.

--BigJoe

Learn patience, you must.
Young PerlMonk, craves Not these things.
Use the source Luke.


Comment on Re: using sequences with dbi
Download Code
Re: Re: using sequences with dbi
by runrig (Abbot) on Oct 04, 2001 at 00:48 UTC
    There are some very good reasons for using placeholders instead of quoting your arguments, or at the very least, using $dbh->quote(...).
      Not to be rude, but why make it more complicated than it is? I have read the links and it looks to like it is mostly personal opinion. When it is something simple and quick I don't use place holders. When it is complicated from the begining then I use place holders. But again that is my personnal opinion.

      --BigJoe

      Learn patience, you must.
      Young PerlMonk, craves Not these things.
      Use the source Luke.

        Because, at the very least, if you run the same program with different parameters, then multiple statements are sent to the server, with different text. This means they have to be reparsed.

        If you use placeholders, then, irrespective of the number of times the statement is executed, the database only ever gets one version of it, but with different parameters. So there's only one parse (which is both faster and more memory efficient for the server).

        Whether or not its 'complicated', if you're executing the same statement many times, its more efficient to use placeholders, especially on a database like Oracle, which keeps a SQL cache of its own, so you would benefit even when you only execute the statement a few times, but execute the script many times.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2014-09-01 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (11 votes), past polls