Ejemplo n.º 1
0
        public void TestSetUp()
        {
            HeapDatabase testdb = new HeapDatabase(null, "testdb");
            ITransactionState transaction = testdb.CreateTransaction();
            transaction.CreateSchema("test");

            IMutableTable table = (IMutableTable) transaction.CreateTable(new TableName("test", "names"));
            table.Columns.Add("id", SqlType.Numeric, true);
            table.Columns.Add("first_name", SqlType.String, true);
            table.Columns.Add("last_name", SqlType.String, true);

            TableRow row = table.NewRow();
            row.SetValue("id", 1);
            row.SetValue("first_name", "Antonello");
            row.SetValue("last_name", "Provenzano");
            row.Insert();
            table.Commit();

            table = (IMutableTable) transaction.CreateTable(new TableName("test", "books"));
            table.Columns.Add("id", SqlType.Numeric, true);
            table.Columns.Add("title", SqlType.String, true);
            table.Columns.Add("author", SqlType.String, false);

            row = table.NewRow();
            row["id"] = 1;
            row["title"] = "The Lord Of The Rings";
            row["author"] = "J. R. R. Tolkien";
            row.Insert();

            row = table.NewRow();
            row["id"] = 2;
            row["title"] = "Buddenbrooks";
            row["author"] = "Thomas Mann";
            row.Insert();

            table.Commit();

            table = (IMutableTable) transaction.CreateTable(new TableName("test", "book_read"));
            table.Columns.Add("id", SqlType.Numeric, true);
            table.Columns.Add("book_id", SqlType.Numeric, true);
            table.Columns.Add("name_id", SqlType.Numeric, true);
            table.Columns.Add("read_date", SqlType.DateTime, true);

            row = table.NewRow();
            row["id"] = 1;
            row["book_id"] = 1;
            row["name_id"] = 1;
            row["read_date"] = "2001-12-22";
            row.Insert();

            row = table.NewRow();
            row["id"] = 2;
            row["book_id"] = 2;
            row["name_id"] = 1;
            row["read_date"] = "2009-05-10";
            row.Insert();

            table.Commit();

            testdb.CommitTransaction(transaction);

            sessionContext = new EmbeddedSessionContext(testdb, true, "antonello");
            connection = sessionContext.CreateConnection();
            connection.Open();

            try {
                IDbCommand command = connection.CreateCommand();
                command.CommandText = "SET SCHEMA test;";
                command.ExecuteNonQuery();
            } catch (Exception e) {
                Console.Error.WriteLine("Error: {0}", e.Message);
                Console.Error.WriteLine(e.StackTrace);
            }
        }