BeginTx implements the driver.ConnBeginTx.BeginTx method.
(ctx context.Context, opts driver.TxOptions)
| 242 | |
| 243 | // BeginTx implements the driver.ConnBeginTx.BeginTx method. |
| 244 | func (c *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { |
| 245 | if atomic.LoadInt32(&c.closed) != 0 { |
| 246 | return nil, driver.ErrBadConn |
| 247 | } |
| 248 | |
| 249 | // start transaction |
| 250 | log.WithField("inTx", c.inTransaction).Debug("begin transaction") |
| 251 | |
| 252 | if c.inTransaction { |
| 253 | return nil, sql.ErrTxDone |
| 254 | } |
| 255 | |
| 256 | // TODO(xq262144): make use of the ctx argument |
| 257 | c.inTransaction = true |
| 258 | c.queries = c.queries[:0] |
| 259 | |
| 260 | return c, nil |
| 261 | } |
| 262 | |
| 263 | // PrepareContext implements the driver.ConnPrepareContext.ConnPrepareContext method. |
| 264 | func (c *conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { |