MCPcopy
hub / github.com/go-sql-driver/mysql / BeginTx

Method BeginTx

connection.go:610–632  ·  view source on GitHub ↗

BeginTx implements driver.ConnBeginTx interface

(ctx context.Context, opts driver.TxOptions)

Source from the content-addressed store, hash-verified

608
609// BeginTx implements driver.ConnBeginTx interface
610func (mc *mysqlConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
611 if mc.closed.Load() {
612 return nil, driver.ErrBadConn
613 }
614
615 if err := mc.watchCancel(ctx); err != nil {
616 return nil, err
617 }
618 defer mc.finish()
619
620 if sql.IsolationLevel(opts.Isolation) != sql.LevelDefault {
621 level, err := mapIsolationLevel(opts.Isolation)
622 if err != nil {
623 return nil, err
624 }
625 err = mc.exec("SET TRANSACTION ISOLATION LEVEL " + level)
626 if err != nil {
627 return nil, err
628 }
629 }
630
631 return mc.begin(opts.ReadOnly)
632}
633
634func (mc *mysqlConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
635 dargs, err := namedValueToValue(args)

Callers 3

TestContextCancelBeginFunction · 0.80
TestContextBeginReadOnlyFunction · 0.80

Calls 5

watchCancelMethod · 0.95
finishMethod · 0.95
execMethod · 0.95
beginMethod · 0.95
mapIsolationLevelFunction · 0.85

Tested by 3

TestContextCancelBeginFunction · 0.64
TestContextBeginReadOnlyFunction · 0.64