MCPcopy Index your code
hub / github.com/upper/db / expandQuery

Function expandQuery

internal/sqlbuilder/convert.go:16–54  ·  view source on GitHub ↗
(in []byte, inArgs []interface{})

Source from the content-addressed store, hash-verified

14)
15
16func expandQuery(in []byte, inArgs []interface{}) ([]byte, []interface{}) {
17 out := make([]byte, 0, len(in))
18 outArgs := make([]interface{}, 0, len(inArgs))
19
20 i := 0
21 for i < len(in) && len(inArgs) > 0 {
22 if in[i] == '?' {
23 out = append(out, in[:i]...)
24 in = in[i+1:]
25 i = 0
26
27 replace, replaceArgs := expandArgument(inArgs[0])
28 inArgs = inArgs[1:]
29
30 if len(replace) > 0 {
31 replace, replaceArgs = expandQuery(replace, replaceArgs)
32 out = append(out, replace...)
33 } else {
34 out = append(out, '?')
35 }
36
37 outArgs = append(outArgs, replaceArgs...)
38 continue
39 }
40 i = i + 1
41 }
42
43 if len(out) < 1 {
44 return in, inArgs
45 }
46
47 out = append(out, in[:]...)
48 in = nil
49
50 outArgs = append(outArgs, inArgs[:]...)
51 inArgs = nil
52
53 return out, outArgs
54}
55
56func expandArgument(arg interface{}) ([]byte, []interface{}) {
57 values, isSlice := toInterfaceArguments(arg)

Callers 2

expandArgumentFunction · 0.85
PreprocessFunction · 0.85

Calls 1

expandArgumentFunction · 0.85

Tested by

no test coverage detected