File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,11 @@ func numInput(query string) int {
17
17
args = make (map [string ]struct {})
18
18
reader = bytes .NewReader ([]byte (query ))
19
19
quote , keyword bool
20
- like = newMatcher ("like" )
20
+ inBetween bool
21
+ like = newMatcher ("like" )
21
22
limit = newMatcher ("limit" )
23
+ between = newMatcher ("between" )
24
+ and = newMatcher ("and" )
22
25
)
23
26
for {
24
27
if char , _ , err := reader .ReadRune (); err == nil {
@@ -50,6 +53,12 @@ func numInput(query string) int {
50
53
default :
51
54
if limit .matchRune (char ) || like .matchRune (char ) {
52
55
keyword = true
56
+ } else if between .matchRune (char ) {
57
+ keyword = true
58
+ inBetween = true
59
+ } else if inBetween && and .matchRune (char ) {
60
+ keyword = true
61
+ inBetween = false
53
62
} else {
54
63
keyword = keyword && (char == ' ' || char == '\t' || char == '\n' )
55
64
}
Original file line number Diff line number Diff line change @@ -27,9 +27,13 @@ func Test_NumInput(t *testing.T) {
27
27
?
28
28
)
29
29
` : 3 ,
30
- "SELECT * from EXAMPLE LIMIT ?" : 1 ,
31
- "SELECT * from EXAMPLE LIMIT ?, ?" : 2 ,
32
- "SELECT * from EXAMPLE WHERE os_id like ?" : 1 ,
30
+ "SELECT * from EXAMPLE LIMIT ?" : 1 ,
31
+ "SELECT * from EXAMPLE LIMIT ?, ?" : 2 ,
32
+ "SELECT * from EXAMPLE WHERE os_id like ?" : 1 ,
33
+ "SELECT * FROM example WHERE a BETWEEN ? AND ?" : 2 ,
34
+ "SELECT * FROM example WHERE a BETWEEN ? AND ? AND b = ?" : 3 ,
35
+ "SELECT * FROM example WHERE a = ? AND b BETWEEN ? AND ?" : 3 ,
36
+ "SELECT * FROM example WHERE a BETWEEN ? AND ? AND b BETWEEN ? AND ?" : 4 ,
33
37
} {
34
38
assert .Equal (t , num , numInput (query ), query )
35
39
}
You can’t perform that action at this time.
0 commit comments