Exemple #1
0
        public void Issue604_RecoversFromFailedRelease()
        {
            db.Trace = true;
            var initialCount = db.Table <TestObj> ().Count();

            var rollbacks = 0;

            db.Tracer = m => {
                //Console.WriteLine (m);
                if (m.StartsWith("Executing: release"))
                {
                    throw SQLiteException.New(SQLite3.Result.Busy, "Make release fail");
                }
                if (m == "Executing: rollback")
                {
                    rollbacks++;
                }
            };
            var sp0 = db.SaveTransactionPoint();

            db.Insert(new TestObj());
            try {
                db.Release(sp0);
                Assert.Fail("Should have thrown");
            }
            catch (SQLiteException ex) when(ex.Result == SQLite3.Result.Busy)
            {
                db.Tracer = null;
            }
            Assert.False(db.IsInTransaction);
            Assert.AreEqual(1, rollbacks);

            db.BeginTransaction();
            db.Insert(new TestObj());
            db.Commit();
            Assert.AreEqual(initialCount + 1, db.Table <TestObj> ().Count());
        }