I am using mysql/ado.net/C# heres my problem
I know mysql is concurrent, however i have file data (the thumbname name) and db data (the row) to be in sync.
If i start a transaction and it fails for any reason will this be a problem? If i have this code ran at the same time on two cores will they clobber eachother? I essentially need to know if 1) the last_insert_id is dependable on not changing. 2) if one transaction uses said rowid that another transaction wont use it.
start transaction
insert statement, however i dont want it to be active yet;
select LAST_INSERT_ID()
File.Delete(lastid)//may exist from a transaction that failed
File.Move(thumbImage, lastid)
transaction.commit()//ok done
Is this safe? Why or why not?
解决方案
MySQL's last_insert_id() is dependable in that it's always the LAST insert performed by THAT PARTICULAR connection. It won't report an insert id created by some other connection, it won't report an insert that you did two connections ago. It won't matter which cpu core the actual insert occured on, and which core the last_insert_id() call is processed on. It will always be the right ID number for that connection.
If you roll back a transaction that did an insert, last_insert_id() will STILL report that new id, even though it no longer exists. The id will not be reused, however, in a subsequent insert