1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 17:40:55 +00:00
This commit is contained in:
BaoyangChai 2019-06-09 01:19:17 +08:00
parent cc0eacbe02
commit 873f62edff

View File

@ -116,6 +116,7 @@ func (d *DB) getStmt(query string) (*sql.Stmt, error) {
d.RUnlock() d.RUnlock()
return stmt, nil return stmt, nil
} }
d.RUnlock()
stmt, err := d.Prepare(query) stmt, err := d.Prepare(query)
if err != nil { if err != nil {
@ -140,7 +141,7 @@ func (d *DB) Exec(query string, args ...interface{}) (sql.Result, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return stmt.Exec(args) return stmt.Exec(args...)
} }
func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) { func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
@ -148,7 +149,7 @@ func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{})
if err != nil { if err != nil {
return nil, err return nil, err
} }
return stmt.ExecContext(ctx, args) return stmt.ExecContext(ctx, args...)
} }
func (d *DB) Query(query string, args ...interface{}) (*sql.Rows, error) { func (d *DB) Query(query string, args ...interface{}) (*sql.Rows, error) {
@ -156,7 +157,7 @@ func (d *DB) Query(query string, args ...interface{}) (*sql.Rows, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return stmt.Query(args) return stmt.Query(args...)
} }
func (d *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) { func (d *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
@ -164,7 +165,7 @@ func (d *DB) QueryContext(ctx context.Context, query string, args ...interface{}
if err != nil { if err != nil {
return nil, err return nil, err
} }
return stmt.QueryContext(ctx, args) return stmt.QueryContext(ctx, args...)
} }
func (d *DB) QueryRow(query string, args ...interface{}) *sql.Row { func (d *DB) QueryRow(query string, args ...interface{}) *sql.Row {
@ -173,7 +174,7 @@ func (d *DB) QueryRow(query string, args ...interface{}) *sql.Row {
panic(err) panic(err)
return nil return nil
} }
return stmt.QueryRow(args) return stmt.QueryRow(args...)
} }
@ -261,8 +262,9 @@ func addAliasWthDB(aliasName, driverName string, db *sql.DB) (*alias, error) {
al.Name = aliasName al.Name = aliasName
al.DriverName = driverName al.DriverName = driverName
al.DB = &DB{ al.DB = &DB{
DB: db, RWMutex: new(sync.RWMutex),
stmts: make(map[string]*sql.Stmt), DB: db,
stmts: make(map[string]*sql.Stmt),
} }
if dr, ok := drivers[driverName]; ok { if dr, ok := drivers[driverName]; ok {