How to find out value of inserted AutoInc when using MySql

102 views
Skip to first unread message

bryan hunt

unread,
May 16, 2011, 10:25:32 AM5/16/11
to scalaquery
I found the previous, similarly named thread.

http://groups.google.com/group/scalaquery/browse_thread/thread/d762802aa878dcb5/099f82ec46fe22f5

In the response it refered to SimpleScalarFunction, I don't think this
class exists.

In MySql the vendor function to call is LAST_INSERT_ID() rather than the
H2 specific SCOPE_IDENTITY.

This code shows the MySql way. I'm posting it to the list for
posterity's sake.

val scopeIdentity = SimpleFunction.nullary[Long]("LAST_INSERT_ID")

val inserted = Actions.insert(
"cat", "eats", "dog)

//Print out the count of inserted records.
println(inserted )

//Print out the primary key for the last inserted record.
println(Query(scopeIdentity).first)

//Regards
//Bryan


Toby Thain

unread,
Mar 18, 2012, 2:04:29 AM3/18/12
to scala...@googlegroups.com


On Monday, 16 May 2011 10:25:32 UTC-4, bryan hunt wrote:

posterity's sake.

This code shows the MySql way. I'm posting it to the list for

val scopeIdentity = SimpleFunction.nullary[Long]("LAST_INSERT_ID")
     


Thankyou, this was exactly what I needed just now.

--Toby
 
Reply all
Reply to author
Forward
0 new messages