Ejemplo n.º 1
0
 public static IEnumerable <Statement> Statements(string sql)
 {
     using (var stringReader = new StringReader(sql)) {
         var parser = new PlSql(stringReader);
         return(parser.SequenceOfStatements());
     }
 }
Ejemplo n.º 2
0
        public static ITable[] Execute(IDatabaseConnection connection, SqlQuery query)
        {
            // StatementTree caching

            // Substitute all parameter substitutions in the statement tree.
            // TODO: IExpressionPreparer preparer = new QueryPreparer(query);

            // Create a new parser and set the parameters...
            IEnumerable <Statement> statements;

            string commandText = query.Text;

            try {
                lock (SqlParser) {
                    SqlParser.ReInit(new StreamReader(new MemoryStream(Encoding.Unicode.GetBytes(commandText)), Encoding.Unicode));
                    SqlParser.Reset();
                    // Parse the statement.
                    statements = SqlParser.SequenceOfStatements();
                }
            } catch (ParseException e) {
                var tokens = SqlParser.token_source.tokenHistory;
                throw new SqlParseException(e, commandText, tokens);
            }


            List <ITable> results = new List <ITable>();

            foreach (Statement parsedStatement in statements)
            {
                var statement = parsedStatement;
                // TODO: statement = statement.PrepareExpressions(preparer);

                // Convert the StatementTree to a statement object
                statement.Query = query;

                DatabaseQueryContext context = new DatabaseQueryContext(connection);

                // Prepare the statement
                statement = statement.PrepareStatement(context);

                // Evaluate the SQL statement.
                results.Add(statement.Evaluate(context));
            }

            return(results.ToArray());
        }