Example #1
0
        public ITable Execute(Query query, Expression expression)
        {
            // Create the QueryProcessor
            QueryProcessor processor = new QueryProcessor(transaction);

            // If it's a select,
            if (expression is SelectExpression) {
                QueryOptimizer optimizer = new QueryOptimizer(transaction);
                expression = optimizer.SubstituteParameters(expression, query);
                expression = optimizer.Qualify(expression);
                expression = optimizer.Optimize(expression);

                // Execute the query,
                return processor.Execute(expression);
            }

            // Set the parameter as the base table, and the base rowid (the
            // parameters table only has 1 row).
            processor.PushTable(new QueryParametersTable(query));
            processor.UpdateTableRow(new RowId(0));

            // Otherwise it must be an interpretable function

            if (expression is FunctionExpression) {
                string fun_name = (string)expression.GetArgument("name");

                if (fun_name.Equals("create_table"))
                    return CreateTable(expression);
                /*
                TODO:
                if (fun_name.Equals("drop_table"))
                    return DropTable(processor, expression);
                if (fun_name.Equals("create_index"))
                    return CreateIndex(processor, expression);
                if (fun_name.Equals("drop_index"))
                    return DropIndex(processor, expression);
                if (fun_name.Equals("explain_expression"))
                    return ExplainExpression(expression);
                */
            }

            throw new NotSupportedException();
        }