[Gambas-user] MySQL last_insert_id value

tobias tobiasboe1 at ...20...
Fri Jan 20 23:14:32 CET 2012


hi,

> How would I get the MySQL last_insert_id() value into an integer
> variable inside gambas?
>
> I tried with
>
> CurrentID=db.exec("select last_insert_id() as last")
>
> but I get a type mismatch error.  Expecting integer, got result.
>
> Thanks,
>
> Keith
>

i suppose CurrentID is an integer?
you get that error because you actually want to stuff a Result object 
(the return value of DB.Exec()) into an integer (CurrentID as i 
guessed). to get the desired value you should use the returned Result 
object like this:

CurrentID = DB.Exec("select last_insert_id() as last")["last"]

which will get you the value of field "last" in the Result.
see the doc for details.

regards,
tobi




More information about the User mailing list