PrepareContext delegates down to the underlying PreparerContext and caches the result using the provided query as a key
(ctx context.Context, query string)
| 41 | // PrepareContext delegates down to the underlying PreparerContext and caches the result |
| 42 | // using the provided query as a key |
| 43 | func (sc *StmtCache) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) { |
| 44 | ctxPrep, ok := sc.prep.(PreparerContext) |
| 45 | if !ok { |
| 46 | return nil, NoContextSupport |
| 47 | } |
| 48 | sc.mu.Lock() |
| 49 | defer sc.mu.Unlock() |
| 50 | stmt, ok := sc.cache[query] |
| 51 | if ok { |
| 52 | return stmt, nil |
| 53 | } |
| 54 | stmt, err := ctxPrep.PrepareContext(ctx, query) |
| 55 | if err == nil { |
| 56 | sc.cache[query] = stmt |
| 57 | } |
| 58 | return stmt, err |
| 59 | } |
| 60 | |
| 61 | // ExecContext delegates down to the underlying PreparerContext using a prepared statement |
| 62 | func (sc *StmtCache) ExecContext(ctx context.Context, query string, args ...interface{}) (res sql.Result, err error) { |