private void TestTransactions(DBRunner runner, ISQLExecuter executer, DBDatabase db, DBTable table, IConnectionInfo connInfo) { Output("TestTransactions:"); Output(""); try { DBConnection conn = runner.OpenConnection(executer, db, connInfo); try { Stmt_Insert stmtInsert; Stmt_Select stmtSelect; long result; Output("Begin transaction"); DBTransaction trans = runner.CreateTransaction(executer); trans.Begin(conn); try { Output("Insert row"); stmtInsert = new Stmt_Insert(table); stmtInsert.AddColumns("uiNoegle", "iTal", "lStortTal", "dtDato", "bValg"); stmtInsert.AddValues(Guid.NewGuid(), 87, (long)2394287487, DateTime.Now, false); runner.Insert(executer, conn, stmtInsert); stmtSelect = new Stmt_Select(); stmtSelect.AddTable(table); stmtSelect.AddAggregate(new Aggre_Count()); result = runner.SelectWithSingleAggregate(executer, conn, stmtSelect); Output("Count: " + result + " / 1"); Output("Rollback"); trans.RollbackAll(); } catch (Exception) { trans.RollbackAll(); throw; } stmtSelect = new Stmt_Select(); stmtSelect.AddTable(table); stmtSelect.AddAggregate(new Aggre_Count()); result = runner.SelectWithSingleAggregate(executer, conn, stmtSelect); Output("Count: " + result + " / 0"); Output(""); Output("Begin new transaction"); trans = runner.CreateTransaction(executer); trans.Begin(conn); try { Output("Insert row"); stmtInsert = new Stmt_Insert(table); stmtInsert.AddColumns("uiNoegle", "iTal", "lStortTal", "dtDato", "bValg"); stmtInsert.AddValues(Guid.NewGuid(), 87, (long)2394287487, DateTime.Now, false); runner.Insert(executer, conn, stmtInsert); stmtSelect = new Stmt_Select(); stmtSelect.AddTable(table); stmtSelect.AddAggregate(new Aggre_Count()); result = runner.SelectWithSingleAggregate(executer, conn, stmtSelect); Output("Count: " + result + " / 1"); Output("Commit"); trans.CommitAll(); } catch (Exception) { trans.RollbackAll(); throw; } stmtSelect = new Stmt_Select(); stmtSelect.AddTable(table); stmtSelect.AddAggregate(new Aggre_Count()); result = runner.SelectWithSingleAggregate(executer, conn, stmtSelect); Output("Count: " + result + " / 1"); } finally { conn.Close(); } } catch (Exception ex) { Output("TestTransactions failed with an exception:"); Output(ex); } finally { Output(""); Output(""); } }