Re: Autoincrement & Sequences
| From: | Manuel Lemos | Date: | Sat, 01 Dec 2001 21:55:03 +0000 |
| Subject: | Re: Autoincrement & Sequences | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-3274@lists.php.net to get a copy of this message | ||
Hello,
Paul Meagher wrote:
> I think that if you want to do portable db programming you need to resort
> to using a sequences table even thought this is inefficient because 1) it
> involves an extra query and 2) alot of the processing is done in PHP
> userspace (versus c space with the MySQL autoincrement feature).
>
> The only other option I can think off would be to somehow intercept the
> queries before they hit the db and rewrite them to a format that works for
> the particular db.
>
> $sql = "INSERT INTO myTable (text) VALUES ('foo')";
> $db>query($sql, "auto", id);
>
> For MySQL the SQL would would not need to be rewritten.
>
> For Postgres the SQL would need to be rewritten (behind the scenes).
>
> Not sure exactly how Metabase works in this case as I have not had a chance
> to look at it too much yet.
Using tables with auto-incremented fields was an invention of Metabase.
It was a feature that it already had 2 years ago when it when publicly
released. Other PHP abstraction layers just borrowed the idea, which I
don't have a problem because it is a good idea.
Some database have sequences and others have auto-incremented fields.
Few databases provide both. Anyway, what matters is that you can emulate
sequences portably with auto-incremented fields and not the other way
around. This is why sequences is the way to go for truely portable
applications.
Regards,
Manuel Lemos