mirror of https://github.com/go-gorm/gorm.git
Merge pull request #1412 from slayer/master
prevent nil pointer dereference on closed connection
This commit is contained in:
commit
b21c0bef9b
6
main.go
6
main.go
|
@ -454,7 +454,7 @@ func (s *DB) Debug() *DB {
|
||||||
// Begin begin a transaction
|
// Begin begin a transaction
|
||||||
func (s *DB) Begin() *DB {
|
func (s *DB) Begin() *DB {
|
||||||
c := s.clone()
|
c := s.clone()
|
||||||
if db, ok := c.db.(sqlDb); ok {
|
if db, ok := c.db.(sqlDb); ok && db != nil {
|
||||||
tx, err := db.Begin()
|
tx, err := db.Begin()
|
||||||
c.db = interface{}(tx).(SQLCommon)
|
c.db = interface{}(tx).(SQLCommon)
|
||||||
c.AddError(err)
|
c.AddError(err)
|
||||||
|
@ -466,7 +466,7 @@ func (s *DB) Begin() *DB {
|
||||||
|
|
||||||
// Commit commit a transaction
|
// Commit commit a transaction
|
||||||
func (s *DB) Commit() *DB {
|
func (s *DB) Commit() *DB {
|
||||||
if db, ok := s.db.(sqlTx); ok {
|
if db, ok := s.db.(sqlTx); ok && db != nil {
|
||||||
s.AddError(db.Commit())
|
s.AddError(db.Commit())
|
||||||
} else {
|
} else {
|
||||||
s.AddError(ErrInvalidTransaction)
|
s.AddError(ErrInvalidTransaction)
|
||||||
|
@ -476,7 +476,7 @@ func (s *DB) Commit() *DB {
|
||||||
|
|
||||||
// Rollback rollback a transaction
|
// Rollback rollback a transaction
|
||||||
func (s *DB) Rollback() *DB {
|
func (s *DB) Rollback() *DB {
|
||||||
if db, ok := s.db.(sqlTx); ok {
|
if db, ok := s.db.(sqlTx); ok && db != nil {
|
||||||
s.AddError(db.Rollback())
|
s.AddError(db.Rollback())
|
||||||
} else {
|
} else {
|
||||||
s.AddError(ErrInvalidTransaction)
|
s.AddError(ErrInvalidTransaction)
|
||||||
|
|
Loading…
Reference in New Issue