private void TestSmallInsert(DBRunner runner, ISQLExecuter executer, ISQL builder, DBDatabase db, DBTable table, IConnectionInfo connInfo) { Output("TestSmallInsert:"); Output(""); try { DBConnection conn = runner.OpenConnection(executer, db, connInfo); try { Output("Insert single row"); Stmt_Insert stmtInsert = new Stmt_Insert(table); stmtInsert.AddColumns("uiNoegle", "iTal", "lStortTal", "dtDato", "bValg"); stmtInsert.AddValues(Guid.NewGuid(), 87, (long)2394287487, DateTime.Now, false); Output(builder.ToSQL(stmtInsert)); runner.Insert(executer, conn, stmtInsert); Output("Row inserted"); } finally { conn.Close(); } } catch (Exception ex) { Output("TestSmallInsert failed with an exception:"); Output(ex); } finally { Output(""); Output(""); } }
private void TestUnion(DBRunner runner, ISQLExecuter executer, ISQL builder, DBDatabase db, DBTable table1, DBTable table2, IConnectionInfo connInfo) { Output("TestUnion:"); Output(""); try { DBConnection conn = runner.OpenConnection(executer, db, connInfo); try { Output("Insert more test rows"); Stmt_Insert stmtInsert = new Stmt_Insert(table1); stmtInsert.AddColumns("uiNoegle", "txTekst", "iTal", "lStortTal", "dtDato", "bValg"); stmtInsert.AddValues(Guid.NewGuid(), "Giv mig en bog!", 123, (long)213142566, DateTime.Now, true); Output(builder.ToSQL(stmtInsert)); runner.Insert(executer, conn, stmtInsert); Output("Rows inserted"); Output(""); ShowContents(runner, executer, conn, table1); Output(""); ShowContents(runner, executer, conn, table2); Output(""); Stmt_Select stmtSelect1 = new Stmt_Select(); stmtSelect1.AddColumns(table1, "uiNoegle", "txTekst", "iTal", "lStortTal"); Stmt_Select stmtSelect2 = new Stmt_Select(); stmtSelect2.AddColumns(table2, "uiNoegle", "txTekst", "iTal", "lStortTal"); Stmt_Select stmtUnion = new Stmt_Select(); stmtUnion.AddColumns(table1, "uiNoegle", "txTekst", "iTal", "lStortTal"); stmtUnion.AddUnion(stmtSelect1); stmtUnion.AddUnion(stmtSelect2); stmtUnion.AddSort(table1, "iTal", Order.Ascending); Output(builder.ToSQL(stmtUnion)); ShowContents(stmtUnion, runner, executer, conn); } finally { conn.Close(); } } catch (Exception ex) { Output("TestUpdate failed with an exception:"); Output(ex); } finally { Output(""); Output(""); } }
private void TestFunctions(DBRunner runner, ISQLExecuter executer, ISQL builder, DBDatabase db, DBTable table, IConnectionInfo connInfo) { Output("TestFunctions:"); Output(""); try { DBConnection conn = runner.OpenConnection(executer, db, connInfo); try { Output("Insert single row"); Stmt_Insert stmtInsert = new Stmt_Insert(table); stmtInsert.AddColumns("uiNoegle", "iTal", "lStortTal", "dtDato", "bValg"); stmtInsert.AddValues(Guid.NewGuid(), 87, (long)2394287487, DateTime.Now, false); Output(builder.ToSQL(stmtInsert)); runner.Insert(executer, conn, stmtInsert); stmtInsert = new Stmt_Insert(table); stmtInsert.AddColumns("uiNoegle", "txTekst", "iTal", "lStortTal", "dtDato", "bValg"); stmtInsert.AddValues(Guid.NewGuid(), "Blåbærgrød", 87, (long)2394287487, DateTime.Now, false); Output(builder.ToSQL(stmtInsert)); runner.Insert(executer, conn, stmtInsert); Output("Rows inserted"); Output(""); ShowContents(runner, executer, conn, table); Output(""); Stmt_Select stmtSelect = new Stmt_Select(); stmtSelect.AddTable(table); IFunction func = new Func_SubString(table, "txTekst", 3, 8); stmtSelect.AddFunction(new Func_SubString(func, 0, 2)); Output(builder.ToSQL(stmtSelect)); ShowContents(stmtSelect, runner, executer, conn); Output(""); stmtSelect = new Stmt_Select(); stmtSelect.AddTable(table); stmtSelect.AddFunction(new Func_ToLower(table, "txTekst")); Output(builder.ToSQL(stmtSelect)); ShowContents(stmtSelect, runner, executer, conn); Output(""); stmtSelect = new Stmt_Select(); stmtSelect.AddTable(table); stmtSelect.AddFunction(new Func_ToUpper(table, "txTekst")); Output(builder.ToSQL(stmtSelect)); ShowContents(stmtSelect, runner, executer, conn); } finally { conn.Close(); } } catch (Exception ex) { Output("TestUpdate failed with an exception:"); Output(ex); } finally { Output(""); Output(""); } }
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(""); } }