示例#1
0
        public virtual string CompileTableExpression(SqlResult ctx, FromBase from)
        {
            if (from is RawFromClause raw)
            {
                ctx.Bindings.AddRange(raw.Bindings);
                return(WrapIdentifiers(raw.Expression));
            }

            if (from is QueryFromClause queryFromClause)
            {
                var fromQuery = queryFromClause.Query;

                var alias = string.IsNullOrEmpty(fromQuery.QueryAlias) ? "" : $" {TableAsKeyword}" + WrapValue(fromQuery.QueryAlias);

                var subCtx = CompileSelectQuery(fromQuery);

                ctx.Bindings.AddRange(subCtx.Bindings);

                return("(" + subCtx.RawSql + ")" + alias);
            }

            if (from is FromClause fromClause)
            {
                return(Wrap(fromClause.Table));
            }

            throw InvalidClauseException("TableExpression", from);
        }
示例#2
0
        public virtual SqlResult CompileCte(FromBase cte)
        {
            var ctx = new SqlResult();

            if (null == cte)
            {
                return(ctx);
            }

            if (cte is RawFromClause raw)
            {
                ctx.Bindings.AddRange(raw.Bindings);
                ctx.RawSql = $"{WrapValue(raw.Alias)} AS ({WrapIdentifiers(raw.Expression)})";
            }
            else if (cte is QueryFromClause queryFromClause)
            {
                var subCtx = CompileSelectQuery(queryFromClause.Query);
                ctx.Bindings.AddRange(subCtx.Bindings);

                ctx.RawSql = $"{WrapValue(queryFromClause.Alias)} AS ({subCtx.RawSql})";
            }

            return(ctx);
        }