public bool InsertHistory(string sql, eSQLHistoryType historyType) { // Open database (or create if not exits) if (FindCountHistoryEntry(sql, historyType) <= 0) { using (var db = new LiteDatabase(DatabaseLocation)) { // Get customer collection var historys = db.GetCollection <History>(schemaName); // Create your new customer instance var history = new History { DBName = DatabaseName, Stamp = DateTime.Now, SQL = sql, SuccessType = historyType, IsActive = true }; historys.EnsureIndex(x => x.DBName); historys.EnsureIndex(x => x.Stamp); historys.EnsureIndex(x => x.SuccessType); // Insert (Id will be auto-incremented) historys.Insert(history); return(true); } } return(false); }
public int FindCountHistoryEntry(string sql, eSQLHistoryType historyType) { int count = 0; using (var db = new LiteDatabase(DatabaseLocation)) { // Get customer collection var historys = db.GetCollection <History>(schemaName); historys.EnsureIndex(x => x.DBName); historys.EnsureIndex(x => x.Stamp); historys.EnsureIndex(x => x.SuccessType); var r = historys.Find(x => x.DBName == DatabaseName && x.SQL == sql && x.SuccessType == historyType); count = r.Count(); } return(count); }