robertohuertasm / SQLite4Unity3d

SQLite made easy for Unity3d

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Insert not returning auto increment id

rwomack opened this issue · comments

connection.Insert(record) is always returning 1 not the auto incremented id, it appears to be returning RowsAffected from ExecuteNonQuery even though map.HasAutoIncPk is true and it updates the field?

Yes, you can do a temp fix with renaming the variable long id on line 1374 to count and cast the long into the int and then make the SetAutoIncPK to use the count instead of the long id.
Just as bellow:

if (map.HasAutoIncPK)
{
// long id = SQLite3.LastInsertRowid (Handle);
   count = (int) SQLite3.LastInsertRowid (Handle);

// map.SetAutoIncPK (obj, id);
   map.SetAutoIncPK (obj, count);
}

You will then get the auto incremented id

@Aresak Why introduce messy comments?

int primaryKey = 0;
			
if (map.HasAutoIncPK)
{
    primaryKey = (int)SQLite3.LastInsertRowid (Handle);
    map.SetAutoIncPK (obj, primaryKey);
}

return primaryKey;