-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstmt_in.go
More file actions
53 lines (51 loc) · 1.33 KB
/
stmt_in.go
File metadata and controls
53 lines (51 loc) · 1.33 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package qsql
import (
"fmt"
)
func stmtIn(paramIdx, paramsLen int, driverNames ...string) string {
driverName := ""
if len(driverNames) > 0 {
driverName = driverNames[0]
}
drvName := getDrvName(nil, driverName)
switch drvName {
case DRV_NAME_ORACLE, _DRV_NAME_OCI8:
result := []byte{}
for i := 0; i < paramsLen; i++ {
result = append(result, []byte(fmt.Sprintf(":%d,", paramIdx+i))...)
}
if len(result) > 0 {
return string(result[:len(result)-1]) // remove the last ','
}
return string(result)
case DRV_NAME_POSTGRES:
result := []byte{}
for i := 0; i < paramsLen; i++ {
result = append(result, []byte(fmt.Sprintf("$%d,", paramIdx+i))...)
}
if len(result) > 0 {
return string(result[:len(result)-1]) // remove the last ','
}
return string(result)
case DRV_NAME_SQLSERVER, _DRV_NAME_MSSQL:
result := []byte{}
for i := 0; i < paramsLen; i++ {
result = append(result, []byte(fmt.Sprintf("@p%d,", paramIdx+i))...)
}
if len(result) > 0 {
return string(result[:len(result)-1]) // remove the last ','
}
return string(result)
default:
resultLen := paramsLen * 2
result := make([]byte, resultLen)
for i := 0; i < resultLen; i += 2 {
result[i] = '?'
result[i+1] = ','
}
if len(result) > 0 {
return string(result[:len(result)-1]) // remove the last ','
}
return string(result)
}
}