Re: OID Usage

Поиск
Список
Период
Сортировка
От Christian Kratzer
Тема Re: OID Usage
Дата
Msg-id 20050114102431.W6920@vesihiisi.cksoft.de
обсуждение исходный текст
Ответ на Re: OID Usage  (Bo Lorentsen <bl@netgroup.dk>)
Ответы Re: OID Usage  (Michael Fuhr <mike@fuhr.org>)
Re: OID Usage  (Bo Lorentsen <bl@netgroup.dk>)
Список 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@cksoft.de
CK Software GmbH                        http://www.cksoft.de/
Phone: +49 7452 889 135                 Fax: +49 7452 889 136

В списке pgsql-general по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Functions that return RECORD type
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: OID Usage