[Gambas-user] gb.db autoincrement ?

admin at ...1080... admin at ...1080...
Wed Oct 22 21:16:15 CEST 2008


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)



gambas-user-request at lists.sourceforge.net schrieb:

Message: 4
Date: Mon, 20 Oct 2008 09:54:18 +0200
From: Doriano Blengino <doriano.blengino at ...1909...>
Subject: Re: [Gambas-user] gb.db autoincrement ?
To: mailing list for gambas users <gambas-user at lists.sourceforge.net>
Message-ID: <48FC392A.7020400 at ...1909...>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Doriano Blengino ha scritto:

> > 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.
>> >>
>> >>     
>>     
> > About the Last_insert_ID(), I read about this function, but it seems it 
> > is not implemented in gambas.
> > May be I can import it using "EXTERNAL sub (...) ..."; or perhaps is 
> > more simple to do a query, once a lock is in place.
> >   
>   
I correct myself - probably I doesn't need to be implemented in gambas, 
because one can use it in a simple sql request. I will try it:

    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...)

Thanks for your information, and cheers,
Doriano








More information about the User mailing list