github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/sql_conn_prepare_context.go (about)

     1  // (c) Copyright IBM Corp. 2023
     2  
     3  package instana
     4  
     5  import (
     6  	"context"
     7  	"database/sql/driver"
     8  )
     9  
    10  type wConnPrepareContext struct {
    11  	driver.ConnPrepareContext
    12  	connDetails DbConnDetails
    13  	sensor      TracerLogger
    14  }
    15  
    16  func (conn *wConnPrepareContext) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
    17  	stmt, err := conn.ConnPrepareContext.PrepareContext(ctx, query)
    18  
    19  	if err != nil {
    20  		conn.connDetails.Error = err
    21  		return stmt, err
    22  	}
    23  
    24  	if stmtAlreadyWrapped(stmt) {
    25  		return stmt, nil
    26  	}
    27  
    28  	return wrapStmt(stmt, query, conn.connDetails, conn.sensor), nil
    29  }