Пример #1
0
        public static void Main()
        {
            try
            {
                DBRunner     runner   = new DBRunner();
                ISQLExecuter executer = new DB2_SQLExecuter(new DB2_SQL());
                DBDatabase   database = new DBDatabase("EISST");

                // Open connection to the database
                Output("Open connection to database");

                IConnectionInfo connInfo   = new DB2_ConnectionInfo("vagn", "EISST", "EISST", "EISSTEISST");
                DBConnection    connection = runner.OpenConnection(executer, database, connInfo);

                try
                {
                    // Extract meta data for all the tables we need
                    Output("Extract table metadata");

                    DBTable pluginsTable = runner.GetTableMetaData(executer, connection, database, "EISST", "Plugins");
                    database.AddTable(pluginsTable);

                    DBTable gruppePostkasseTable = runner.GetTableMetaData(executer, connection, database, "EISST", "GruppePostkasse");
                    database.AddTable(gruppePostkasseTable);

                    DBTable revisionssporTable = runner.GetTableMetaData(executer, connection, database, "EISST", "Revisionsspor");
                    database.AddTable(revisionssporTable);

//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.abort.Plugin", "Abort_Grundoplysninger");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.bdb.Plugin", "BDB_Grundoplysninger");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.cancer.Plugin", "Cancer");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.commoncancer.Plugin", "CommonCancer");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.genoptraening.Plugin", "Genoptraening_Grundoplysninger");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.hbs.Plugin", "HBS_Grundoplysninger");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.injicerbarheroin.Plugin", "InjicerbarHeroin_Grundoplysninger");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.ivf.Plugin", "IVF_Grundoplysninger");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.minipas.Plugin", "MiniPas_Skema1_Grundoplysninger");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.nab.Plugin", "NAB_Grundoplysninger");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.mortality.Plugin", "Mortality_Side1", "Mortality_Side2");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.patologi.Plugin", "Patologi_Skema1");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.psykiatrilovensp3.Plugin", "Psykiatrilovensp3_Grundoplysninger");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.sengepladser.Plugin", "Sengepladser_Grundoplysninger");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.sib.Plugin", "SIB_Grundoplysninger");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.tvang1.Plugin", "Tvang_Skema1_Head");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.tvang2.Plugin", "Tvang_Skema2_Head");
                    FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.tvang3.Plugin", "Tvang_Skema3_Head");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.tvang4.Plugin", "Tvang_Skema4_Head");
//					FindDocuments(pluginsTable, gruppePostkasseTable, revisionssporTable, runner, executer, connection, "dk.hob.ei.tvang5.Plugin", "Tvang_Skema5_Head");
                }
                finally
                {
                    Output("Close connection");
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                Output("Exception failure: " + ex);
            }
        }
Пример #2
0
        public static void Main(String[] args)
        {
            try
            {
                DBRunner     runner   = new DBRunner();
                ISQLExecuter executer = new DB2_SQLExecuter(new DB2_SQL());
                DBDatabase   database = new DBDatabase("EISST");

                // Open connection to the database
                Output("Open connection to database");

                IConnectionInfo connInfo   = new DB2_ConnectionInfo("vagn", "EISST", "EISST", "EISSTEISST");
                DBConnection    connection = runner.OpenConnection(executer, database, connInfo);

                try
                {
                    // Extract meta data for all the tables we need
                    Output("Extract table metadata");

                    DBTable pluginsTable = runner.GetTableMetaData(executer, connection, database, "EISST", "Plugins");
                    database.AddTable(pluginsTable);

                    DBTable grupperTable = runner.GetTableMetaData(executer, connection, database, "EISST", "Grupper");
                    database.AddTable(grupperTable);

                    DBTable gruppePostkasseTable = runner.GetTableMetaData(executer, connection, database, "EISST", "GruppePostkasse");
                    database.AddTable(gruppePostkasseTable);

                    DBTable side1Table = runner.GetTableMetaData(executer, connection, database, "EISST", "Mortality_Side1");
                    database.AddTable(side1Table);

                    DBTable side2Table = runner.GetTableMetaData(executer, connection, database, "EISST", "Mortality_Side2");
                    database.AddTable(side2Table);

                    Output("Find needed ids");

                    // Find the plug-in id for mortality documents
                    Guid pluginID = FindPluginID(pluginsTable, runner, executer, connection);
                    if (pluginID.Equals(Guid.Empty))
                    {
                        Output("Couldn't find plug-in ID");
                        return;
                    }

                    Output("Plug-in ID: " + pluginID.ToString("B").ToUpper());

                    // Find the group id where the documents are stored
                    Guid groupID = FindGroupID(grupperTable, runner, executer, connection);
                    if (groupID.Equals(Guid.Empty))
                    {
                        Output("Couldn't find group ID");
                        return;
                    }

                    Output("Group ID: " + groupID.ToString("B").ToUpper());

                    Output("Delete documents that are stored in the database");
                    FixMailBox(pluginID, groupID, gruppePostkasseTable, side1Table, side2Table, runner, executer, connection);
                }
                finally
                {
                    Output("Close connection");
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                Output("Exception failure: " + ex);
            }
        }
Пример #3
0
        private void TestSQLBuild(ISQL builder, DBDatabase db, DBTable table)
        {
            Output("TestSQLBuild:");
            Output("");

            try
            {
                Output("Criterias:");
                ICriteria crit1 = new Crit_Match(table, "lStortTal", MatchType.Equal, 6576547634);
                ICriteria crit2 = new Crit_Match(table, "txTekst", MatchType.Different, "Bent");
                ICriteria crit3 = new Crit_Match(table, "sLilleTal", MatchType.IsNull);

                Stmt_Select stmtSelect = new Stmt_Select();
                stmtSelect.AddAllColumns(table);
                stmtSelect.AddCriteria(crit1);
                stmtSelect.AddCriteria(crit2);
                stmtSelect.AddCriteria(crit3);
                Output(builder.ToSQL(stmtSelect));

                stmtSelect = new Stmt_Select();
                stmtSelect.AddAllColumns(table);
                stmtSelect.AddCriteria(new Crit_Or(crit1, crit2));
                stmtSelect.AddCriteria(crit3);
                Output(builder.ToSQL(stmtSelect));

                stmtSelect = new Stmt_Select();
                stmtSelect.AddAllColumns(table);
                ICriteria tempCrit = new Crit_And(crit2, crit3);
                stmtSelect.AddCriteria(new Crit_Or(crit1, tempCrit));
                Output(builder.ToSQL(stmtSelect));

                stmtSelect = new Stmt_Select();
                stmtSelect.AddAllColumns(table);
                stmtSelect.AddCriteria(new Crit_Or(new Crit_Or(crit1, crit2), crit3));
                Output(builder.ToSQL(stmtSelect));

                stmtSelect = new Stmt_Select();
                stmtSelect.AddAllColumns(table);
                stmtSelect.AddCriteria(crit1);
                stmtSelect.AddCriteria(crit2);
                stmtSelect.AddCriteria(new Crit_In(table, "iTal", true, 3, 5, 254, 31));
                Output(builder.ToSQL(stmtSelect));

                Stmt_Select stmtSelect1 = new Stmt_Select();
                stmtSelect1.AddColumn(table, "iTal");

                stmtSelect = new Stmt_Select();
                stmtSelect.AddAllColumns(table);
                stmtSelect.AddCriteria(new Crit_SubQuery(table, "iTal", stmtSelect1));
                Output(builder.ToSQL(stmtSelect));

                stmtSelect = new Stmt_Select();
                stmtSelect.AddAllColumns(table);
                stmtSelect.AddCriteria(new Crit_SubQuery(table, "iTal", true, stmtSelect1));
                Output(builder.ToSQL(stmtSelect));
                Output("");

                Output("Aggregates:");
                stmtSelect = new Stmt_Select();
                stmtSelect.AddColumn(table, "iTal");
                stmtSelect.Distinct = true;
                Output(builder.ToSQL(stmtSelect));

                stmtSelect = new Stmt_Select();
                stmtSelect.AddTable(table);
                stmtSelect.AddAggregate(new Aggre_Count());
                Output(builder.ToSQL(stmtSelect));

                stmtSelect = new Stmt_Select();
                stmtSelect.AddTable(table);
                stmtSelect.AddAggregate(new Aggre_Count(table, "iTal"));
                Output(builder.ToSQL(stmtSelect));

                stmtSelect = new Stmt_Select();
                stmtSelect.AddTable(table);
                stmtSelect.AddAggregate(new Aggre_Max(table, "iTal"));
                Output(builder.ToSQL(stmtSelect));

                stmtSelect = new Stmt_Select();
                stmtSelect.AddTable(table);
                stmtSelect.AddAggregate(new Aggre_Min(table, "iTal"));
                Output(builder.ToSQL(stmtSelect));
                Output("");

                Output("Create tables:");
                DBTable employees = db.AddTable("Employees");
                employees.AddColumn("Employee_ID", ColumnType.String, 2, ColumnFlag.PrimaryKey | ColumnFlag.NotNull);
                employees.AddColumn("Name", ColumnType.String, 50, ColumnFlag.NotNull);

                DBTable orders = db.AddTable("Orders");
                orders.AddColumn("Prod_ID", ColumnType.Int, ColumnFlag.PrimaryKey | ColumnFlag.NotNull);
                orders.AddColumn("Product", ColumnType.String, 50, ColumnFlag.NotNull | ColumnFlag.IndexUnique);
                orders.AddColumn("Employee_ID", ColumnType.String, 2, ColumnFlag.NotNull);

                DBTable storage = db.AddTable("Storage");
                storage.AddColumn("Storage_ID", ColumnType.Int, ColumnFlag.PrimaryKey | ColumnFlag.NotNull);
                storage.AddColumn("Prod_ID", ColumnType.Int, ColumnFlag.NotNull);
                storage.AddColumn("Count", ColumnType.Int, ColumnFlag.NotNull | ColumnFlag.IndexDesc);

                Stmt_CreateTable stmtCreate = new Stmt_CreateTable(employees);
                Output(builder.ToSQL(stmtCreate));

                stmtCreate = new Stmt_CreateTable(orders);
                Output(builder.ToSQL(stmtCreate));

                stmtCreate = new Stmt_CreateTable(storage);
                Output(builder.ToSQL(stmtCreate));
                Output("");

                Output("Joins:");
                stmtSelect = new Stmt_Select();
                stmtSelect.AddColumn(employees, "Name");
                stmtSelect.AddColumn(orders, "Product");
                stmtSelect.AddJoin(new Join_Inner(employees, "Employee_ID", orders, "Employee_ID"));
                stmtSelect.AddColumn(storage, "Count");
                stmtSelect.AddJoin(new Join_Inner(orders, "Prod_ID", storage, "Prod_ID"));
                stmtSelect.AddCriteria(new Crit_Match(storage, "Count", MatchType.Bigger, 10));
                stmtSelect.AddSort(employees, "Name", Order.Ascending);
                stmtSelect.AddSort(orders, "Product", Order.Descending);
                Output(builder.ToSQL(stmtSelect));

                stmtSelect = new Stmt_Select();
                stmtSelect.AddColumn(employees, "Name");
                stmtSelect.AddColumn(orders, "Product");
                stmtSelect.AddJoin(new Join_Left(employees, "Employee_ID", orders, "Employee_ID"));
                Output(builder.ToSQL(stmtSelect));

                stmtSelect = new Stmt_Select();
                stmtSelect.AddColumn(employees, "Name");
                stmtSelect.AddColumn(orders, "Product");
                stmtSelect.AddJoin(new Join_Right(employees, "Employee_ID", orders, "Employee_ID"));
                Output(builder.ToSQL(stmtSelect));
                Output("");

                Output("Misc");
                DBTable employees1 = db.AddTable("Employees1");
                employees1.AddColumn("Employee_ID", ColumnType.String, 2, ColumnFlag.PrimaryKey | ColumnFlag.NotNull);
                employees1.AddColumn("Name", ColumnType.String, 50, ColumnFlag.NotNull);

                stmtSelect = new Stmt_Select();
                stmtSelect.AddAllColumns(employees);
                Stmt_Insert stmtInsert = new Stmt_Insert(employees1);
                stmtInsert.InsertFromSelect = stmtSelect;
                Output(builder.ToSQL(stmtInsert));
            }
            catch (Exception ex)
            {
                Output("TestSQLBuild failed with an exception:");
                Output(ex);
            }
            finally
            {
                Output("");
                Output("");
            }
        }
Пример #4
0
        private void TestThread(ManualResetEvent exitEvent, Object userData)
        {
            try
            {
                ISQL            builder;
                ISQLExecuter    executer;
                IConnectionInfo connInfo;

                switch ((int)userData)
                {
                // VistaDB
                case 0:
                {
                    String path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                    path = Path.Combine(path, "VistaDB");
                    if (Directory.Exists(path))
                    {
                        Directory.Delete(path, true);
                    }

                    builder  = new VistaDB_SQL();
                    executer = new VistaDB_SQLExecuter((VistaDB_SQL)builder, path);
                    connInfo = new VistaDB_ConnectionInfo(true);
                    break;
                }

                // DB2
                case 1:
                {
                    builder  = new DB2_SQL();
                    executer = new DB2_SQLExecuter((DB2_SQL)builder);
                    connInfo = new DB2_ConnectionInfo("sei-backend", "testdb", "eisst", "EISSTEISST");
                    break;
                }

                default:
                    return;
                }

                // Create and start the runner
                DBRunner runner = new DBRunner();

                try
                {
                    // Show provider
                    IProvider prov = executer.Provider;
                    Output("Provider: " + prov.Name + " - Version: " + prov.Version);
                    Output("");

                    // Create the database and test tables
                    DBDatabase db = new DBDatabase("DBTest.MyTest");

                    DBTable table1 = db.AddTable("Table1");
                    table1.AddColumn("uiNoegle", ColumnType.Guid, ColumnFlag.PrimaryKey | ColumnFlag.NotNull);
                    table1.AddColumn("txTekst", ColumnType.String, 20, ColumnFlag.None);
                    table1.AddColumn("iTal", ColumnType.Int, ColumnFlag.PrimaryKey | ColumnFlag.NotNull);
                    table1.AddColumn("dtDato", ColumnType.DateTime, ColumnFlag.IndexAsc);
                    table1.AddColumn("sLilleTal", ColumnType.Small, ColumnFlag.None);
                    table1.AddColumn("lStortTal", ColumnType.Long, ColumnFlag.NotNull);
                    table1.AddColumn("txStorTekst", ColumnType.Clob, 32 * 1024, ColumnFlag.None);
                    table1.AddColumn("bValg", ColumnType.Boolean, ColumnFlag.NotNull);
                    table1.AddColumn("biBillede", ColumnType.Blob, 10 * 1024 * 1024, ColumnFlag.Compressed);
                    table1.AddColumn("iAutoTaeller", ColumnType.Int, ColumnFlag.NotNull | ColumnFlag.Identity);

                    DBTable table2 = db.AddTable("Table2");
                    table2.AddColumn("uiNoegle", ColumnType.Guid, ColumnFlag.PrimaryKey | ColumnFlag.NotNull);
                    table2.AddColumn("txTekst", ColumnType.String, 20, ColumnFlag.None);
                    table2.AddColumn("iTal", ColumnType.Int, ColumnFlag.PrimaryKey | ColumnFlag.NotNull);
                    table2.AddColumn("dtDato", ColumnType.DateTime, ColumnFlag.IndexAsc);
                    table2.AddColumn("sLilleTal", ColumnType.Small, ColumnFlag.None);
                    table2.AddColumn("lStortTal", ColumnType.Long, ColumnFlag.NotNull);
                    table2.AddColumn("txStorTekst", ColumnType.Clob, 32 * 1024, ColumnFlag.None);
                    table2.AddColumn("bValg", ColumnType.Boolean, ColumnFlag.NotNull);
                    table2.AddColumn("biBillede", ColumnType.Blob, 10 * 1024 * 1024, ColumnFlag.Compressed);

                    TestDatabase(runner, executer, db);
                    TestConnection(runner, executer, db, connInfo);
                    TestTable(runner, executer, builder, db, table2, connInfo);

                    {
                        Output("Create table again for other tests");
                        DBConnection conn = runner.OpenConnection(executer, db, connInfo);

                        try
                        {
                            Stmt_CreateTable stmtCreate = new Stmt_CreateTable(table1);
                            runner.CreateTable(executer, conn, stmtCreate);

                            stmtCreate = new Stmt_CreateTable(table2);
                            runner.CreateTable(executer, conn, stmtCreate);
                        }
                        finally
                        {
                            conn.Close();
                            Output("");
                        }
                    }

                    TestTable2(runner, executer, db, "Table1", connInfo);
                    TestSmallInsert(runner, executer, builder, db, table1, connInfo);
                    TestSmallSelect(runner, executer, builder, db, table1, connInfo);
                    TestSmallDelete(runner, executer, builder, db, table1, connInfo);
                    TestTransactions(runner, executer, db, table2, connInfo);
                    TestUpdate(runner, executer, builder, db, table2, connInfo);
                    TestFunctions(runner, executer, builder, db, table2, connInfo);
                    TestUnion(runner, executer, builder, db, table1, table2, connInfo);
                    TestSQLBuild(builder, db, table1);

                    {
                        Output("Dropping testing tables");
                        DBConnection conn = runner.OpenConnection(executer, db, connInfo);

                        try
                        {
                            Stmt_DropTable stmtDrop = new Stmt_DropTable(table1);
                            runner.DropTable(executer, conn, stmtDrop);

                            stmtDrop = new Stmt_DropTable(table2);
                            runner.DropTable(executer, conn, stmtDrop);
                        }
                        finally
                        {
                            conn.Close();
                            Output("Done");
                        }
                    }
                }
                finally
                {
                    runner.Close();
                }
            }
            catch (Exception ex)
            {
                Output("Whole test failed with an exception:");
                Output(ex);
            }
        }