getting the key of an inserted record
am 15.09.2006 11:06:00 von HG
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
Re: getting the key of an inserted record
am 15.09.2006 15:16:38 von Aggro
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.
Re: getting the key of an inserted record
am 15.09.2006 18:37:50 von HG
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