public ITable ExecQuery(Query query) { // TODO: Look up the query in a cache to see if we parsed it // before. // Parse it SqlParser parser = new SqlParser(new StringReader(query.Text)); // Determine that type of expression and dispatch as necessary, // If it's a SELECT query, Expression expression; try { expression = parser.Statement(); } catch (ParseException e) { // Parse error, report it back as an sql exception. throw new ApplicationException(e.Message); } // commit and rollback are special case operations, string fun_name = ""; if (expression is FunctionExpression) { fun_name = expression.GetArgument("name").ToString(); } if (fun_name.Equals("transaction_commit")) { lastSpecialCommand = "commit"; return null; } if (fun_name.Equals("transaction_rollback")) { lastSpecialCommand = "rollback"; return null; } if (fun_name.Equals("schema_assignment")) { lastSpecialCommand = "set_schema"; specialCommandArgument = expression; return null; } // Put the operation through the interpreter return Execute(query, expression); }
public SqlType Parse(IContext context, string s) { var parser = new SqlParser(); var typeInfo = parser.ParseType(s); if (PrimitiveTypes.IsPrimitive(typeInfo.TypeName)) { return(PrimitiveTypes.Resolver.Resolve(typeInfo)); } if (context == null) { throw new Exception($"Type {typeInfo.TypeName} is not primitive and no context is provided"); } var resolver = context.Scope.Resolve <ISqlTypeResolver>(); if (resolver == null) { throw new InvalidOperationException($"The type {typeInfo.TypeName} is not primitive and no resolver was found in context"); } return(resolver.Resolve(typeInfo)); }
protected Expression ParseExpression(string s) { return(SqlParser.SqlExpression(s)); }
protected IEnumerable <Statement> ParseStatements(string s) { return(SqlParser.Statements(s)); }