public async Task InsertAsync(BaseEntry entry) { try { await Task.Run(() => { using (var custstmt = DbConnection.Prepare(EasySql.CreateInsert(entry.GetType()))) { EasySql.FillInsert(custstmt, entry); var res = custstmt.Step(); if (res != SQLiteResult.DONE) { throw new Exception(); } } } ); } catch (Exception ex) { Debug.WriteLine(ex.Message); return; } using (var idstmt = DbConnection.Prepare("SELECT last_insert_rowid()")) { idstmt.Step(); { entry.Id = (long)idstmt[0]; } } }
public Task UpdateItemAsync(BaseEntry item) { return(Task.Run(() => { using ( var projstmt = DbConnection.Prepare(EasySql.CreateUpdate(item.GetType()))) { // Reset the prepared statement so we can reuse it. projstmt.ClearBindings(); projstmt.Reset(); EasySql.FillUpdate(projstmt, item); projstmt.Step(); } })); }
public Task DeleteItemAsync(BaseEntry item) { return(Task.Run(() => { using ( var projstmt = DbConnection.Prepare(string.Format("DELETE FROM {0} WHERE Id = ?", item.GetType().Name))) { // Reset the prepared statement so we can reuse it. projstmt.ClearBindings(); projstmt.Reset(); projstmt.Bind(1, item.Id); projstmt.Step(); } })); }