Skip to content

Commit

Permalink
fix: max_prepared_stmt
Browse files Browse the repository at this point in the history
  • Loading branch information
derek committed Mar 17, 2020
1 parent f98cdc5 commit 221afc1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions LocalSession.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,11 @@ func (it *LocalSession) QueryPrepare(sqlPrepare string, args ...interface{}) ([]
}

var rows *sql.Rows
var stmt *sql.Stmt
var err error
var t, _ = it.txStack.Last()
if t != nil {
stmt, err := t.Prepare(sqlPrepare)
stmt, err = t.Prepare(sqlPrepare)
err = it.dbErrorPack(err)
if err != nil {
return nil, err
Expand All @@ -363,7 +364,7 @@ func (it *LocalSession) QueryPrepare(sqlPrepare string, args ...interface{}) ([]
return nil, err
}
} else {
stmt, err := it.db.Prepare(sqlPrepare)
stmt, err = it.db.Prepare(sqlPrepare)
err = it.dbErrorPack(err)
if err != nil {
return nil, err
Expand All @@ -375,6 +376,9 @@ func (it *LocalSession) QueryPrepare(sqlPrepare string, args ...interface{}) ([]
return nil, err
}
}
if stmt != nil {
defer stmt.Close()
}
if rows != nil {
defer rows.Close()
}
Expand All @@ -395,10 +399,11 @@ func (it *LocalSession) ExecPrepare(sqlPrepare string, args ...interface{}) (*Re
}

var result sql.Result
var stmt *sql.Stmt
var err error
var t, _ = it.txStack.Last()
if t != nil {
stmt, err := t.Prepare(sqlPrepare)
stmt, err = t.Prepare(sqlPrepare)
err = it.dbErrorPack(err)
if err != nil {
return nil, err
Expand All @@ -409,7 +414,7 @@ func (it *LocalSession) ExecPrepare(sqlPrepare string, args ...interface{}) (*Re
return nil, err
}
} else {
stmt, err := it.db.Prepare(sqlPrepare)
stmt, err = it.db.Prepare(sqlPrepare)
err = it.dbErrorPack(err)
if err != nil {
return nil, err
Expand All @@ -420,6 +425,9 @@ func (it *LocalSession) ExecPrepare(sqlPrepare string, args ...interface{}) (*Re
return nil, err
}
}
if stmt != nil {
defer stmt.Close()
}
if err != nil {
return nil, err
} else {
Expand Down

0 comments on commit 221afc1

Please sign in to comment.