public T ReadByKey <T>(object key) where T : class { var desc = Registory.GetClassDesc <T>(); var result = database.ExecuteQuery( SQLMaker.GenerateSelectSQL <T>(desc, key)); T[] r = ResultReader.Get <T>(result, desc); if (r.Length > 0) { return(r[0]); } else { return(null); } }
public void UpdateOrInsert <T>(T obj) { var desc = Registory.GetClassDesc <T>(); string queryData = SQLMaker.GenerateSelectSQL <T> (desc, obj); try{ DataTable queryResult = database.ExecuteQuery(queryData); if (queryResult.Rows.Count > 0) { // Debug.Log(":: Update Data"); string update = SQLMaker.GenerateUpdateSQL(desc, obj); database.ExecuteNonQuery(update); } else { // Debug.Log(":: Insert Data"); string insert = SQLMaker.GenerateInsertSQL(desc, obj); database.ExecuteNonQuery(insert); } }catch (SqliteException e) { Debug.Log("Fail! err: " + e.ErrorCode + " - " + e.Message); } }