5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
\r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
8 // of this software and associated documentation files (the "Software"), to deal
\r
9 // in the Software without restriction, including without limitation the rights
\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
11 // copies of the Software, and to permit persons to whom the Software is
\r
12 // furnished to do so, subject to the following conditions:
\r
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
27 using System.Collections.Generic;
\r
28 using System.Linq.Expressions;
\r
30 using DbLinq.Data.Linq.Sql;
\r
31 using DbLinq.Data.Linq.Sugar.Expressions;
\r
33 namespace DbLinq.Vendor
\r
38 interface ISqlProvider
\r
41 /// String values and function parameter first character index is 1
\r
43 bool StringIndexStartsAtOne { get; }
\r
45 string NewLine { get; }
\r
48 /// Converts a constant value to a literal representation
\r
50 /// <param name="literal"></param>
\r
51 /// <returns></returns>
\r
52 SqlStatement GetLiteral(object literal);
\r
55 /// Converts a standard operator to an expression
\r
57 /// <param name="operationType"></param>
\r
58 /// <param name="p"></param>
\r
59 /// <returns></returns>
\r
60 SqlStatement GetLiteral(ExpressionType operationType, IList<SqlStatement> p);
\r
63 /// Converts a special expression type to literal
\r
65 /// <param name="operationType"></param>
\r
66 /// <param name="p"></param>
\r
67 /// <returns></returns>
\r
68 SqlStatement GetLiteral(SpecialExpressionType operationType, IList<SqlStatement> p);
\r
71 /// Places the expression into parenthesis
\r
73 /// <param name="a"></param>
\r
74 /// <returns></returns>
\r
75 SqlStatement GetParenthesis(SqlStatement a);
\r
78 /// Returns a column related to a table.
\r
79 /// Ensures about the right case
\r
81 /// <param name="table"></param>
\r
82 /// <param name="column"></param>
\r
83 /// <returns></returns>
\r
84 string GetColumn(string table, string column);
\r
87 /// Returns a column related to a table.
\r
88 /// Ensures about the right case
\r
90 /// <param name="column"></param>
\r
91 /// <returns></returns>
\r
92 string GetColumn(string column);
\r
95 /// Returns a table alias
\r
96 /// Ensures about the right case
\r
98 /// <param name="table"></param>
\r
99 /// <param name="alias"></param>
\r
100 /// <returns></returns>
\r
101 string GetTableAsAlias(string table, string alias);
\r
104 /// Returns a subquery alias
\r
105 /// Ensures about the right case
\r
107 /// <param name="table"></param>
\r
108 /// <param name="alias"></param>
\r
109 /// <returns></returns>
\r
110 string GetSubQueryAsAlias(string table, string alias);
\r
113 /// Returns a table alias
\r
115 /// <param name="table"></param>
\r
116 /// <returns></returns>
\r
117 string GetTable(string table);
\r
120 /// Returns a literal parameter name
\r
122 /// <returns></returns>
\r
123 string GetParameterName(string nameBase);
\r
126 /// Joins a list of table selection to make a FROM clause
\r
128 /// <param name="tables"></param>
\r
129 /// <returns></returns>
\r
130 SqlStatement GetFromClause(SqlStatement[] tables);
\r
133 /// Joins a list of conditions to make a WHERE clause
\r
135 /// <param name="wheres"></param>
\r
136 /// <returns></returns>
\r
137 SqlStatement GetWhereClause(SqlStatement[] wheres);
\r
140 /// Returns a valid alias syntax for the given table
\r
142 /// <param name="nameBase"></param>
\r
143 /// <returns></returns>
\r
144 string GetTableAlias(string nameBase);
\r
147 /// Joins a list of operands to make a SELECT clause
\r
149 /// <param name="selects"></param>
\r
150 /// <returns></returns>
\r
151 SqlStatement GetSelectClause(SqlStatement[] selects);
\r
154 /// Joins a list of operands to make a SELECT clause
\r
156 /// <param name="selects"></param>
\r
157 /// <returns></returns>
\r
158 SqlStatement GetSelectDistinctClause(SqlStatement[] selects);
\r
161 /// Returns all table columns (*)
\r
163 /// <returns></returns>
\r
164 string GetColumns();
\r
167 /// Returns a LIMIT clause around a SELECT clause
\r
169 /// <param name="select">SELECT clause</param>
\r
170 /// <param name="limit">limit value (number of columns to be returned)</param>
\r
171 /// <returns></returns>
\r
172 SqlStatement GetLiteralLimit(SqlStatement select, SqlStatement limit);
\r
175 /// Returns a LIMIT clause around a SELECT clause, with offset
\r
177 /// <param name="select">SELECT clause</param>
\r
178 /// <param name="limit">limit value (number of columns to be returned)</param>
\r
179 /// <param name="offset">first row to be returned (starting from 0)</param>
\r
180 /// <param name="offsetAndLimit">limit+offset</param>
\r
181 /// <returns></returns>
\r
182 SqlStatement GetLiteralLimit(SqlStatement select, SqlStatement limit, SqlStatement offset, SqlStatement offsetAndLimit);
\r
185 /// Returns an ORDER criterium
\r
187 /// <param name="expression"></param>
\r
188 /// <param name="descending"></param>
\r
189 /// <returns></returns>
\r
190 SqlStatement GetOrderByColumn(SqlStatement expression, bool descending);
\r
193 /// Joins a list of conditions to make a ORDER BY clause
\r
195 /// <param name="orderBy"></param>
\r
196 /// <returns></returns>
\r
197 SqlStatement GetOrderByClause(SqlStatement[] orderBy);
\r
200 /// Joins a list of conditions to make a GROUP BY clause
\r
202 /// <param name="groupBy"></param>
\r
203 /// <returns></returns>
\r
204 SqlStatement GetGroupByClause(SqlStatement[] groupBy);
\r
207 /// Joins a list of conditions to make a HAVING clause
\r
209 /// <param name="havings"></param>
\r
210 /// <returns></returns>
\r
211 SqlStatement GetHavingClause(SqlStatement[] havings);
\r
214 /// Returns an operation between two SELECT clauses (UNION, UNION ALL, etc.)
\r
216 /// <param name="selectOperator"></param>
\r
217 /// <param name="selectA"></param>
\r
218 /// <param name="selectB"></param>
\r
219 /// <returns></returns>
\r
220 SqlStatement GetLiteral(SelectOperatorType selectOperator, SqlStatement selectA, SqlStatement selectB);
\r
223 /// Builds an insert clause
\r
225 /// <param name="table">Table name</param>
\r
226 /// <param name="inputColumns">Columns to be inserted</param>
\r
227 /// <param name="inputValues">Values to be inserted into columns</param>
\r
228 /// <returns></returns>
\r
229 SqlStatement GetInsert(SqlStatement table, IList<SqlStatement> inputColumns, IList<SqlStatement> inputValues);
\r
232 /// Builds the statements that gets back the IDs for the inserted statement
\r
234 /// <param name="outputParameters">Expected output parameters</param>
\r
235 /// <param name="outputExpressions">Expressions (to help generate output parameters)</param>
\r
236 /// <returns></returns>
\r
237 SqlStatement GetInsertIds(IList<SqlStatement> outputParameters, IList<SqlStatement> outputExpressions);
\r
240 /// Builds an update clause
\r
242 /// <param name="table"></param>
\r
243 /// <param name="inputColumns">Columns to be inserted</param>
\r
244 /// <param name="inputValues">Values to be inserted into columns</param>
\r
245 /// <param name="outputParameters">Expected output parameters</param>
\r
246 /// <param name="outputExpressions">Expressions (to help generate output parameters)</param>
\r
247 /// <param name="inputPKColumns">PK columns for reference</param>
\r
248 /// <param name="inputPKValues">PK values for reference</param>
\r
249 /// <returns></returns>
\r
250 SqlStatement GetUpdate(SqlStatement table, IList<SqlStatement> inputColumns, IList<SqlStatement> inputValues,
\r
251 IList<SqlStatement> outputParameters, IList<SqlStatement> outputExpressions,
\r
252 IList<SqlStatement> inputPKColumns, IList<SqlStatement> inputPKValues);
\r
255 /// Builds a delete clause
\r
257 /// <param name="table"></param>
\r
258 /// <param name="inputPKColumns">PK columns for reference</param>
\r
259 /// <param name="inputPKValues">PK values for reference</param>
\r
260 /// <returns></returns>
\r
261 SqlStatement GetDelete(SqlStatement table, IList<SqlStatement> inputPKColumns, IList<SqlStatement> inputPKValues);
\r
264 /// given 'User', return '[User]' to prevent a SQL keyword conflict
\r
266 /// <param name="name"></param>
\r
267 string GetSafeName(string name);
\r
270 /// Returns a case safe query, converting quoted names <<MixedCaseName>> to "MixedCaseName"
\r
272 /// <param name="sqlString"></param>
\r
273 /// <returns></returns>
\r
274 string GetSafeQuery(string sqlString);
\r
277 ///Returns a SqlStatement with a conversion of an expression(value) to a type(newType)
\r
281 /// value= OrderDetail.Quantity
\r
282 /// newType= boolean
\r
284 /// it should return CONVERT(bit,OrderDetail.Quantity)
\r
286 /// <returns></returns>
\r
287 SqlStatement GetLiteralConvert(SqlStatement value, System.Type newType);
\r
290 /// Returns an INNER JOIN syntax
\r
292 /// <param name="joinedTable"></param>
\r
293 /// <param name="joinExpression"></param>
\r
294 /// <returns></returns>
\r
295 SqlStatement GetInnerJoinClause(SqlStatement joinedTable, SqlStatement joinExpression);
\r
298 /// Returns a LEFT JOIN syntax
\r
300 /// <param name="joinedTable"></param>
\r
301 /// <param name="joinExpression"></param>
\r
302 /// <returns></returns>
\r
303 SqlStatement GetLeftOuterJoinClause(SqlStatement joinedTable, SqlStatement joinExpression);
\r
306 /// Returns a RIGHT JOIN syntax
\r
308 /// <param name="joinedTable"></param>
\r
309 /// <param name="joinExpression"></param>
\r
310 /// <returns></returns>
\r
311 SqlStatement GetRightOuterJoinClause(SqlStatement joinedTable, SqlStatement joinExpression);
\r
314 /// Concatenates all join clauses
\r
316 /// <param name="joins"></param>
\r
317 /// <returns></returns>
\r
318 SqlStatement GetJoinClauses(SqlStatement[] joins);
\r