getting the key of an inserted record

Hi,

I want to use a table with an auto-incremented key and some non-unique
field (date ...)

I want to insert a record and get its key value right away - I am in a
multi-threaded environment, so after my commit, someone else might
insert a record ... before I can fetch my key value.

Is there a way ?

BTW: I'm doing this from Python.

Thanks.

hg
HG [ Fr, 15 September 2006 11:06 ] [ ID #1467397 ]

Re: getting the key of an inserted record

hg wrote:

> I want to use a table with an auto-incremented key and some non-unique
> field (date ...)
>
> I want to insert a record and get its key value right away - I am in a
> multi-threaded environment, so after my commit, someone else might
> insert a record ... before I can fetch my key value.
>
> Is there a way ?
>
> BTW: I'm doing this from Python.

Use LAST_INSERT_ID() SQL function or the mysql_insert_id() C API
function. At least php has similar function so I assume Python has one
too, but I don't know what name or how to use it. But at least the SQL
function can be used with any language.
Aggro [ Fr, 15 September 2006 15:16 ] [ ID #1467399 ]

Re: getting the key of an inserted record

Aggro wrote:
> hg wrote:
>
>> I want to use a table with an auto-incremented key and some non-unique
>> field (date ...)
>>
>> I want to insert a record and get its key value right away - I am in a
>> multi-threaded environment, so after my commit, someone else might
>> insert a record ... before I can fetch my key value.
>>
>> Is there a way ?
>>
>> BTW: I'm doing this from Python.
>
> Use LAST_INSERT_ID() SQL function or the mysql_insert_id() C API
> function. At least php has similar function so I assume Python has one
> too, but I don't know what name or how to use it. But at least the SQL
> function can be used with any language.

Thanks,

will that work before the commit ?

hg
HG [ Fr, 15 September 2006 18:37 ] [ ID #1467403 ]
Datenbanken » mailing.database.mysql » getting the key of an inserted record

Vorheriges Thema: New and need some help, please - mysql
Nächstes Thema: with rollup