Beispiel #1
0
        private string RenderInto(ParametersContainer outParameters, RenderingContext ctx)
        {
            var sb = new StringBuilder();

            ctx.AliasesStack.Push(_aliases);

            if (_isSimple)
            {
                var res = RenderSimple(ctx);
                ctx.AliasesStack.Pop();
                return(res);
            }

            foreach (var part in _parts)
            {
                if (part.Text != null)
                {
                    sb.Append(part.Text);
                }

                if (part.Table != null)
                {
                    var alias = ResolvePlaceholder(ctx, part.Table);
                    if (alias != null)
                    {
                        sb.Append(EscapeUtils.QuoteObjectName(alias));
                    }
                    else
                    {
                        sb.Append(EscapeUtils.QuoteTable(part.Table.Table.Name, part.Table.Table.Schema));
                    }
                }

                if (part.Column != null)
                {
                    var alias = ResolvePlaceholder(ctx, part.Column.TablePlaceholder);
                    if (alias != null)
                    {
                        sb.Append(EscapeUtils.QuoteObjectName(alias));
                        sb.Append(".");
                    }

                    sb.Append(EscapeUtils.QuoteObjectName(part.Column.Column.Name));
                }

                if (part.ParamIdx != -1)
                {
                    sb.Append(outParameters.GetNextParam(_parameters[part.ParamIdx]));
                }

                if (part.RawQuery != null)
                {
                    sb.Append(part.RawQuery.RenderInto(outParameters, ctx));
                }
            }

            ctx.AliasesStack.Pop();
            return(sb.ToString());
        }
Beispiel #2
0
        public void Render(out string query, out ParametersContainer outParameters)
        {
            var ctx = new RenderingContext();

            ctx.AliasesStack = new Stack <Dictionary <string, string> >();
            ctx.AliasesStack.Push(_aliases);
            ctx.SkipExplicitColumnTableNames = _skipExplicitColumnTableNames;
            outParameters = new ParametersContainer();
            query         = RenderInto(outParameters, ctx);
        }
Beispiel #3
0
        public RawQuery Append(PgValue value)
        {
            if (ParametersContainer.TryInlineShortValue(value, out string inlined))
            {
                Append(inlined);
            }
            else
            {
                int idx = _parameters.Count;
                _parameters.Add(value);
                _parts.Add(new QueryPart()
                {
                    ParamIdx = idx,
                });
            }

            return(this);
        }