Ejemplo n.º 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());
        }
Ejemplo n.º 2
0
        private string RenderSimple(RenderingContext ctx)
        {
            var sb = new StringBuilder();

            ctx.AliasesStack.Push(_aliases);

            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)
                {
                    // if (!ctx.skipExplicitColumnTableNames) {
                    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));
                }

                else if (part.ParamIdx != -1)
                {
                    sb.Append(PgTypesConverter.ConvertToPgString(_parameters[part.ParamIdx]));
                }

                else if (part.RawQuery != null)
                {
                    sb.Append(part.RawQuery.RenderSimple(ctx));
                }
            }

            ctx.AliasesStack.Pop();
            return(sb.ToString());
        }
Ejemplo n.º 3
0
        public RawQuery AppendTableName(string tableName, string schema = null, string alias = null)
        {
            if (schema == null)
            {
                Append(EscapeUtils.QuoteObjectName(tableName));
            }
            else
            {
                Append($"{EscapeUtils.QuoteObjectName(schema)}.{EscapeUtils.QuoteObjectName(tableName)}");
            }

            if (alias != null)
            {
                Append(" ", EscapeUtils.QuoteObjectName(alias));
            }

            return(this);
        }
Ejemplo n.º 4
0
 public RawQuery AppendObjectName(string name)
 {
     Append(EscapeUtils.QuoteObjectName(name));
     return(this);
 }
Ejemplo n.º 5
0
 public RawQuery AppendColumnName(string columnName)
 {
     Append(EscapeUtils.QuoteObjectName(columnName));
     return(this);
 }