fix arg conversion #61
10
filter.go
10
filter.go
@ -73,20 +73,14 @@ type SeqFilter struct {
|
||||
func convertQuestionMark(sql, prefix string, start int) string {
|
||||
var buf strings.Builder
|
||||
var beginSingleQuote bool
|
||||
var beginTransfer bool
|
||||
var index = start
|
||||
for _, c := range sql {
|
||||
if !beginSingleQuote && c == '?' {
|
||||
buf.WriteString(fmt.Sprintf("%s%v", prefix, index))
|
||||
index++
|
||||
} else {
|
||||
if c == '\\' {
|
||||
beginTransfer = true
|
||||
} else {
|
||||
if !beginTransfer && c == '\'' {
|
||||
beginSingleQuote = !beginSingleQuote
|
||||
}
|
||||
beginTransfer = false
|
||||
if c == '\'' {
|
||||
beginSingleQuote = !beginSingleQuote
|
||||
}
|
||||
buf.WriteRune(c)
|
||||
}
|
||||
|
@ -28,7 +28,10 @@ func TestSeqFilter(t *testing.T) {
|
||||
var kases = map[string]string{
|
||||
"SELECT * FROM TABLE1 WHERE a=? AND b=?": "SELECT * FROM TABLE1 WHERE a=$1 AND b=$2",
|
||||
"SELECT 1, '???', '2006-01-02 15:04:05' FROM TABLE1 WHERE a=? AND b=?": "SELECT 1, '???', '2006-01-02 15:04:05' FROM TABLE1 WHERE a=$1 AND b=$2",
|
||||
"select '1\\'?' from issue": "select '1\\'?' from issue",
|
||||
"select '1''?' from issue": "select '1''?' from issue",
|
||||
"select '1\\??' from issue": "select '1\\??' from issue",
|
||||
"select '1\\\\',? from issue": "select '1\\\\',$1 from issue",
|
||||
"select '1\\''?',? from issue": "select '1\\''?',$1 from issue",
|
||||
}
|
||||
for sql, result := range kases {
|
||||
assert.EqualValues(t, result, convertQuestionMark(sql, "$", 1))
|
||||
|
Reference in New Issue
Block a user