RE: [PEAR-DEV] Re: Autoincrement & Sequences
| From: | Lukas Smith | Date: | Sun, 02 Dec 2001 04:10:13 +0000 |
| Subject: | RE: [PEAR-DEV] Re: Autoincrement & Sequences | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-3279@lists.php.net to get a copy of this message | ||
So this would only work if you where to build the query from pieces
(like creating a query object), but this would probably go against the
speed goals. Otherwise you would have to parse the query.
The only other solution would be to create a fair amount of functions:
$sql = "INSERT INTO myTable
(".write_id_name_with_not_auto_with_seperator('id_name')." text) VALUES
(".get_seq_val_with_seperator('some_seq')." 'foo')";
$db->query($sql);
looks quite ugly to me :-)
If you also want the seq value then things could get even uglier
$sql = "INSERT INTO myTable
(".write_id_name_if_not_auto_with_seperator('id_name')." text) VALUES
(".put_seq_val_here_with_seperator()." 'foo')";
$id = $db->query_seq($sql, 'some_seq');
query_seq()
Sequence enabled:
Get ID
use the ID in the Insert
return the generated ID.
Autoincrement enabled:
do the Insert
return ID via mysql_insert_id
I am too tired to explain the other functions I have used but I made
their names fairly descriptive.
The auto increment could be set similarly to the create sequences. For
mysql this would then of course be a sequence linked to a table (I am
not into MSSQL but isn't this the case for sequences there too?).
But also note that sequences are still more flexible than auto
increment, so even with my suggestion is not thrown out as ugly as hell,
I would like true sequence emulation for mysql.
So with the few sleep I got in the last couple days and the fact that
its already 4am here I do not really have a solution for this. Damn I
hope this stuff made sense and I did not waste people's time :-)
Best regards,
Lukas Smith
smith@dybnet.de
_______________________________
DybNet Internet Solutions GbR
Alt Moabit 89
10559 Berlin
Tel. : +49 30 83 22 50 00
Fax : +49 30 83 22 50 07
www.dybnet.de info@dybnet.de
_______________________________
> -----Original Message-----
> From: Manuel Lemos [mailto:mlemos@acm.org]
> Sent: Saturday, December 01, 2001 10:55 PM
> To: pear-dev@lists.php.net
> Subject: [PEAR-DEV] Re: Autoincrement & Sequences
>
> 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
>
> --
> PEAR Development Mailing List (http://pear.php.net/)
> To unsubscribe, e-mail: pear-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: pear-dev-help@lists.php.net
> To contact the list administrators, e-mail:
php-list-admin@lists.php.net