MCPcopy
hub / github.com/uptrace/uptrace / append

Method append

pkg/clickhouse/ch/chschema/formatter.go:39–98  ·  view source on GitHub ↗
(dst []byte, p *parser.Parser, args []any)

Source from the content-addressed store, hash-verified

37 return f.append(b, parser.NewString(query), args)
38}
39func (f Formatter) append(dst []byte, p *parser.Parser, args []any) []byte {
40 var namedArgs NamedArgAppender
41 if len(args) == 1 {
42 if v, ok := args[0].(NamedArgAppender); ok {
43 namedArgs = v
44 } else if v, ok := newStructArgs(f, args[0]); ok {
45 namedArgs = v
46 }
47 }
48 var argIndex int
49 for p.Valid() {
50 b, ok := p.ReadSep('?')
51 if !ok {
52 dst = append(dst, b...)
53 continue
54 }
55 if len(b) > 0 && b[len(b)-1] == '\\' {
56 dst = append(dst, b[:len(b)-1]...)
57 dst = append(dst, '?')
58 continue
59 }
60 dst = append(dst, b...)
61 name, numeric := p.ReadIdent()
62 if name != "" {
63 if numeric {
64 idx, err := strconv.Atoi(name)
65 if err != nil {
66 goto restore_arg
67 }
68 if idx >= len(args) {
69 goto restore_arg
70 }
71 dst = f.appendArg(dst, args[idx])
72 continue
73 }
74 if namedArgs != nil {
75 dst, ok = namedArgs.AppendNamedArg(f, dst, name)
76 if ok {
77 continue
78 }
79 }
80 dst, ok = f.args.AppendNamedArg(f, dst, name)
81 if ok {
82 continue
83 }
84 restore_arg:
85 dst = append(dst, '?')
86 dst = append(dst, name...)
87 continue
88 }
89 if argIndex >= len(args) {
90 dst = append(dst, '?')
91 continue
92 }
93 arg := args[argIndex]
94 argIndex++
95 dst = f.appendArg(dst, arg)
96 }

Callers 1

AppendQueryMethod · 0.95

Calls 6

appendArgMethod · 0.95
AppendNamedArgMethod · 0.95
newStructArgsFunction · 0.85
ReadIdentMethod · 0.80
ValidMethod · 0.45
ReadSepMethod · 0.45

Tested by

no test coverage detected