This repository was archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatement.go
More file actions
84 lines (72 loc) · 2.35 KB
/
statement.go
File metadata and controls
84 lines (72 loc) · 2.35 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package sqlp
import (
goSql "database/sql"
"errors"
)
// @author valor.
var errNoRawSqlHandler = errors.New("raw sql handler is nil")
type fakeStmt string
func (f fakeStmt) queryAtDB(dbSession *DBSession, args ...interface{}) (*goSql.Rows, error) {
if dbSession.disablePreparedStmtAtDBSession {
return f.queryRawAtDB(dbSession, args...)
}
return dbSession.database.Query(string(f), args...)
}
func (f fakeStmt) queryRawAtDB(dbSession *DBSession, args ...interface{}) (*goSql.Rows, error) {
if dbSession.rawSqlHandler == nil {
return nil, errNoRawSqlHandler
}
rawSql, err := dbSession.rawSqlHandler.ToRawSql(string(f), args...)
if err != nil {
return nil, err
}
return dbSession.database.Query(rawSql)
}
func (f fakeStmt) queryAtTx(txSession *TxSession, args ...interface{}) (*goSql.Rows, error) {
if txSession.db.disablePreparedStmtAtTxSession {
return f.queryRawAtTx(txSession, args...)
}
return txSession.tx.Query(string(f), args...)
}
func (f fakeStmt) queryRawAtTx(txSession *TxSession, args ...interface{}) (*goSql.Rows, error) {
if txSession.db.rawSqlHandler == nil {
return nil, errNoRawSqlHandler
}
rawSql, err := txSession.db.rawSqlHandler.ToRawSql(string(f), args...)
if err != nil {
return nil, err
}
return txSession.tx.Query(rawSql)
}
func (f fakeStmt) execAtDB(dbSession *DBSession, args ...interface{}) (goSql.Result, error) {
if dbSession.disablePreparedStmtAtDBSession {
return f.execRawAtDB(dbSession, args...)
}
return dbSession.database.Exec(string(f), args...)
}
func (f fakeStmt) execRawAtDB(dbSession *DBSession, args ...interface{}) (goSql.Result, error) {
if dbSession.rawSqlHandler == nil {
return nil, errNoRawSqlHandler
}
rawSql, err := dbSession.rawSqlHandler.ToRawSql(string(f), args...)
if err != nil {
return nil, err
}
return dbSession.database.Exec(rawSql)
}
func (f fakeStmt) execAtTx(txSession *TxSession, args ...interface{}) (goSql.Result, error) {
if txSession.db.disablePreparedStmtAtTxSession {
return f.execRawAtTx(txSession, args...)
}
return txSession.tx.Exec(string(f), args...)
}
func (f fakeStmt) execRawAtTx(txSession *TxSession, args ...interface{}) (goSql.Result, error) {
if txSession.db.rawSqlHandler == nil {
return nil, errNoRawSqlHandler
}
rawSql, err := txSession.db.rawSqlHandler.ToRawSql(string(f), args...)
if err != nil {
return nil, err
}
return txSession.tx.Exec(rawSql)
}