mirror of https://github.com/go-gorm/gorm.git
DryRun for RowQuery, Exec, close #3106
This commit is contained in:
parent
90a40361ed
commit
89ea62077d
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func RawExec(db *gorm.DB) {
|
func RawExec(db *gorm.DB) {
|
||||||
if db.Error == nil {
|
if db.Error == nil && !db.DryRun {
|
||||||
result, err := db.Statement.ConnPool.ExecContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...)
|
result, err := db.Statement.ConnPool.ExecContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
db.AddError(err)
|
db.AddError(err)
|
||||||
|
|
|
@ -10,10 +10,12 @@ func RowQuery(db *gorm.DB) {
|
||||||
BuildQuerySQL(db)
|
BuildQuerySQL(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := db.Get("rows"); ok {
|
if !db.DryRun {
|
||||||
db.Statement.Dest, db.Error = db.Statement.ConnPool.QueryContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...)
|
if _, ok := db.Get("rows"); ok {
|
||||||
} else {
|
db.Statement.Dest, db.Error = db.Statement.ConnPool.QueryContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...)
|
||||||
db.Statement.Dest = db.Statement.ConnPool.QueryRowContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...)
|
} else {
|
||||||
|
db.Statement.Dest = db.Statement.ConnPool.QueryRowContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue