コード例 #1
0
        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();
                }
            }
        }
コード例 #2
0
        public void CheckTableExistsTest()
        {
            using (var ds = new SQLiteDatastore())
            {
                ds.Execute("CREATE TABLE tbl (col1 TEXT);");

                ds.CheckTableExists("tbl");
                ds.CheckTableExists("notATable").Should().BeFalse();
            }
        }
コード例 #3
0
        public void Read_Empty_Table()
        {
            using (var ds = new SQLiteDatastore())
            {
                ds.Execute(TestDBBuilder.CREATE_MULTIPROPTABLE);

                ds.CheckTableExists("MultiPropTable").Should().BeTrue();

                ds.From <POCOMultiTypeObject>().Invoking(x => x.Query()).Should().NotThrow();
            }
        }
コード例 #4
0
        public void CommitTransaction_WtihNoTransaction()
        {
            using (var ds = new SQLiteDatastore())
            {
                ds.Execute("CREATE TABLE TableA (Data TEXT);");

                ds.CurrentTransaction.Should().BeNull();
                ds.CommitTransaction();//extra commit should not throw exception, but will fail Debug.Assert

                ds.CheckTableExists("TableA").Should().BeTrue();
            }
        }
コード例 #5
0
        public void RollBackTransaction_WtihTransaction()
        {
            using (var ds = new SQLiteDatastore())
            {
                ds.BeginTransaction();

                ds.Execute("CREATE TABLE TableA (Data TEXT);");

                ds.RollbackTransaction();

                ds.CheckTableExists("TableA").Should().BeFalse();
            }
        }
コード例 #6
0
        public void CommitTransaction_WtihTransaction()
        {
            using (var ds = new SQLiteDatastore())
            {
                ds.CurrentTransaction.Should().BeNull();

                ds.BeginTransaction();

                ds.CurrentTransaction.Should().NotBeNull();

                ds.Execute("CREATE TABLE TableA (Data TEXT);");

                ds.CommitTransaction();

                ds.CurrentTransaction.Should().BeNull();
                ds.TransactionDepth.Should().Be(0);

                ds.CheckTableExists("TableA").Should().BeTrue();
            }
        }
コード例 #7
0
        public void CreateTableTest()
        {
            using (var ds = new SQLiteDatastore())
            {
                var cols = new ColumnInfo[]
                {
                    new ColumnInfo("ID", System.Data.DbType.Int64)
                    {
                        AutoIncrement = true
                    },
                    new ColumnInfo("Field1", System.Data.DbType.AnsiString)
                };

                ds.CreateTable("TableA", cols, false);

                ds.Invoking(x => x.Execute("EXPLAIN SELECT * FROM TableA;")).Should().NotThrow();

                ds.CheckTableExists("TableA").Should().BeTrue();
            }
        }