fix stmtcache invalidation
This patch fixes jackc/pgx#841. The meat of the fix lives in [a PR to the pgconn repo][1]. This change just checks for errors after executing a prepared statement and informs the underlying stmtcache about them so that it can properly clean up. We don't try to get fancy with retries or anything like that, just return the error and allow the application to handle it. I had to make [some][1] [changes][2] to to the jackc/pgconn package as well as this package. Fixes #841 [1]: https://github.com/jackc/pgconn/pull/56 [2]: https://github.com/jackc/pgconn/pull/55
This commit is contained in:
@@ -106,6 +106,7 @@ type connRows struct {
|
||||
sql string
|
||||
args []interface{}
|
||||
closed bool
|
||||
conn *Conn
|
||||
|
||||
resultReader *pgconn.ResultReader
|
||||
multiResultReader *pgconn.MultiResultReader
|
||||
@@ -145,8 +146,13 @@ func (rows *connRows) Close() {
|
||||
endTime := time.Now()
|
||||
rows.logger.log(rows.ctx, LogLevelInfo, "Query", map[string]interface{}{"sql": rows.sql, "args": logQueryArgs(rows.args), "time": endTime.Sub(rows.startTime), "rowCount": rows.rowCount})
|
||||
}
|
||||
} else if rows.logger.shouldLog(LogLevelError) {
|
||||
rows.logger.log(rows.ctx, LogLevelError, "Query", map[string]interface{}{"err": rows.err, "sql": rows.sql, "args": logQueryArgs(rows.args)})
|
||||
} else {
|
||||
if rows.logger.shouldLog(LogLevelError) {
|
||||
rows.logger.log(rows.ctx, LogLevelError, "Query", map[string]interface{}{"err": rows.err, "sql": rows.sql, "args": logQueryArgs(rows.args)})
|
||||
}
|
||||
if rows.err != nil {
|
||||
rows.conn.stmtcache.StatementErrored(rows.sql, rows.err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user