[Gambas-user] MySQL last_insert_id value

Keith Clark keithclark at ...2185...
Fri Jan 20 23:46:58 CET 2012


On 12-01-20 05:14 PM, tobias wrote:
> 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
>
> ------------------------------------------------------------------------------
> Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
Thanks Tobi....I'm still having some trouble understanding and 
implementing this db.exec function.  Could you point me to the 
documentation that shows some examples?  I don't seem to find many via 
Google.

Keith





More information about the User mailing list