Internal
SqlBuilderBase.cs
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using SqExpress.StatementSyntax;
using SqExpress.Syntax;
using SqExpress.Syntax.Boolean;
using SqExpress.Syntax.Boolean.Predicate;
using SqExpress.Syntax.Expressions;
using SqExpress.Syntax.Functions;
using SqExpress.Syntax.Functions.Known;
using SqExpress.Syntax.Internal;
using SqExpress.Syntax.Names;
using SqExpress.Syntax.Output;
using SqExpress.Syntax.Select;
using SqExpress.Syntax.Select.Selecsatems;
using SqExpress.Syntax.Type;
using SqExpress.Syntax.Update;
using SqExpress.Syntax.Value;
using SqExpress.Utils;
namespace SqExpress.SqlExport.Internal
{
internal abstract clast SqlBuilderBase: IExprVisitorInternal
{
protected readonly SqlBuilderOptions Options;
protected readonly StringBuilder Builder;
private IStatementVisitor? _statementBuilder;
protected SqlBuilderBase(SqlBuilderOptions? options, StringBuilder? externalBuilder)
{
this.Options = options ?? SqlBuilderOptions.Default;
this.Builder = externalBuilder ?? new StringBuilder();
}
private readonly SqlAliasGenerator _aliasGenerator = new SqlAliasGenerator();
//Boolean Expressions
public bool VisitExprBooleanAnd(ExprBooleanAnd expr, IExpr? parent)
{
if (expr.Left is ExprBooleanOr)
{
this.AcceptPar('(', expr.Left, ')', expr);
this.Builder.Append("AND");
}
else
{
expr.Left.Accept(this, expr);
this.Builder.Append(" AND");
}
if (expr.Right is ExprBooleanOr)
{
this.AcceptPar('(', expr.Right, ')', expr);
}
else
{
this.Builder.Append(' ');
expr.Right.Accept(this, expr);
}
return true;
}
public bool VisitExprBooleanOr(ExprBooleanOr expr, IExpr? parent)
{
expr.Left.Accept(this, expr);
this.Builder.Append(" OR ");
expr.Right.Accept(this, expr);
return true;
}
public bool VisitExprBooleanNot(ExprBooleanNot expr, IExpr? parent)
{
this.Builder.Append("NOT");
if (expr.Expr is ExprPredicate)
{
this.Builder.Append(' ');
expr.Expr.Accept(this, expr);
}
else
{
this.AcceptPar('(', expr.Expr, ')', expr);
}
return true;
}
//Boolean Predicates
public bool VisitExprBooleanNotEq(ExprBooleanNotEq exprBooleanNotEq, IExpr? parent)
{
exprBooleanNotEq.Left.Accept(this, exprBooleanNotEq);
this.Builder.Append("!=");
exprBooleanNotEq.Right.Accept(this, exprBooleanNotEq);
return true;
}
public bool VisitExprBooleanEq(ExprBooleanEq exprBooleanEq, IExpr? parent)
{
exprBooleanEq.Left.Accept(this, exprBooleanEq);
this.Builder.Append('=');
exprBooleanEq.Right.Accept(this, exprBooleanEq);
return true;
}
public bool VisitExprBooleanGt(ExprBooleanGt booleanGt, IExpr? parent)
{
booleanGt.Left.Accept(this, booleanGt);
this.Builder.Append('>');
booleanGt.Right.Accept(this, booleanGt);
return true;
}
public bool VisitExprBooleanGtEq(ExprBooleanGtEq booleanGtEq, IExpr? parent)
{
booleanGtEq.Left.Accept(this, booleanGtEq);
this.Builder.Append(">=");
booleanGtEq.Right.Accept(this, booleanGtEq);
return true;
}
public bool VisitExprBooleanLt(ExprBooleanLt booleanLt, IExpr? parent)
{
booleanLt.Left.Accept(this, booleanLt);
this.Builder.Append('