Get last inserted ID

I am currently using the method below to get the id of the last row inserted.

    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;

This method still works, but I'm not sure if it is completely reliable.

Suppose there are two client applications, each with its own separate database connections, that call the server-side method above at the same time. Bearing in mind that client threads run in parallel and that SQLite can only perform one operation at a time (or, as I have already heard), is it possible for one client instance to return the identifier of the row of the record that was inserted by another instance?

Finally, is there a better way to get the last inserted row id?

+3
source share
2

/ , ?

, , , .

, SQLite , , ?

, .

, . , , .

, SQLite.

+6

, id , , , .

, , . , , . , , , .

+2

All Articles