From: | Christian Kratzer <ck-lists(at)cksoft(dot)de> |
---|---|
To: | Bo Lorentsen <bl(at)netgroup(dot)dk> |
Cc: | Michael Glaesemann <grzm(at)myrealbox(dot)com>, "pgsql-general postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: OID Usage |
Date: | 2005-01-14 09:32:18 |
Message-ID: | 20050114102431.W6920@vesihiisi.cksoft.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
On Fri, 14 Jan 2005, Bo Lorentsen wrote:
> Michael Glaesemann wrote:
>
>> You can use currval() to get the sequence value that was pulled from your
>> insert. You can check the documentation for usage, as well as searching
>> the archives for discussions of using OIDs as part of your database logic.
>
> I know this, but i like not to know anything about the metadata of the table
> i use. Basicly using the same functionality, as given in mysql in the
> mysql_insert_id, as I use the same low level code for both DB's (until my
> boss give in totally to PG :-)).
why should your application not want to know about the metadata of it's
own tables ? That sounds quite strange when you think about it.
If you name your sequences in a generic way you can alway construct the
name of the sequence from the name of the table and the id column.
We use this in our php framework
function insert_id()
{
global $pg_conn;
if(isset($pg_conn)) {
$query = sprintf("SELECT currval('%s_%s_seq') AS id",$this->table,$this->id_column);
$result = @pg_query($pg_conn,$query);
$row = pg_fetch_assoc($result);
return strval($row["id"]);
} else {
return 0;
}
}
Greetings
Christian
--
Christian Kratzer ck(at)cksoft(dot)de
CK Software GmbH http://www.cksoft.de/
Phone: +49 7452 889 135 Fax: +49 7452 889 136
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2005-01-14 10:15:08 | Re: OID Usage |
Previous Message | Richard Huxton | 2005-01-14 09:29:00 | Re: Functions that return RECORD type |