[Gambas-user] gb.db autoincrement ?
Doriano Blengino
doriano.blengino at ...1909...
Thu Oct 23 07:49:38 CEST 2008
admin at ...1080... ha scritto:
> Hi Doriano
>
> As the description says, the last_inserted_id() is during the same
> connection reserved for the client.
> I would recommend to use a stored procedure. Indeed, why not delegate
> the SQL thing to the server.
> The first time it seems to be expensive, but it is not so. I would be
> helpful if necessary.
>
> Regards, Werner(007)
>
This would be cool. I never used stored procedures, even if I read about
them.
So my problem (and other's, I suppose) is:
1: Create a master record with unique ID and several other fields in
table "invoices"
2: Obtain the inserted ID
3: Add one or more (sometimes a lot) slave records, each carrying the
obtained ID, and other fields.
I think a stored procedure wants all its parameters in a single call, or
it is not so?
If you can help, I will be happy - thanks.
Doriano.
>>> admin at ...1080... ha scritto:
>>>
>>>
>>
>>
>>>>> But in case you are using mySQL there is the function LAST_INSERT_ID (),
>>>>> see:
>>>>> http://dev.mysql.com/doc/refman/5.1/en/information-functions.html#function_last-insert-id.
>>>>>
>>>
>>>
>>>
> db.exec("insert data in master table 'invoices'")
> lastinserted=db.exec("select last_insert_id() as last")
>
> Perhaps locks are still needed (or this last_insert_id() is "cached" in
> the client library? It would be good...)
>
More information about the User
mailing list