DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
QueryExtensions.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 using System.Collections.Generic;
19 
21 using Deveel.Data.Sql.Tables;
22 
23 namespace Deveel.Data.Sql.Statements {
24  public static class QueryExtensions {
25  public static ITable[] ExecuteQuery(this IQuery query, SqlQuery sqlQuery) {
26  return StatementExecutor.Execute(query, sqlQuery);
27  }
28 
29  public static ITable[] ExecuteQuery(this IQuery query, string sqlSource, params QueryParameter[] parameters) {
30  var sqlQuery = new SqlQuery(sqlSource);
31  if (parameters != null) {
32  foreach (var parameter in parameters) {
33  sqlQuery.Parameters.Add(parameter);
34  }
35  }
36 
37  return query.ExecuteQuery(sqlQuery);
38  }
39 
40  public static ITable[] ExecuteQuery(this IQuery query, string sqlSource) {
41  return query.ExecuteQuery(sqlSource, null);
42  }
43 
44  // TODO: Provide an overload with dynamic object parameter
45 
46  #region CreateView
47 
48  public static ITable ExecuteCreateView(this IQuery query, string viewName, string querySource) {
49  return ExecuteCreateView(query, viewName, new string[0], querySource);
50  }
51 
52  public static ITable ExecuteCreateView(this IQuery query, string viewName, IEnumerable<string> columnNames, string querySource) {
53  var expression = SqlExpression.Parse(querySource);
54  if (expression.ExpressionType != SqlExpressionType.Query)
55  throw new ArgumentException("The input query string is invalid.", "querySource");
56 
57  return query.ExecuteCreateView(viewName, columnNames, (SqlQueryExpression)expression);
58  }
59 
60  public static ITable ExecuteCreateView(this IQuery query, string viewName, SqlQueryExpression queryExpression) {
61  return ExecuteCreateView(query, viewName, new string[0], queryExpression);
62  }
63 
64  public static ITable ExecuteCreateView(this IQuery query, string viewName, IEnumerable<string> columnNames,
65  SqlQueryExpression queryExpression) {
66  var statement = new CreateViewStatement(viewName, columnNames, queryExpression);
67  return statement.Execute(query);
68  }
69 
70  #endregion
71  }
72 }
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
static ITable ExecuteCreateView(this IQuery query, string viewName, IEnumerable< string > columnNames, SqlQueryExpression queryExpression)
static SqlExpression Parse(string s)
Parses the given SQL string to an expression that can be evaluated.
static ITable[] ExecuteQuery(this IQuery query, SqlQuery sqlQuery)
static ITable[] Execute(IRequest query, SqlQuery sqlQuery)
This method transforms the input SQL query into a set of statements, prepares and executes them again...
static ITable ExecuteCreateView(this IQuery query, string viewName, string querySource)
static ITable[] ExecuteQuery(this IQuery query, string sqlSource, params QueryParameter[] parameters)
static ITable ExecuteCreateView(this IQuery query, string viewName, SqlQueryExpression queryExpression)
SqlExpressionType
All the possible type of SqlExpression supported
static ITable ExecuteCreateView(this IQuery query, string viewName, IEnumerable< string > columnNames, string querySource)
static ITable[] ExecuteQuery(this IQuery query, string sqlSource)
Defines the base class for instances that represent SQL expression tree nodes.
This class is used to transform an input query to a set of statements and execute them within a given...