Exemplo n.º 1
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());
        }
Exemplo n.º 2
0
        public static bool TryInlineShortValue(PgValue pgValue, out string inlined)
        {
            inlined = null;

            object value = pgValue.Value;

            switch (pgValue.Type)
            {
            case KDPgValueTypeEnum _:
                inlined = PgTypesConverter.ConvertToPgString(value);
                return(true);
            }

            switch (value)
            {
            case string s when pgValue.Type == KDPgValueTypeInstances.String && s.Length < 30:
                inlined = PgTypesConverter.ConvertToPgString(s);
                return(true);

            case int v:
                inlined = PgTypesConverter.ConvertToPgString(v);
                return(true);

            case null:
                inlined = "NULL";
                return(true);

            case true:
                inlined = "TRUE";
                return(true);

            case false:
                inlined = "FALSE";
                return(true);
            }

            return(false);
        }