private int InsertRecord(string recordName) { try { _sqlite.BeginTransaction(true); //return _sqlite.Insert(new RecordSets { name = recordName }); RecordSets newRecordSets = new RecordSets { name = recordName }; int rowEffected = _sqlite.Insert(newRecordSets); if (1 != rowEffected) { throw new Exception("Insert Record Item Failed"); } return(newRecordSets.id); } catch (Exception ex) { Debug.LogErrorFormat("error:{0} cant insert", recordName); return(-1); } finally { _sqlite.Commit(); } }
/// <summary> /// 根据名字获取record在表中的ID /// </summary> /// <param name="recordName"></param> /// <returns></returns> private int?GetRecordID(string recordName) { RecordSets recordSets = _sqlite .Table <RecordSets>() .Where(rn => rn.name.Equals(recordName)) .FirstOrDefault(); return(recordSets == null ? (int?)null : recordSets.id); }
public bool RecordExistByID(string id) { RecordSets recordSets = _sqlite .Table <RecordSets>() .Where(ri => ri.id.Equals(id)) .FirstOrDefault(); return(recordSets != null); }
/// <summary> /// 根据ID从SqlLite中取数据 /// </summary> /// <param name="id"></param> /// <returns></returns> public CacheItem Get(string id) { RecordSets recordSets = null; if (!RecordExistByID(id)) { return(null); } recordSets = _sqlite .Table <RecordSets>() .Where(r => r.id.Equals(id)) .FirstOrDefault(); return(new CacheItem() { Data = recordSets.data, AddedToCacheTicksUtc = recordSets.timestamp }); }
/// <summary> /// 根据ID从SqlLite中取数据 /// </summary> /// <param name="key"></param> /// <returns></returns> public CacheItem GetItem(string key) { RecordSets recordUtil = null; try { int?recordID = GetRecordID(key); if (!recordID.HasValue) { return(null); } recordUtil = _sqlite .Table <RecordSets>() .Where(t => t.recordid == recordID.Value ) .FirstOrDefault(); DateTime?lastModified = null; if (recordUtil.lastmodified.HasValue) { lastModified = UnixTimestampUtils.From((double)recordUtil.lastmodified.Value); } return(new CacheItem() { Data = recordUtil.data, AddedToCacheTicksUtc = recordUtil.timestamp, LastModified = lastModified }); } catch (Exception ex) { Debug.Log("ex: " + ex.Message); return(null); } }