Re: a little suggestion on DB
| From: | Stig S. Bakken | Date: | Fri, 22 Nov 2002 23:15:57 +0000 |
| Subject: | Re: a little suggestion on DB | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-2815@lists.php.net to get a copy of this message | ||
On Fri, 2002-11-22 at 21:00, Pablo Enrique Roman Asenjo wrote:
> Dear pear-designers,
>
> In order to have a very flexible library, i have one observation on DB
> nextId() function:
> If you build a system in mysql using auto_increment pk, then you perform all
> insert using last_insert_id(). It could be greater to generalize the nextId
> function to report the last_insert_id() if it is the case of mysql and the
> argument is empty.
> That could simplify a lot of migration stuff from one database to another.
Actually, it is the other way around :-)
In for example Oracle, you may request the current value of a sequence
with "sequence.currval", but you have no guarantee that some other
process is doing the same thing at the same time and getting the same
id. Because of this we _always_ request the _next_ key, which is an
atomic operation. The value is incremented before it is fetched, and it
is protected so that other processes must wait until the increment/read
is done before doing their own increment/read.
- Stig