//插入数据 public void Insert(LogEntity log) { SQLiteCommand cmd = new SQLiteCommand(conn); cmd.CommandText = "insert into '" + user + "_Log' values(@state,@context)"; cmd.Parameters.Add(new SQLiteParameter("state", log.state)); cmd.Parameters.Add(new SQLiteParameter("context", log.context)); cmd.ExecuteNonQuery(); }
//读取全部数据 public void Select(out List<LogEntity> LEL) { SQLiteCommand cmd = new SQLiteCommand(conn); cmd.CommandText = "select * from '" + user + "_Log'"; SQLiteDataReader reader = cmd.ExecuteReader(); LogEntity LE = new LogEntity(); LEL = new List<LogEntity>(); if (reader.HasRows) { while (reader.Read()) { LE.state = reader.GetValue(0).ToString(); LE.context = reader.GetValue(1).ToString(); LEL.Add(LE); } } }
//读取全部数据 public void Select(out List <LogEntity> LEL) { SQLiteCommand cmd = new SQLiteCommand(conn); cmd.CommandText = "select * from '" + user + "_Log'"; SQLiteDataReader reader = cmd.ExecuteReader(); LogEntity LE = new LogEntity(); LEL = new List <LogEntity>(); if (reader.HasRows) { while (reader.Read()) { LE.state = reader.GetValue(0).ToString(); LE.context = reader.GetValue(1).ToString(); LEL.Add(LE); } } }
//保存日志 public void LogSave(LogEntity LE) { log.Insert(LE); }
//数据库Log读写测试 public void DBDataControllerLogTest() { File.Delete(Environment.CurrentDirectory + "\\Stock3.db"); DBDataController DBC = new DBDataController("user8", Environment.CurrentDirectory + "\\Stock3.db"); DB_ERROR DBE = DBC.GetLastError(); LogEntity LE = new LogEntity(); LE.state = "状态"; LE.context = "错误内容"; DBC.LogSave(LE);//存入一条数据 List<LogEntity> LEL; DBC.LogRead(out LEL);//读取 Assert.AreEqual(1, LEL.Count); Assert.AreEqual(LE.state, LEL[0].state);//判断读取与存入的数据是否一致 Assert.AreEqual(LE.context, LEL[0].context); }