i have 2 tables
"CREATE TABLE if not exists tag_name( " +
"tagid INTEGER PRIMARY KEY, " +
"title TEXT UNIQUE);";
"CREATE TABLE if not exists media_tags( " +
"media_id INTEGER, " +
"tagid INTEGER);";
Then i insert them with this code. The problem is, last_insert_rowid is not what i expect. I expect when INSERT is ignored it will return the rowid that cause the insert to fail. Example if i insert "tag1", "tag2", "tag3". then insert "tag2" i expect 2 to be returned instead of the last inserted row that was a success. How do i solve this?
void insertMediaTags(List<string> tags, long mediaId)
{
foreach(string tag in tags)
{
command.CommandText =
"INSERT OR IGNORE INTO tag_name(title) VALUES(@title); " +
"SELECT last_insert_rowid() AS RecordID;";
command.Parameters.Add("@title", DbType.String).Value = tag;
long tagid = (long)command.ExecuteScalar();
command.CommandText =
"INSERT INTO media_tags(media_id, tagid) " +
"VALUES(@media_id, @tagid);";
command.Parameters.Add("@media_id", DbType.Int32).Value = mediaId;
command.Parameters.Add("@tagid", DbType.Int64).Value = tagid;
command.ExecuteNonQuery();
}
}