I was trying to get the id of an inserted object without executing a new query.
In the code I found a function SQLite3.LastInsertRowid(Sqlite3DatabaseHandle db) that is called inside the SQLiteConnection.Insert() function.
The Insert function code is
var insertCmd = map.GetInsertCommand (this, extra);
var count = insertCmd.ExecuteNonQuery (vals);
if (map.HasAutoIncPK)
{
var id = SQLite3.LastInsertRowid (Handle);
map.SetAutoIncPK (obj, id);
}
return count;
I can get the "map" by using conn.GetMapping(Type)
The map.SetAutoIncPK sets the the LastInsertRowid to a private property _autoPk
However, there's no way to read that! nothing like map.GetAutoIncPK
I think being able to get the LastInsertRowid directly is better in performance than executing a new query to get it.
If there's something that i'm not aware of please tell me. I've just started using sqlite-net.
The only issue with implementing map.GetAutoIncPK is that you still can't get ids for multiple inserts. but at least it solves most of the problem and multiple inserts have a workaround.
I can submit map.GetAutoIncPK but do you think it's a good idea?
I've solved this by creating a new property SQLiteConnection.LastInsertRowid and assigning a value to it in SQLiteConnection.Insert(). Is this the best solution? And should i submit it?
You still can retrieve the LastInsertRowId from your code without touching the library with
SQLite3.LastInsertRowid (db.Handle); (db being your SQLiteConnection object)
Hello,
I was trying to get the id of an inserted object without executing a new query.
In the code I found a function
SQLite3.LastInsertRowid(Sqlite3DatabaseHandle db)
that is called inside theSQLiteConnection.Insert()
function.The Insert function code is
I can get the "map" by using
conn.GetMapping(Type)
The
map.SetAutoIncPK
sets the theLastInsertRowid
to a private property_autoPk
However, there's no way to read that! nothing like
map.GetAutoIncPK
I think being able to get theLastInsertRowid
directly is better in performance than executing a new query to get it.If there's something that i'm not aware of please tell me. I've just started using sqlite-net.
The only issue with implementingmap.GetAutoIncPK
is that you still can't get ids for multiple inserts. but at least it solves most of the problem and multiple inserts have a workaround.I can submitmap.GetAutoIncPK
but do you think it's a good idea?I've solved this by creating a new property
SQLiteConnection.LastInsertRowid
and assigning a value to it inSQLiteConnection.Insert()
. Is this the best solution? And should i submit it?