示例#1
0
        public void Init()
        {
            var engine = new SqlCeEngine(_connstr);
            if (System.IO.File.Exists(_dbFilename)) {
                System.IO.File.Delete(_dbFilename);
            }
            engine.CreateDatabase();

            _conn = new SqlCeConnection(_connstr);
            _conn.Open();

            var cmd = new SqlCeCommand("create table test_table (id int identity primary key, str nvarchar(100));", _conn);
            cmd.ExecuteNonQuery();
            cmd.Dispose();

            if (_conn != null) {
                _conn.Close();
                _conn.Dispose();
            }

            _indepDalc = new SqlCeDalc(_connstr);
        }
示例#2
0
        public void InsertViaTransactionCommit()
        {
            int rowCount = _indepDalc.GetRowCount();

            using (var dalc = new SqlCeDalc(_connstr)) {
                using (var trans = dalc.BeginTransaction()) {
                    dalc.InsertOneRow("a row");

                    int newRowCount = dalc.GetRowCount();
                    Assert.AreEqual(rowCount + 1, newRowCount);
                    trans.Commit();
                }
            }
            // Ensure row was indeed committed
            Assert.AreEqual(rowCount + 1, _indepDalc.GetRowCount());
        }
示例#3
0
        /// <summary>
        /// Inserts two rows into test_table. 
        /// 
        /// If commit, then commits transaction (expected rowcount == rowcount +2),
        /// else rolls back (expected rowcount == rowcount)
        /// </summary>
        /// <param name="commit"></param>
        private void DoSharedTransactionWork(bool commit)
        {
            using (var dalc = new SqlCeDalc(_connstr)) {
                using (var trans = dalc.BeginTransaction()) {
                    // Do some work in the outer dalc
                    dalc.InsertOneRow("outer");

                    using (var innerDalc = new SqlCeDalc(trans)) {
                        innerDalc.InsertOneRow("inner");
                    }

                    if (commit) {
                        trans.Commit();
                    } else {
                        trans.Rollback();
                    }
                }
            }
        }