[Gambas-user] MySQL last_insert_id value

tobias tobiasboe1 at ...20...
Sat Jan 21 00:04:26 CET 2012


On 20.01.2012 23:46, Keith Clark wrote:
> 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
>
>
> ------------------------------------------------------------------------------
> Try before you buy = See our experts in action!
> 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-dev2
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user

i wrote a paper for school about this topic last year and had most of my 
information from the mailing list (see archive), the doc (everything 
below gambasdoc.org/help/comp/gb.db) and the picture database example 
which may be a good point to start.
i could send you the paper but it's german...




More information about the User mailing list