public void BackupDatabase_into_existing() { using (var ds = new SQLiteDatastore()) { var dbbuilder = new TestDBBuilder(); ds.CreateDatastore(dbbuilder); var orgTableInfo = ds.QueryGeneric("SELECT * FROM Sqlite_Master;").ToArray(); orgTableInfo.Should().NotBeEmpty(); var backupTarget = base.GetTempFilePath(".db"); RegesterFileForCleanUp(backupTarget); // create database file using (var targetds = new SQLiteDatastore(backupTarget)) { targetds.CreateDatastore(dbbuilder); targetds.Execute("CREATE TABLE Something (" + "col1 text" + ");"); targetds.CheckTableExists("Something").Should().BeTrue(); targetds.Execute("ALTER Table MultiPropTable ADD COLUMN justanothercolumn text;"); targetds.CheckFieldExists("MultiPropTable", "justanothercolumn").Should().BeTrue(); ds.BackupDatabase(targetds); targetds.CheckTableExists("something").Should().BeFalse(); targetds.CheckFieldExists("MultiPropTable", "justanothercolumn").Should().BeFalse(); } } }
public void CheckFieldExistsTest() { using (var ds = new SQLiteDatastore()) { ds.Execute("CREATE TABLE TableA (ID INTEGER PRIMARY KEY);"); Assert.True(ds.CheckFieldExists("TableA", "id")); //test ignores case Assert.True(ds.CheckFieldExists("TableA", "ID")); //test ignores white space Assert.True(ds.CheckFieldExists("TableA", " ID")); Assert.False(ds.CheckFieldExists("TABLEA", "data")); } }
public void AddFieldTest() { using (var ds = new SQLiteDatastore()) { ds.Execute("CREATE TABLE TableA (ID INTEGER PRIMARY KEY);"); Assert.True(ds.CheckFieldExists("TableA", "ID")); Assert.False(ds.CheckFieldExists("TABLEA", "Data")); ds.AddField("TableA", new ColumnInfo() { Name = "Data", DBType = System.Data.DbType.AnsiString }); Assert.True(ds.CheckFieldExists("TABLEA", "Data")); Assert.Throws <SQLException>(() => ds.AddField("TableA", new ColumnInfo() { Name = "Data", DBType = System.Data.DbType.AnsiString })); } }