Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The way that you do this *correctly* in oracle is to make use of its "returning" clause, and the DBI's bind_param_in_out() method. This is the only way to properly avoid concurrency issues, and it also works cleanly and is fast.

In code, it looks something like this:

my $sql = "insert into foo (name,value) values (?,?) returning id into + ?"; my $sth = $dbh->prepare($sql); $sth->bind_param(0, $name); $sth->bind_param(1, $value); $sth->bind_param_inout(2, \$id, 1024); # this is a reference that gets + written to! $sth->execute; print $id; # or whatever... $id has been written into by the execute
Assuming that the id column is driven by a sequence and a trigger.

Granted, doing individual calls to bind_param / bind_param_inout is kind of painful and ugly, so when I do this I actually written a wrapper around calling all the binding, but this is the crux of what it does / how it works.

------------ :Wq Not an editor command: Wq

In reply to Re: Sequences, last_insert_id, SQLite, and Oracle by etcshadow
in thread Sequences, last_insert_id, SQLite, and Oracle by gaal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2024-04-23 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found