DicomWebStorge/Orthanc-1.7.4/OrthancFramework/UnitTestsSources/SQLiteChromiumTests.cpp
// Rolling back any part of a transaction should roll back all of them.
Rolling back any part of a transaction should roll back all of them.
Rolling back any part of a transaction should roll back all of them .
TEST_F(SQLTransactionTest, NestedRollback) {
  EXPECT_EQ(0, db().GetTransactionNesting());
  {
    Transaction outer(db());
    outer.Begin();
    EXPECT_EQ(1, db().GetTransactionNesting());
    {
      Transaction inner1(db());
      inner1.Begin();
      EXPECT_TRUE(db().Execute("INSERT INTO foo (a, b) VALUES (1, 2)"));
      EXPECT_EQ(2, db().GetTransactionNesting());
      inner1.Commit();
      EXPECT_EQ(1, db().GetTransactionNesting());
    }
    EXPECT_EQ(1, CountFoo());
    {
      Transaction inner2(db());
      inner2.Begin();
      EXPECT_TRUE(db().Execute("INSERT INTO foo (a, b) VALUES (1, 2)"));
      EXPECT_EQ(2, db().GetTransactionNesting());
      inner2.Rollback();
      EXPECT_EQ(1, db().GetTransactionNesting());
    }
    EXPECT_EQ(1, db().GetTransactionNesting());
    {
      Transaction inner3(db());
      EXPECT_THROW(inner3.Begin(), OrthancException);
      EXPECT_EQ(1, db().GetTransactionNesting());
    }
  }
  EXPECT_EQ(0, db().GetTransactionNesting());
  EXPECT_EQ(0, CountFoo());
}
TEST_F ( SQLTransactionTest , NestedRollback ) { EXPECT_EQ ( 0 , db ( ) . GetTransactionNesting ( ) ) ; { Transaction outer ( db ( ) ) ; outer . Begin ( ) ; EXPECT_EQ ( 1 , db ( ) . GetTransactionNesting ( ) ) ; { Transaction inner1 ( db ( ) ) ; inner1 . Begin ( ) ; EXPECT_TRUE ( db ( ) . Execute ( " " ) ) ; EXPECT_EQ ( 2 , db ( ) . GetTransactionNesting ( ) ) ; inner1 . Commit ( ) ; EXPECT_EQ ( 1 , db ( ) . GetTransactionNesting ( ) ) ; } EXPECT_EQ ( 1 , CountFoo ( ) ) ; { Transaction inner2 ( db ( ) ) ; inner2 . Begin ( ) ; EXPECT_TRUE ( db ( ) . Execute ( " " ) ) ; EXPECT_EQ ( 2 , db ( ) . GetTransactionNesting ( ) ) ; inner2 . Rollback ( ) ; EXPECT_EQ ( 1 , db ( ) . GetTransactionNesting ( ) ) ; } EXPECT_EQ ( 1 , db ( ) . GetTransactionNesting ( ) ) ; { Transaction inner3 ( db ( ) ) ; EXPECT_THROW ( inner3 . Begin ( ) , OrthancException ) ; EXPECT_EQ ( 1 , db ( ) . GetTransactionNesting ( ) ) ; } } EXPECT_EQ ( 0 , db ( ) . GetTransactionNesting ( ) ) ; EXPECT_EQ ( 0 , CountFoo ( ) ) ; }
Rolling back any part of a transaction should roll back all of them.
Rolling back any part of a transaction should roll back all of them .
// Outermost transaction. // The first inner one gets committed. // One row should have gotten inserted. // The second inner one gets rolled back. // A third inner one will fail in Begin since one has already been rolled // back.