18 using System.Collections.Generic;
25 namespace Deveel.Data.Sql.Expressions {
28 private bool rootQuery =
true;
31 builder =
new StringBuilder();
38 return builder.ToString();
43 builder.Append(
" = ");
50 Visit(binaryEpression.
Left);
52 var binaryOpString = GetBinaryOperatorString(binaryEpression.
ExpressionType);
53 builder.AppendFormat(
" {0} ", binaryOpString);
55 Visit(binaryEpression.
Right);
57 return binaryEpression;
61 switch (expressionType) {
123 throw new NotSupportedException();
128 builder.Append(
"CAST ");
129 Visit(castExpression.
Value);
130 builder.Append(
" AS ");
131 builder.Append(castExpression.
SqlType);
133 return base.VisitCast(castExpression);
137 return base.VisitConditional(conditional);
141 var value = constant.
Value;
144 builder.Append(
"({QUERY})");
148 builder.Append(
"NULL");
151 var sz = array.Length;
152 for (
int i = 0; i < sz; i++) {
156 builder.Append(
", ");
160 }
else if (value.Type is
NullType) {
161 builder.Append(
"NULL");
162 }
else if (value.Type.IsPrimitive) {
164 builder.Append(
"NULL");
166 builder.Append(value.Value);
180 var argc = args.Length;
182 for (
int i = 0; i < argc; i++) {
186 builder.Append(
", ");
196 var columns = selectColumns.ToArray();
197 var sz = columns.Length;
198 for (
int i = 0; i < sz; i++) {
199 var column = columns[i];
205 builder.AppendFormat(
"{0}.*", column.TableName);
208 Visit(column.Expression);
211 if (!
String.IsNullOrEmpty(column.Alias))
212 builder.AppendFormat(
" AS {0}", column.Alias);
215 builder.Append(
", ");
223 builder.Append(
"SELECT ");
225 builder.Append(
"DISTINCT ");
233 builder.Append(
" WHERE ");
238 builder.Append(
" GROUP BY ");
239 VisitExpressionList(query.
GroupBy.ToArray());
242 builder.Append(
" HVAING ");
248 builder.Append(
" GROUP MAX ");
261 if (fromClause == null || fromClause.
IsEmpty)
264 builder.Append(
"FROM ");
266 var tables = fromClause.
AllTables.ToList();
267 for (
int i = 0; i < tables.Count; i++) {
268 var source = tables[i];
274 if (joinPart != null) {
276 builder.Append(
" INNER JOIN ");
278 builder.Append(
" RIGHT OUTER JOIN ");
280 builder.Append(
" LEFT OUTER JOIN ");
282 builder.Append(
" FULL OUTER JOINT ");
287 if (source.IsSubQuery) {
289 Visit(source.SubQuery);
292 builder.Append(source.Name);
295 if (!
String.IsNullOrEmpty(source.Alias)) {
296 builder.Append(
" AS ");
297 builder.Append(source.Alias);
300 if (i < tables.Count - 1) {
301 if (joinPart == null) {
302 builder.Append(
", ");
304 builder.Append(
" ON ");
320 for (
int i = 0; i < sz; i++) {
323 builder.Append(
", ");
332 builder.Append(unaryOpString);
348 throw new NotSupportedException();
override SqlExpressionType ExpressionType
IEnumerable< SelectColumn > SelectColumns
ObjectName ReferenceName
Gets the name of the object referenced by the expression.
SqlExpression Operand
Gets the operand expression that is computed.
SqlExpression ValueExpression
SqlExpression Value
Gets the expression whose evaluated value will be converted.
override SqlExpression VisitConditional(SqlConditionalExpression conditional)
An expression that references an object within a context.
A long string in the system.
Handles expressions computed against an unary operator.
override SqlExpression VisitConstant(SqlConstantExpression constant)
string ToSqlString(SqlExpression expression)
JoinType
Enumerates the kind of group join in a selection query.
override SqlExpression VisitUnary(SqlUnaryExpression unary)
SqlType SqlType
Gets the destination type of the conversion
static string GetBinaryOperatorString(SqlExpressionType expressionType)
void PrintFromClause(FromClause fromClause)
override SqlExpression VisitQuery(SqlQueryExpression query)
string GetUnaryOperatorString(SqlExpressionType unaryType)
override SqlExpression VisitTuple(SqlTupleExpression expression)
An SqlExpression that will cast a value retrieved by the evaluation of another expression into a give...
JoinPart GetJoinPart(int offset)
Gets the descriptor of the join at the given offset.
ISqlObject Value
Gets the underlined value that is handled.
IEnumerable< SqlExpression > GroupBy
override SqlExpression VisitAssign(SqlAssignExpression assign)
SqlExpressionType
All the possible type of SqlExpression supported
ExpressionStringBuilder()
DataObject Value
Gets the constant value of the expression.
void PrintQueryColumns(IEnumerable< SelectColumn > selectColumns)
A container for the FROM clause of a select statement.
IEnumerable< FromTable > AllTables
Gets an enumeration of all the tables that are the source of the query.
SqlExpression[] Arguments
override SqlExpression VisitCast(SqlCastExpression castExpression)
string FullName
Gets the full reference name formatted.
override SqlExpression VisitVariableReference(SqlVariableReferenceExpression reference)
override SqlExpression VisitFunctionCall(SqlFunctionCallExpression expression)
Visits the expression that calls the function defined.
An expression that holds a constant value.
override SqlExpression VisitReference(SqlReferenceExpression reference)
SqlExpression OnExpression
readonly StringBuilder builder
override SqlExpressionType ExpressionType
SqlExpression[] Expressions
A data type that represents the NULL value of a given SQL data type.
Defines the base class for instances that represent SQL expression tree nodes.
An object that provides methods for accessing a finite collection of SQL expressions.
SqlExpression HavingExpression
A visitor for SqlExpression objects.
SqlExpression WhereExpression
SqlExpression ReferenceExpression
override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression)