Ejemplo n.º 1
0
        private void TestSmallDelete(DBRunner runner, ISQLExecuter executer, ISQL builder, DBDatabase db, DBTable table, IConnectionInfo connInfo)
        {
            Output("TestSmallDelete:");
            Output("");

            try
            {
                DBConnection conn = runner.OpenConnection(executer, db, connInfo);

                try
                {
                    Output("Delete all rows");
                    Stmt_Delete stmtDelete = new Stmt_Delete(table);
                    Output(builder.ToSQL(stmtDelete));
                    runner.Delete(executer, conn, stmtDelete);
                    Output("Rows deleted");

                    Stmt_Select stmtSelect = new Stmt_Select();
                    stmtSelect.AddTable(table);
                    stmtSelect.AddAggregate(new Aggre_Count());
                    long result = runner.SelectWithSingleAggregate(executer, conn, stmtSelect);
                    Output("Count: " + result + " / 0");
                }
                finally
                {
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                Output("TestSmallDelete failed with an exception:");
                Output(ex);
            }
            finally
            {
                Output("");
                Output("");
            }
        }
Ejemplo n.º 2
0
        private void TestUpdate(DBRunner runner, ISQLExecuter executer, ISQL builder, DBDatabase db, DBTable table, IConnectionInfo connInfo)
        {
            Output("TestUpdate:");
            Output("");

            try
            {
                DBConnection conn = runner.OpenConnection(executer, db, connInfo);

                try
                {
                    Output("Insert more rows");
                    Stmt_Insert stmtInsert = new Stmt_Insert(table);
                    stmtInsert.AddAllColumns();
                    stmtInsert.AddValues(Guid.NewGuid(), "Dette er en tekst", 42, DateTime.Now, null, 6576547634);
                    stmtInsert.AddParameter("MEGET STOR TEKST");
                    stmtInsert.AddValue(true);
                    stmtInsert.AddParameter(new byte[432]);
                    Output(builder.ToSQL(stmtInsert));
                    runner.Insert(executer, conn, stmtInsert);
                    Output("Rows inserted");
                    Output("");

                    ShowContents(runner, executer, conn, table);
                    Output("");

                    Output("Update 1");
                    Stmt_Update stmtUpdate = new Stmt_Update(table);
                    stmtUpdate.AddColumns("txTekst", "iTal");
                    stmtUpdate.AddValues("En ny tekst", 534);
                    stmtUpdate.AddCriteria(new Crit_Match(table, "iTal", MatchType.Equal, 42));
                    Output(builder.ToSQL(stmtUpdate));
                    runner.Update(executer, conn, stmtUpdate);
                    Output("");

                    ShowContents(runner, executer, conn, table);
                    Output("");

                    Output("Update 2");
                    stmtUpdate = new Stmt_Update(table);
                    stmtUpdate.AddColumn("txStorTekst");
                    stmtUpdate.AddParameter("DETTE STÅR MED STORT!");
                    stmtUpdate.AddCriteria(new Crit_Match(table, "txStorTekst", MatchType.IsNull));
                    Output(builder.ToSQL(stmtUpdate));
                    runner.Update(executer, conn, stmtUpdate);
                    Output("");

                    ShowContents(runner, executer, conn, table);
                    Output("");

                    Stmt_Select stmtSelect = new Stmt_Select();
                    stmtSelect.AddTable(table);
                    stmtSelect.AddFunction(new Func_SubString(table, "txTekst", 3, 8));
                    Output(builder.ToSQL(stmtSelect));
                    ShowContents(stmtSelect, runner, executer, conn);
                    Output("");

                    Output("Delete");
                    Stmt_Delete stmtDelete = new Stmt_Delete(table);
                    stmtDelete.AddCriteria(new Crit_Match(table, "bValg", MatchType.Equal, false));
                    Output(builder.ToSQL(stmtDelete));
                    runner.Delete(executer, conn, stmtDelete);
                    Output("");

                    ShowContents(runner, executer, conn, table);
                }
                finally
                {
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                Output("TestUpdate failed with an exception:");
                Output(ex);
            }
            finally
            {
                Output("");
                Output("");
            }
        }