-
Notifications
You must be signed in to change notification settings - Fork 1
/
util_sql_test.go
33 lines (25 loc) · 890 Bytes
/
util_sql_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package taos
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParamsCount(t *testing.T) {
sqlStr := "select * from tb1"
count := paramsCount(sqlStr)
assert.Equal(t, 0, count, "count should be equal 0.")
sqlStr = "select * from tb1 where a = ?"
count = paramsCount(sqlStr)
assert.Equal(t, 1, count, "count should be equal 1.")
sqlStr = `select "xx?xx" from tb1`
count = paramsCount(sqlStr)
assert.Equal(t, 0, count, "count should be equal 0.")
sqlStr = `select "xx?xx" from tb1 where a = ?`
count = paramsCount(sqlStr)
assert.Equal(t, 1, count, "count should be equal 1.")
sqlStr = `select 'xx?xx' from tb1 where a = ?`
count = paramsCount(sqlStr)
assert.Equal(t, 1, count, "count should be equal 1.")
sqlStr = `select 'xx?xx' aa, "\"???" from tb1 where a = ?`
count = paramsCount(sqlStr)
assert.Equal(t, 1, count, "count should be equal 1.")
}