MCPcopy
hub / github.com/jmoiron/sqlx / Rebind

Function Rebind

bind.go:60–90  ·  bind.go::Rebind

FIXME: this should be able to be tolerant of escaped ?'s in queries without losing much speed, and should be to avoid confusion. Rebind a query from the default bindtype (QUESTION) to the target bindtype.

(bindType int, query string)

Source from the content-addressed store, hash-verified

58
59// Rebind a query from the default bindtype (QUESTION) to the target bindtype.
60func Rebind(bindType int, query string) string {
61 switch bindType {
62 case QUESTION, UNKNOWN:
63 return query
64 }
65
66 // Add space enough for 10 params before we have to allocate
67 rqb := make([]byte, 0, len(query)+10)
68
69 var i, j int
70
71 for i = strings.Index(query, "?"); i != -1; i = strings.Index(query, "?") {
72 rqb = append(rqb, query[:i]...)
73
74 switch bindType {
75 case DOLLAR:
76 rqb = append(rqb, '$')
77 case NAMED:
78 rqb = append(rqb, ':', 'a', 'r', 'g')
79 case AT:
80 rqb = append(rqb, '@', 'p')
81 }
82
83 j++
84 rqb = strconv.AppendInt(rqb, int64(j), 10)
85
86 query = query[i+1:]
87 }
88
89 return string(append(rqb, query...))
90}
91
92// Experimental implementation of Rebind which uses a bytes.Buffer. The code is
93// much simpler and should be more resistant to odd unicode, but it is twice as

Callers 6

RebindMethod · 0.85
RebindMethod · 0.85
RebindMethod · 0.85
bindArrayFunction · 0.85
TestRebindFunction · 0.85
BenchmarkRebindFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestRebindFunction · 0.68
BenchmarkRebindFunction · 0.68