public void TestInsertCommand() { var connectionString = DbHelper.CreateStringConnectionFromPath(AssemblyDirectory + emptyDbPath); using (var sqliteDbConnector = new SqliteDbConnector(connectionString)) { var cmd = new CommandModel { Command = "NameInserted", CommandName = "CmdInserted" }; sqliteDbConnector.InsertOrUpdateCommand(cmd); var resultCmd = sqliteDbConnector.GetCommands()[0]; Assert.AreEqual(cmd.CommandName, resultCmd.CommandName); Assert.AreEqual(cmd.Command, resultCmd.Command); } }
public void TestReadCommands() { var connectionString = DbHelper.CreateStringConnectionFromPath(AssemblyDirectory + dbPath); var sqliteDbConnector = new SqliteDbConnector(connectionString); var listCommands = sqliteDbConnector.GetCommands(); int i = 1; foreach (var command in listCommands) { Assert.AreEqual(i, command.Id); Assert.AreEqual("name" + i, command.CommandName); Assert.AreEqual("cmd" + i, command.Command); i++; } }
/// <summary> /// Creates the database. /// </summary> /// <param name="mapFolder">The map folder.</param> /// <param name="dbFileName">Name of the db file.</param> public static void CreateSqliteDatabase(MapConfig config, string scriptFolder, string dbFileName) { //string autoIncrementFileName = string.Format("{0}_auto_increment.{1}.db", dbFileName, DateTime.Now.Ticks); //string guidFileName = string.Format("{0}_guid.{1}.db", dbFileName, DateTime.Now.Ticks); if (File.Exists(dbFileName)) { File.Delete(dbFileName); } IDbConnector dbConnector = new SqliteDbConnector(config.Settings.ConnectionString); IDbAccess db = new DbAccess(dbConnector); var scriptFiles = Directory.GetFiles(scriptFolder, "*.sql", SearchOption.TopDirectoryOnly); using (var conn = dbConnector.CreateNewConnection()) { conn.Open(); var transaction = new TransactionWrapper(conn.BeginTransaction()); try { foreach (var file in scriptFiles) { System.Console.WriteLine("running script {0}", file); using (FileStream fs = File.OpenRead(file)) { using (StreamReader freader = new StreamReader(fs)) { var sql = freader.ReadToEnd(); db.ExecuteNonQuery(conn, transaction, sql); } } } transaction.Commit(); } catch //(Exception ex) { transaction.Rollback(); throw; } transaction.Dispose(); } }