fix: begin transaction fail, rollback panic (#6365)
This commit is contained in:
		
							parent
							
								
									26663ab9bf
								
							
						
					
					
						commit
						740f2be453
					
				| @ -3,6 +3,7 @@ package gorm | |||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"database/sql" | 	"database/sql" | ||||||
|  | 	"reflect" | ||||||
| 	"sync" | 	"sync" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| @ -163,14 +164,14 @@ type PreparedStmtTX struct { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (tx *PreparedStmtTX) Commit() error { | func (tx *PreparedStmtTX) Commit() error { | ||||||
| 	if tx.Tx != nil { | 	if tx.Tx != nil && !reflect.ValueOf(tx.Tx).IsNil() { | ||||||
| 		return tx.Tx.Commit() | 		return tx.Tx.Commit() | ||||||
| 	} | 	} | ||||||
| 	return ErrInvalidTransaction | 	return ErrInvalidTransaction | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (tx *PreparedStmtTX) Rollback() error { | func (tx *PreparedStmtTX) Rollback() error { | ||||||
| 	if tx.Tx != nil { | 	if tx.Tx != nil && !reflect.ValueOf(tx.Tx).IsNil() { | ||||||
| 		return tx.Tx.Rollback() | 		return tx.Tx.Rollback() | ||||||
| 	} | 	} | ||||||
| 	return ErrInvalidTransaction | 	return ErrInvalidTransaction | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 东方上人
						东方上人