-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbindvar.go
59 lines (45 loc) · 1.5 KB
/
bindvar.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package sqlf
import (
"strconv"
)
// BindVar is used to take a format string and convert it into query
// string that a gorp.SqlExecutor or sql.Query can use. It is the
// same as BindVar from gorp.Dialect.
type BindVar interface {
// BindVar binds a variable string to use when forming SQL statements
// in many dbs it is "?", but Postgres appears to use $1
//
// i is a zero based index of the bind variable in this statement
//
BindVar(i int) string
}
// SimpleBindVar is the BindVar format used by SQLite, MySQL, SQLServer(mssql driver)
var SimpleBindVar = simpleBindVar{}
// SQLServerBindVar is the BindVar format used by SQL Server(sqlserver driver)
// https://github.com/denisenkom/go-mssqldb#parameters
// https://github.com/denisenkom/go-mssqldb#deprecated
var SQLServerBindVar = sqlServerBindVar{}
// PostgresBindVar is the BindVar format used by PostgreSQL
var PostgresBindVar = postgresBindVar{}
// OracleBindVar is the BindVar format used by Oracle Database
var OracleBindVar = oracleBindVar{}
type simpleBindVar struct{}
// Returns "?"
func (d simpleBindVar) BindVar(i int) string {
return "?"
}
type postgresBindVar struct{}
// Returns "$(i+1)"
func (d postgresBindVar) BindVar(i int) string {
return "$" + strconv.Itoa(i+1)
}
type sqlServerBindVar struct{}
// Returns "@p(i+1)"
func (d sqlServerBindVar) BindVar(i int) string {
return "@p" + strconv.Itoa(i+1)
}
type oracleBindVar struct{}
// Returns ":(i+1)"
func (d oracleBindVar) BindVar(i int) string {
return ":" + strconv.Itoa(i+1)
}