(ctx context.Context, conn ConnPool, isTransaction bool, query string)
| 64 | } |
| 65 | |
| 66 | func (db *PreparedStmtDB) prepare(ctx context.Context, conn ConnPool, isTransaction bool, query string) (_ *stmt_store.Stmt, err error) { |
| 67 | db.Mux.RLock() |
| 68 | if db.Stmts != nil { |
| 69 | if stmt, ok := db.Stmts.Get(query); ok && (!stmt.Transaction || isTransaction) { |
| 70 | db.Mux.RUnlock() |
| 71 | return stmt, stmt.Error() |
| 72 | } |
| 73 | } |
| 74 | db.Mux.RUnlock() |
| 75 | |
| 76 | // retry |
| 77 | db.Mux.Lock() |
| 78 | if db.Stmts != nil { |
| 79 | if stmt, ok := db.Stmts.Get(query); ok && (!stmt.Transaction || isTransaction) { |
| 80 | db.Mux.Unlock() |
| 81 | return stmt, stmt.Error() |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return db.Stmts.New(ctx, query, isTransaction, conn, db.Mux) |
| 86 | } |
| 87 | |
| 88 | func (db *PreparedStmtDB) BeginTx(ctx context.Context, opt *sql.TxOptions) (ConnPool, error) { |
| 89 | if beginner, ok := db.ConnPool.(TxBeginner); ok { |
no test coverage detected