DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlDefaultCompiler.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 
20 using Deveel.Data.Sql.Parser;
22 using Deveel.Data.Types;
23 
24 namespace Deveel.Data.Sql.Compile {
25  public sealed class SqlDefaultCompiler : ISqlCompiler {
27  if (context == null)
28  throw new ArgumentNullException("context");
29 
30  var compileResult = new SqlCompileResult(context);
31 
32  try {
33  var sqlSource = context.SourceText;
34  var result = SqlParsers.Default.Parse(sqlSource);
35 
36  foreach (var error in result.Errors) {
37  var location = new SourceLocation(error.Line, error.Column);
38  compileResult.Messages.Add(new SqlCompileMessage(CompileMessageLevel.Error, error.Message, location));
39  }
40 
41  ITypeResolver typeResolver = null;
42  if (context.Context != null)
43  typeResolver = context.Context.TypeResolver();
44 
45  var builder = new StatementBuilder(typeResolver);
46  var statements = builder.Build(result.RootNode);
47 
48  foreach (var statement in statements) {
49  compileResult.Statements.Add(statement);
50  }
51 
52  } catch (SqlParseException ex) {
53  compileResult.Messages.Add(new SqlCompileMessage(CompileMessageLevel.Error, ex.Message));
54  } catch (Exception ex) {
55  compileResult.Messages.Add(new SqlCompileMessage(CompileMessageLevel.Error, ex.Message));
56  }
57 
58  return compileResult;
59  }
60 
61  public void Dispose() {
62  }
63  }
64 }
SqlCompileResult Compile(SqlCompileContext context)
static readonly ISqlParser Default
Definition: SqlParsers.cs:23
SqlParseResult Parse(string input)
Analyzes and parses the input and results an object that describes the parsed nodes in a tree that ca...
An error that occurs when compiling a input string into a SQL object.