Skip to content

Commit 6f1dfd0

Browse files
author
deatheyes
committed
update: trackedbuff for normalizer
1 parent a4d5ffc commit 6f1dfd0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tracked_buffer.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,40 @@ type TrackedBuffer struct {
3636
*bytes.Buffer
3737
bindLocations []bindLocation
3838
nodeFormatter NodeFormatter
39+
vPrefix string
40+
fPrefix string
41+
Vars map[string]string
42+
vCount int
43+
fCount int
3944
}
4045

4146
// NewTrackedBuffer creates a new TrackedBuffer.
4247
func NewTrackedBuffer(nodeFormatter NodeFormatter) *TrackedBuffer {
4348
return &TrackedBuffer{
4449
Buffer: new(bytes.Buffer),
4550
nodeFormatter: nodeFormatter,
51+
Vars: make(map[string]string),
52+
vPrefix: ":v",
53+
fPrefix: ":f",
54+
vCount: 1,
55+
fCount: 1,
4656
}
4757
}
4858

59+
// VarArg create variable id
60+
func (buf *TrackedBuffer) VarArg() string {
61+
name := fmt.Sprintf("%s%d", buf.vPrefix, buf.vCount)
62+
buf.vCount++
63+
return name
64+
}
65+
66+
// FuncArg create function id
67+
func (buf *TrackedBuffer) FuncArg() string {
68+
name := fmt.Sprintf("%s%d", buf.fPrefix, buf.fCount)
69+
buf.fCount++
70+
return name
71+
}
72+
4973
// WriteNode function, initiates the writing of a single SQLNode tree by passing
5074
// through to Myprintf with a default format string
5175
func (buf *TrackedBuffer) WriteNode(node SQLNode) *TrackedBuffer {

0 commit comments

Comments
 (0)