Return Last Insert ID from MySQL

Hi all,

I have created a method for database INSERT to return the ID (while self is a MySQL Instance):

myInsertRecord(TableName as String, rec as DatabaseRecord) as Integer

TableName = uppercase(TableName)

Dim Loc_Sql as String

self.InsertRecord(TableName, rec)
If self.Error Then
  Return(-1)
else
  Dim rs as RecordSet
  Loc_Sql = "SELECT LAST_INSERT_ID() Last_GUID"
  rs = self.SQLSelect(Loc_Sql)
  if rs <> nil then
    Return(rs.Field("Last_GUID").IntegerValue)
  else
    Return(-2)
  end if
end if

Is this safe enough to ensure the ID returned is the one that I insert in a multi-user environment?

Xojo’s db class has GetInsertID that returns the last inserted Autoincremented id. But under the hood I think it also uses ‘SELECT LAST_INSERT_ID()’.

This makes me like PostgreSQL even more. It’s as simple as ‘INSERT INTO tbl(col1, col2) VALUES($1, $2) RETURNING id’.