driver/driver_legacy.go
func (c *conn) PrepareContext(ctx context.Context, query string) (stmt driver.Stmt, err error) {
	if c.session.IsBad() {
		return nil, driver.ErrBadConn
	}

	done := make(chan struct{})
	go func() {
		prepareQuery, bulkInsert := checkBulkInsert(query)
		var (
			qt             p.QueryType
			id             uint64
			prmFieldSet    *p.ParameterFieldSet
			resultFieldSet *p.ResultFieldSet
		)
		qt, id, prmFieldSet, resultFieldSet, err = c.session.Prepare(prepareQuery)
		if err != nil {
			goto done
		}
		select {
		default:
		case <-ctx.Done():
			return
		}
		if bulkInsert {
			stmt, err = newBulkInsertStmt(c.session, prepareQuery, id, prmFieldSet)
		} else {
			stmt, err = newStmt(qt, c.session, prepareQuery, id, prmFieldSet, resultFieldSet)
		}
	done:
		close(done)
	}()

	select {
	case <-ctx.Done():
		return nil, ctx.Err()
	case <-done:
		return stmt, err
	}
}
func (c *conn) PrepareContext(ctx context.Context, query string) (stmt driver.Stmt, err error) {
	if c.session.IsBad() {
		return nil, driver.ErrBadConn
	}

	done := make(chan struct{})
	go func() {
		prepareQuery, bulkInsert := checkBulkInsert(query)
		var (
			qt             p.QueryType
			id             uint64
			prmFieldSet    *p.ParameterFieldSet
			resultFieldSet *p.ResultFieldSet
		)
		qt, id, prmFieldSet, resultFieldSet, err = c.session.Prepare(prepareQuery)
		if err != nil {
			goto done
		}
		select {
		default:
		case <-ctx.Done():
			return
		}
		if bulkInsert {
			stmt, err = newBulkInsertStmt(c.session, prepareQuery, id, prmFieldSet)
		} else {
			stmt, err = newStmt(qt, c.session, prepareQuery, id, prmFieldSet, resultFieldSet)
		}
	done:
		close(done)
	}()

	select {
	case <-ctx.Done():
		return nil, ctx.Err()
	case <-done:
		return stmt, err
	}
}
func ( c * conn ) PrepareContext ( ctx context . Context , query string ) ( stmt driver . Stmt , err error ) { if c . session . IsBad ( ) { return nil , driver . ErrBadConn } done := make ( chan struct { } ) go func ( ) { prepareQuery , bulkInsert := checkBulkInsert ( query ) var ( qt p . QueryType id uint64 prmFieldSet * p . ParameterFieldSet resultFieldSet * p . ResultFieldSet ) qt , id , prmFieldSet , resultFieldSet , err = c . session . Prepare ( prepareQuery ) if err != nil { goto done } select { default : case <- ctx . Done ( ) : return } if bulkInsert { stmt , err = newBulkInsertStmt ( c . session , prepareQuery , id , prmFieldSet ) } else { stmt , err = newStmt ( qt , c . session , prepareQuery , id , prmFieldSet , resultFieldSet ) } done : close ( done ) } ( ) select { case <- ctx . Done ( ) : return nil , ctx . Err ( ) case <- done : return stmt , err } }
// database connection
database connection