【发布时间】:2011-08-26 08:07:15
【问题描述】:
我目前正在使用下面的方法来获取最后插入的行的ID。
Database.ExecuteNonQuery(query, parameters);
//if another client/connection inserts a record at this time,
//could the line below return the incorrect row ID?
int fileid = Convert.ToInt32(Database.Scalar("SELECT last_insert_rowid()"));
return fileid;
到目前为止,这种方法运行良好,但我不确定它是否完全可靠。
假设有两个客户端应用程序,每个都有自己独立的数据库连接,它们同时调用上面的服务器端方法。请记住,客户端线程并行运行并且 SQLite 一次只能运行一个操作(或者我听说过),一个客户端实例是否有可能返回由插入的记录的行 ID另一个实例?
最后,有没有更好的方法来获取最后插入的行 ID?
【问题讨论】:
标签: c# sqlite system.data.sqlite