Skip to content

Commit b6e3adf

Browse files
committed
fix template error(arg number > 10)
1 parent 5e5ca5e commit b6e3adf

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

parsing/template/dynamic.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (d *MysqlDynamic) mysqlWhere(b interface{}, cond, columnDesc string, value
151151

152152
func (d *MysqlDynamic) Param(p interface{}) string {
153153
d.index++
154-
key := argPlaceHolder + strconv.Itoa(d.index)
154+
key := getPlaceHolderKey(d.index)
155155
d.paramMap[key] = p
156156
d.keys = append(d.keys, key)
157157
return key
@@ -252,7 +252,7 @@ func (d *PostgresDynamic) getParam() []interface{} {
252252

253253
func (d *PostgresDynamic) Param(p interface{}) string {
254254
d.index++
255-
key := argPlaceHolder + strconv.Itoa(d.index)
255+
key := getPlaceHolderKey(d.index)
256256
d.paramMap[key] = p
257257
d.keys = append(d.keys, key)
258258
return key
@@ -338,3 +338,7 @@ func IsTrue(i interface{}) bool {
338338
}
339339
return t
340340
}
341+
342+
func getPlaceHolderKey(index int) string {
343+
return fmt.Sprintf("%s%06d", argPlaceHolder, index)
344+
}

parsing/template/string_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55

66
package template
77

8-
import "testing"
8+
import (
9+
"testing"
10+
)
911

1012
func TestReplace(t *testing.T) {
1113
old := "ab"
1214
new := "cdab"
1315
s, i := replace("fhaksfjlabdasdabdasljfabda", old, new, -1)
1416
t.Log(s, " ", i)
1517
}
18+
19+
func TestFmt(t *testing.T) {
20+
s := getPlaceHolderKey(10)
21+
t.Log(s)
22+
}

0 commit comments

Comments
 (0)