package pq

import (
	
	
	
	
	
	
	
)
Implement the "QueryerContext" interface
func ( *conn) ( context.Context,  string,  []driver.NamedValue) (driver.Rows, error) {
	 := make([]driver.Value, len())
	for ,  := range  {
		[] = .Value
	}
	 := .watchCancel()
	,  := .query(, )
	if  != nil {
		if  != nil {
			()
		}
		return nil, 
	}
	.finish = 
	return , nil
}
Implement the "ExecerContext" interface
func ( *conn) ( context.Context,  string,  []driver.NamedValue) (driver.Result, error) {
	 := make([]driver.Value, len())
	for ,  := range  {
		[] = .Value
	}

	if  := .watchCancel();  != nil {
		defer ()
	}

	return .Exec(, )
}
Implement the "ConnBeginTx" interface
func ( *conn) ( context.Context,  driver.TxOptions) (driver.Tx, error) {
	var  string

	switch sql.IsolationLevel(.Isolation) {
Don't touch mode: use the server's default
	case sql.LevelReadUncommitted:
		 = " ISOLATION LEVEL READ UNCOMMITTED"
	case sql.LevelReadCommitted:
		 = " ISOLATION LEVEL READ COMMITTED"
	case sql.LevelRepeatableRead:
		 = " ISOLATION LEVEL REPEATABLE READ"
	case sql.LevelSerializable:
		 = " ISOLATION LEVEL SERIALIZABLE"
	default:
		return nil, fmt.Errorf("pq: isolation level not supported: %d", .Isolation)
	}

	if .ReadOnly {
		 += " READ ONLY"
	} else {
		 += " READ WRITE"
	}

	,  := .begin()
	if  != nil {
		return nil, 
	}
	.txnFinish = .watchCancel()
	return , nil
}

func ( *conn) ( context.Context) error {
	if  := .watchCancel();  != nil {
		defer ()
	}
	,  := .simpleQuery(";")
	if  != nil {
		return driver.ErrBadConn // https://golang.org/pkg/database/sql/driver/#Pinger
	}
	.Close()
	return nil
}

func ( *conn) ( context.Context) func() {
	if  := .Done();  != nil {
		 := make(chan struct{})
		go func() {
			select {
At this point the function level context is canceled, so it must not be used for the additional network request to cancel the query. Create a new context to pass into the dial.
				,  := context.WithTimeout(context.Background(), time.Second*10)
				defer ()

				_ = .cancel()
				 <- struct{}{}
			case <-:
			}
		}()
		return func() {
			select {
			case <-:
			case  <- struct{}{}:
			}
		}
	}
	return nil
}

func ( *conn) ( context.Context) error {
	,  := dial(, .dialer, .opts)
	if  != nil {
		return 
	}
	defer .Close()

	{
		 := conn{
			c: ,
		}
		 = .ssl(.opts)
		if  != nil {
			return 
		}

		 := .writeBuf(0)
		.int32(80877102) // cancel request code
		.int32(.processID)
		.int32(.secretKey)

		if  := .sendStartupPacket();  != nil {
			return 
		}
	}
Read until EOF to ensure that the server received the cancel.
	{
		,  := io.Copy(ioutil.Discard, )
		return 
	}