diff --git a/README.md b/README.md index b12dd0d..58d25a8 100644 --- a/README.md +++ b/README.md @@ -223,11 +223,11 @@ urlOptions := map[string]string { ``` * ### Define Lob Fetching Mode * this option define how lob data will be loaded - * default value is `pre` means lob data is send online with other values - * other value is `post` means lob data will be loaded after finish loading other value through a separate network call + * default value is `pre` or `inline` means lob data is send online with other values + * other value is `post` or `stream` means lob data will be loaded after finish loading other value through a separate network call ```golang urlOptions := map[string]string { - "lob fetch": "post", + "lob fetch": "stream", } ``` * ### Define Client Charset @@ -603,7 +603,7 @@ complete code for mapping refcursor to sql.Rows is found in [example/refcursor_t db = sql.OpenDB(connector) ``` -* ### using custom configuration for connection +* ### use custom configurations for connection * another way to set connection configuration instead of using connection string (DSN) * use as follow ```golang @@ -612,7 +612,6 @@ complete code for mapping refcursor to sql.Rows is found in [example/refcursor_t go_ora.RegisterConnConfig(config) // now open db note empty DSN db, err := sql.Open("oracle", "") - ``` @@ -660,6 +659,7 @@ complete code for mapping refcursor to sql.Rows is found in [example/refcursor_t * RegisterConnConfig * fix issue related to LONG and JSON data types * fix issue related to using returning clause with prepared statement will hang +* add `lob fetch=inline` which is equal to `lob fetch=pre` * complete fix for data race diff --git a/v2/advanced_nego/advanced_nego.go b/v2/advanced_nego/advanced_nego.go index e31ce37..2916906 100755 --- a/v2/advanced_nego/advanced_nego.go +++ b/v2/advanced_nego/advanced_nego.go @@ -31,12 +31,12 @@ type AdvNego struct { serviceList []AdvNegoService } -func NewAdvNego(session *network.Session, config *configurations.ConnectionConfig) (*AdvNego, error) { +func NewAdvNego(session *network.Session, tracer trace.Tracer, config *configurations.ConnectionConfig) (*AdvNego, error) { output := &AdvNego{ comm: &AdvancedNegoComm{session: session}, clientInfo: &config.ClientInfo, negoInfo: &config.AdvNegoServiceInfo, - tracer: config.Tracer, + tracer: tracer, serviceList: make([]AdvNegoService, 5), } var err error diff --git a/v2/command.go b/v2/command.go index 2be28b4..3ddadd3 100644 --- a/v2/command.go +++ b/v2/command.go @@ -620,10 +620,10 @@ func (stmt *defaultStmt) fetch(dataSet *DataSet) error { if maxRowSize > 0 { stmt._noOfRowsToFetch = (0x20000 / maxRowSize) + 1 } - stmt.connection.connOption.Tracer.Printf("Fetch Size Calculated: %d", stmt._noOfRowsToFetch) + stmt.connection.tracer.Printf("Fetch Size Calculated: %d", stmt._noOfRowsToFetch) } - tracer := stmt.connection.connOption.Tracer + tracer := stmt.connection.tracer var err = stmt._fetch(dataSet) if errors.Is(err, network.ErrConnReset) { err = stmt.connection.read() @@ -660,7 +660,7 @@ func (stmt *defaultStmt) _fetch(dataSet *DataSet) error { //defer func() { // err := stmt.freeTemporaryLobs() // if err != nil { - // stmt.connection.connOption.Tracer.Printf("Error free temporary lobs: %v", err) + // stmt.connection.tracer.Printf("Error free temporary lobs: %v", err) // } //}() session.ResetBuffer() @@ -697,7 +697,7 @@ func (stmt *defaultStmt) queryLobPrefetch(exeOp int, dataSet *DataSet) error { if maxRowSize > 0 { stmt._noOfRowsToFetch = (0x20000 / maxRowSize) + 1 } - stmt.connection.connOption.Tracer.Printf("Fetch Size Calculated: %d", stmt._noOfRowsToFetch) + stmt.connection.tracer.Printf("Fetch Size Calculated: %d", stmt._noOfRowsToFetch) } stmt.connection.session.ResetBuffer() err := stmt.basicWrite(exeOp, false, true) @@ -1092,8 +1092,8 @@ func (stmt *defaultStmt) read(dataSet *DataSet) (err error) { // return err // } //} - if stmt.connection.connOption.Tracer.IsOn() { - dataSet.Trace(stmt.connection.connOption.Tracer) + if stmt.connection.tracer.IsOn() { + dataSet.Trace(stmt.connection.tracer) } //return stmt.readLobs(dataSet) return nil @@ -1104,7 +1104,7 @@ func (stmt *defaultStmt) freeTemporaryLobs() error { if len(stmt.temporaryLobs) == 0 { return nil } - stmt.connection.connOption.Tracer.Printf("Free %d Temporary Lobs", len(stmt.temporaryLobs)) + stmt.connection.tracer.Printf("Free %d Temporary Lobs", len(stmt.temporaryLobs)) session := stmt.connection.session //defer func(input *[][]byte) { // *input = nil @@ -1248,7 +1248,7 @@ func (stmt *defaultStmt) Close() error { } err := stmt.freeTemporaryLobs() if err != nil { - stmt.connection.connOption.Tracer.Printf("Error free temporary lobs: %v", err) + stmt.connection.tracer.Printf("Error free temporary lobs: %v", err) } if stmt.cursorID != 0 { session := stmt.connection.session @@ -1270,7 +1270,7 @@ func (stmt *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (dr stmt.connection.setBad() return nil, driver.ErrBadConn } - tracer := stmt.connection.connOption.Tracer + tracer := stmt.connection.tracer tracer.Printf("Exec With Context:") stmt.connection.session.StartContext(ctx) defer stmt.connection.session.EndContext() @@ -1845,7 +1845,7 @@ func (stmt *Stmt) _exec(args []driver.NamedValue) (*QueryResult, error) { } if processedPars > 0 { stmt.bulkExec = false - stmt.connection.connOption.Tracer.Printf(" %d:\n%v", x, args[x]) + stmt.connection.tracer.Printf(" %d:\n%v", x, args[x]) parIndex += processedPars structPars = append(structPars, args[x].Value) continue @@ -1986,7 +1986,7 @@ func (stmt *Stmt) _exec(args []driver.NamedValue) (*QueryResult, error) { } stmt.setParam(parIndex, *par) parIndex++ - stmt.connection.connOption.Tracer.Printf(" %d:\n%v", x, args[x]) + stmt.connection.tracer.Printf(" %d:\n%v", x, args[x]) } if useNamedPars { err = stmt.useNamedParameters() @@ -2113,7 +2113,7 @@ func (stmt *Stmt) Exec(args []driver.Value) (driver.Result, error) { stmt.connection.setBad() return nil, driver.ErrBadConn } - tracer := stmt.connection.connOption.Tracer + tracer := stmt.connection.tracer tracer.Printf("Exec:\n%s", stmt.text) var result *QueryResult var err error @@ -2226,7 +2226,7 @@ func (stmt *Stmt) Query_(namedArgs []driver.NamedValue) (*DataSet, error) { stmt.connection.setBad() return nil, driver.ErrBadConn } - tracer := stmt.connection.connOption.Tracer + tracer := stmt.connection.tracer stmt._noOfRowsToFetch = stmt.connection.connOption.PrefetchRows stmt._hasMoreRows = true var useNamedPars = len(namedArgs) > 0 @@ -2319,7 +2319,7 @@ func (stmt *Stmt) QueryContext(ctx context.Context, namedArgs []driver.NamedValu stmt.connection.setBad() return nil, driver.ErrBadConn } - tracer := stmt.connection.connOption.Tracer + tracer := stmt.connection.tracer tracer.Print("Query With Context:", stmt.text) stmt.connection.session.StartContext(ctx) @@ -2346,7 +2346,7 @@ func (stmt *Stmt) _query() (*DataSet, error) { //defer func() { // err = stmt.freeTemporaryLobs() // if err != nil { - // stmt.connection.connOption.Tracer.Printf("Error free temporary lobs: %v", err) + // stmt.connection.tracer.Printf("Error free temporary lobs: %v", err) // } //}() @@ -2448,7 +2448,7 @@ func (stmt *Stmt) Query(args []driver.Value) (driver.Rows, error) { stmt.connection.setBad() return nil, driver.ErrBadConn } - tracer := stmt.connection.connOption.Tracer + tracer := stmt.connection.tracer tracer.Printf("Query:\n%s", stmt.text) var dataSet *DataSet var err error diff --git a/v2/configurations/connect_config.go b/v2/configurations/connect_config.go index 23e7b5d..8c108af 100644 --- a/v2/configurations/connect_config.go +++ b/v2/configurations/connect_config.go @@ -3,7 +3,6 @@ package configurations import ( "errors" "fmt" - "github.com/sijms/go-ora/v2/trace" "net" "net/url" "os" @@ -32,10 +31,11 @@ type ConnectionConfig struct { DatabaseInfo SessionInfo AdvNegoServiceInfo - Tracer trace.Tracer - TraceDir string - PrefetchRows int - Lob LobFetch + //Tracer trace.Tracer + TraceFilePath string + TraceDir string + PrefetchRows int + Lob LobFetch //Failover int //RetryTime int @@ -246,16 +246,17 @@ func ParseConfig(dsn string) (*ConnectionConfig, error) { } config.SessionInfo.Timeout = time.Second * time.Duration(to) case "TRACE FILE": - if len(val[0]) > 0 { - tf, err := os.Create(val[0]) - if err != nil { - //noinspection GoErrorStringFormat - return nil, fmt.Errorf("Can't open trace file: %w", err) - } - config.Tracer = trace.NewTraceWriter(tf) - } else { - config.Tracer = trace.NilTracer() - } + config.TraceFilePath = val[0] + //if len(val[0]) > 0 { + // tf, err := os.Create(val[0]) + // if err != nil { + // //noinspection GoErrorStringFormat + // return nil, fmt.Errorf("Can't open trace file: %w", err) + // } + // config.Tracer = trace.NewTraceWriter(tf) + //} else { + // config.Tracer = trace.NilTracer() + //} case "TRACE DIR": fallthrough case "TRACE FOLDER": diff --git a/v2/connection.go b/v2/connection.go index 05aff59..341776b 100755 --- a/v2/connection.go +++ b/v2/connection.go @@ -77,6 +77,7 @@ type Connection struct { LogonMode LogonMode autoCommit bool //conStr *ConnectionString + tracer trace.Tracer connOption *configurations.ConnectionConfig session *network.Session tcpNego *TCPNego @@ -260,13 +261,13 @@ func (conn *Connection) GetNLS() (*NLSData, error) { // Prepare take a query string and create a stmt object func (conn *Connection) Prepare(query string) (driver.Stmt, error) { - conn.connOption.Tracer.Print("Prepare\n", query) + conn.tracer.Print("Prepare\n", query) return NewStmt(query, conn), nil } // Ping test if connection is online func (conn *Connection) Ping(ctx context.Context) error { - conn.connOption.Tracer.Print("Ping") + conn.tracer.Print("Ping") conn.session.ResetBuffer() conn.session.StartContext(ctx) defer conn.session.EndContext() @@ -305,7 +306,7 @@ func (conn *Connection) getStrConv(charsetID int) (converters.IStringConverter, //} func (conn *Connection) Logoff() error { - conn.connOption.Tracer.Print("Logoff") + conn.tracer.Print("Logoff") session := conn.session session.ResetBuffer() //session.PutBytes(0x11, 0x87, 0, 0, 0, 0x2, 0x1, 0x11, 0x1, 0, 0, 0, 0x1, 0, 0, 0, 0, 0, 0x1, 0, 0, 0, 0, 0, @@ -358,7 +359,7 @@ func (conn *Connection) Open() error { } //func (conn *Connection) restore() error { -// tracer := conn.connOption.Tracer +// tracer := conn.tracer // failOver := conn.connOption.Failover // var err error // for trial := 0; trial < failOver; trial++ { @@ -382,12 +383,23 @@ func (conn *Connection) OpenWithContext(ctx context.Context) error { now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), now.Nanosecond()) if tr, err := os.Create(traceFileName); err == nil { - conn.connOption.Tracer = trace.NewTraceWriter(tr) + conn.tracer = trace.NewTraceWriter(tr) } } + } else { + if len(conn.connOption.TraceFilePath) > 0 { + tf, err := os.Create(conn.connOption.TraceFilePath) + if err != nil { + //noinspection GoErrorStringFormat + return fmt.Errorf("Can't open trace file: %w", err) + } + conn.tracer = trace.NewTraceWriter(tf) + } else { + conn.tracer = trace.NilTracer() + } } - tracer := conn.connOption.Tracer + tracer := conn.tracer switch conn.connOption.DBAPrivilege { case configurations.SYSDBA: conn.LogonMode |= SysDba @@ -397,7 +409,7 @@ func (conn *Connection) OpenWithContext(ctx context.Context) error { conn.LogonMode = 0 } conn.connOption.ResetServerIndex() - conn.session = network.NewSession(conn.connOption) + conn.session = network.NewSession(conn.connOption, conn.tracer) W := conn.connOption.Wallet if conn.connOption.SSL && W != nil { err := conn.session.LoadSSLData(W.Certificates, W.PrivateKeys, W.CertificateRequests) @@ -416,7 +428,7 @@ func (conn *Connection) OpenWithContext(ctx context.Context) error { // advanced negotiation if session.Context.ACFL0&1 != 0 && session.Context.ACFL0&4 == 0 && session.Context.ACFL1&8 == 0 { tracer.Print("Advance Negotiation") - ano, err := advanced_nego.NewAdvNego(session, conn.connOption) + ano, err := advanced_nego.NewAdvNego(session, conn.tracer, conn.connOption) if err != nil { return err } @@ -493,7 +505,7 @@ func (conn *Connection) getDBTimeZone() { // Begin a transaction func (conn *Connection) Begin() (driver.Tx, error) { - conn.connOption.Tracer.Print("Begin transaction") + conn.tracer.Print("Begin transaction") conn.autoCommit = false return &Transaction{conn: conn, ctx: context.Background()}, nil } @@ -505,7 +517,7 @@ func (conn *Connection) BeginTx(ctx context.Context, opts driver.TxOptions) (dri if opts.Isolation != 0 { return nil, errors.New("only support default value for isolation") } - conn.connOption.Tracer.Print("Begin transaction with context") + conn.tracer.Print("Begin transaction with context") conn.autoCommit = false return &Transaction{conn: conn, ctx: ctx}, nil } @@ -525,10 +537,11 @@ func NewConnection(databaseUrl string, config *configurations.ConnectionConfig) } //conStr, err := newConnectionStringFromUrl(databaseUrl) - + temp := new(configurations.ConnectionConfig) + *temp = *config return &Connection{ State: Closed, - connOption: config, + connOption: temp, cStrConv: converters.NewStringConverter(config.CharsetID), autoCommit: true, cusTyp: map[string]customType{}, @@ -545,7 +558,7 @@ func NewConnection(databaseUrl string, config *configurations.ConnectionConfig) // Close the connection by disconnect network session func (conn *Connection) Close() (err error) { - tracer := conn.connOption.Tracer + tracer := conn.tracer tracer.Print("Close") //var err error = nil if conn.session != nil { @@ -561,14 +574,14 @@ func (conn *Connection) Close() (err error) { conn.session = nil } conn.State = Closed - conn.connOption.Tracer.Print("Connection Closed") - _ = conn.connOption.Tracer.Close() + conn.tracer.Print("Connection Closed") + _ = conn.tracer.Close() return } // doAuth a login step that occur during open connection func (conn *Connection) doAuth() error { - conn.connOption.Tracer.Print("doAuth") + conn.tracer.Print("doAuth") if len(conn.connOption.UserID) > 0 && len(conn.connOption.Password) > 0 { conn.session.ResetBuffer() conn.session.PutBytes(3, 0x76, 0, 1) @@ -950,7 +963,7 @@ func (conn *Connection) BulkInsert(sqlText string, rowNum int, columns ...[]driv defer func() { _ = stmt.Close() }() - tracer := conn.connOption.Tracer + tracer := conn.tracer tracer.Printf("BulkInsert:\n%s", stmt.text) tracer.Printf("Row Num: %d", rowNum) tracer.Printf("Column Num: %d", len(columns)) @@ -1081,7 +1094,7 @@ func (conn *Connection) PrepareContext(ctx context.Context, query string) (drive if conn.State != Opened { return nil, driver.ErrBadConn } - conn.connOption.Tracer.Print("Prepare With Context\n", query) + conn.tracer.Print("Prepare With Context\n", query) conn.session.StartContext(ctx) defer conn.session.EndContext() return NewStmt(query, conn), nil @@ -1089,7 +1102,7 @@ func (conn *Connection) PrepareContext(ctx context.Context, query string) (drive func (conn *Connection) readMsg(msgCode uint8) error { session := conn.session - tracer := conn.connOption.Tracer + tracer := conn.tracer var err error switch msgCode { case 4: @@ -1240,7 +1253,7 @@ func (conn *Connection) ResetSession(_ context.Context) error { } func (conn *Connection) dataTypeNegotiation() error { - tracer := conn.connOption.Tracer + tracer := conn.tracer var err error tracer.Print("Data Type Negotiation") conn.dataNego = buildTypeNego(conn.tcpNego, conn.session) @@ -1273,7 +1286,7 @@ func (conn *Connection) dataTypeNegotiation() error { //this.m_marshallingEngine.m_bServerUsingBigSCN = this.m_serverCompileTimeCapabilities[7] >= (byte) 8; } func (conn *Connection) protocolNegotiation() error { - tracer := conn.connOption.Tracer + tracer := conn.tracer var err error tracer.Print("TCP Negotiation") conn.tcpNego, err = newTCPNego(conn.session) diff --git a/v2/driver.go b/v2/driver.go index cd13581..d524557 100644 --- a/v2/driver.go +++ b/v2/driver.go @@ -69,7 +69,8 @@ func (driver *OracleDriver) init(conn *Connection) error { driver.nStrConv = conn.nStrConv.Clone() } if driver.connOption == nil { - driver.connOption = conn.connOption + driver.connOption = new(configurations.ConnectionConfig) + *driver.connOption = *conn.connOption } driver.dataCollected = true } diff --git a/v2/lob.go b/v2/lob.go index 266db23..b4be864 100644 --- a/v2/lob.go +++ b/v2/lob.go @@ -74,7 +74,7 @@ func (lob *Lob) getSize() (size int64, err error) { lob.initialize() lob.sendSize = true session := lob.connection.session - lob.connection.connOption.Tracer.Print("Read Lob Size") + lob.connection.tracer.Print("Read Lob Size") session.ResetBuffer() lob.writeOp(1) err = session.Write() @@ -86,15 +86,15 @@ func (lob *Lob) getSize() (size int64, err error) { return } size = lob.size - lob.connection.connOption.Tracer.Print("Lob Size: ", size) + lob.connection.tracer.Print("Lob Size: ", size) return } func (lob *Lob) getDataWithOffsetSize(offset, count int64) (data []byte, err error) { if offset == 0 && count == 0 { - lob.connection.connOption.Tracer.Print("Read Lob Data:") + lob.connection.tracer.Print("Read Lob Data:") } else { - lob.connection.connOption.Tracer.Printf("Read Lob Data Position: %d, Count: %d\n", offset, count) + lob.connection.tracer.Printf("Read Lob Data Position: %d, Count: %d\n", offset, count) } lob.initialize() lob.size = count @@ -122,7 +122,7 @@ func (lob *Lob) getData() (data []byte, err error) { } func (lob *Lob) putData(data []byte) error { - lob.connection.connOption.Tracer.Printf("Put Lob Data: %d bytes", len(data)) + lob.connection.tracer.Printf("Put Lob Data: %d bytes", len(data)) lob.initialize() lob.size = int64(len(data)) lob.sendSize = true @@ -140,7 +140,7 @@ func (lob *Lob) putData(data []byte) error { func (lob *Lob) putString(data string) error { conn := lob.connection - conn.connOption.Tracer.Printf("Put Lob String: %d character", int64(len([]rune(data)))) + conn.tracer.Printf("Put Lob String: %d character", int64(len([]rune(data)))) lob.initialize() var strConv converters.IStringConverter if lob.variableWidthChar() { @@ -193,7 +193,7 @@ func (lob *Lob) freeTemporary() error { } func (lob *Lob) createTemporaryBLOB() error { - lob.connection.connOption.Tracer.Print("Create Temporary BLob:") + lob.connection.tracer.Print("Create Temporary BLob:") lob.sourceLocator = make([]byte, 0x28) lob.sourceLocator[1] = 0x54 lob.sourceLen = len(lob.sourceLocator) @@ -215,7 +215,7 @@ func (lob *Lob) createTemporaryBLOB() error { } func (lob *Lob) createTemporaryClob(charset, charsetForm int) error { - lob.connection.connOption.Tracer.Print("Create Temporary CLob") + lob.connection.tracer.Print("Create Temporary CLob") lob.sourceLocator = make([]byte, 0x28) lob.sourceLocator[1] = 0x54 lob.sourceLen = len(lob.sourceLocator) @@ -243,7 +243,7 @@ func (lob *Lob) createTemporaryClob(charset, charsetForm int) error { } func (lob *Lob) open(mode, opID int) error { - lob.connection.connOption.Tracer.Printf("Open Lob: Mode= %d Operation ID= %d", mode, opID) + lob.connection.tracer.Printf("Open Lob: Mode= %d Operation ID= %d", mode, opID) if lob.isTemporary() { if lob.sourceLocator[7]&8 == 8 { return errors.New("TTC Error") @@ -267,7 +267,7 @@ func (lob *Lob) open(mode, opID int) error { } func (lob *Lob) close(opID int) error { - lob.connection.connOption.Tracer.Print("Close Lob: ") + lob.connection.tracer.Print("Close Lob: ") //if lob.isTemporary() { // if lob.sourceLocator[7]&8 == 8 { // return errors.New("TTC Error") diff --git a/v2/network/data_packet.go b/v2/network/data_packet.go index f95dfa4..ad76dcd 100644 --- a/v2/network/data_packet.go +++ b/v2/network/data_packet.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "errors" + "github.com/sijms/go-ora/v2/trace" "sync" ) @@ -24,7 +25,7 @@ func (pck *DataPacket) bytes() []byte { return ret.Bytes() } -func newDataPacket(initialData []byte, sessionCtx *SessionContext, mu *sync.Mutex) (*DataPacket, error) { +func newDataPacket(initialData []byte, sessionCtx *SessionContext, tracer trace.Tracer, mu *sync.Mutex) (*DataPacket, error) { //var outputData []byte = initialData var err error mu.Lock() @@ -36,7 +37,6 @@ func newDataPacket(initialData []byte, sessionCtx *SessionContext, mu *sync.Mute if sessionCtx.AdvancedService.CryptAlgo != nil { //outputData = make([]byte, len(outputData)) //copy(outputData, outputData) - tracer := sessionCtx.connConfig.Tracer tracer.LogPacket("Write packet (Decrypted): ", initialData) initialData, err = sessionCtx.AdvancedService.CryptAlgo.Encrypt(initialData) if err != nil { @@ -61,7 +61,7 @@ func newDataPacket(initialData []byte, sessionCtx *SessionContext, mu *sync.Mute }, nil } -func newDataPacketFromData(packetData []byte, sessionCtx *SessionContext, mu *sync.Mutex) (*DataPacket, error) { +func newDataPacketFromData(packetData []byte, sessionCtx *SessionContext, tracer trace.Tracer, mu *sync.Mutex) (*DataPacket, error) { mu.Lock() defer mu.Unlock() if len(packetData) < 0xA || PacketType(packetData[4]) != DATA { @@ -92,7 +92,6 @@ func newDataPacketFromData(packetData []byte, sessionCtx *SessionContext, mu *sy if err != nil { return nil, err } - tracer := sessionCtx.connConfig.Tracer tracer.LogPacket("Read packet (Decrypted): ", pck.buffer) } if sessionCtx.AdvancedService.HashAlgo != nil { diff --git a/v2/network/session.go b/v2/network/session.go index ffc878d..67c29dc 100755 --- a/v2/network/session.go +++ b/v2/network/session.go @@ -85,7 +85,6 @@ func NewSessionWithInputBufferForDebug(input []byte) *Session { SessionDataUnitSize: 0xFFFF, TransportDataUnitSize: 0xFFFF, }, - Tracer: trace.NilTracer(), } return &Session{ //ctx: context.Background(), @@ -98,10 +97,10 @@ func NewSessionWithInputBufferForDebug(input []byte) *Session { Summary: nil, UseBigClrChunks: false, ClrChunkSize: 0x40, - tracer: options.Tracer, + tracer: trace.NilTracer(), } } -func NewSession(config *configurations.ConnectionConfig) *Session { +func NewSession(config *configurations.ConnectionConfig, tracer trace.Tracer) *Session { return &Session{ //ctx: context.Background(), conn: nil, @@ -112,7 +111,7 @@ func NewSession(config *configurations.ConnectionConfig) *Session { UseBigClrChunks: false, ClrChunkSize: 0x40, lastPacket: bytes.Buffer{}, - tracer: config.Tracer, + tracer: tracer, } } @@ -604,7 +603,7 @@ func (session *Session) Connect(ctx context.Context) error { } func (session *Session) WriteFinalPacket() error { - data, err := newDataPacket(nil, session.Context, &session.mu) + data, err := newDataPacket(nil, session.Context, session.tracer, &session.mu) if err != nil { return err } @@ -636,7 +635,7 @@ func (session *Session) Write() error { size := session.outBuffer.Len() if size == 0 { // send empty data packet - pck, err := newDataPacket(nil, session.Context, &session.mu) + pck, err := newDataPacket(nil, session.Context, session.tracer, &session.mu) if err != nil { return err } @@ -650,7 +649,7 @@ func (session *Session) Write() error { segment := make([]byte, segmentLen) for size > segmentLen { copy(segment, outputBytes[offset:offset+segmentLen]) - pck, err := newDataPacket(segment, session.Context, &session.mu) + pck, err := newDataPacket(segment, session.Context, session.tracer, &session.mu) if err != nil { return err } @@ -664,7 +663,7 @@ func (session *Session) Write() error { } } if size != 0 { - pck, err := newDataPacket(outputBytes[offset:], session.Context, &session.mu) + pck, err := newDataPacket(outputBytes[offset:], session.Context, session.tracer, &session.mu) if err != nil { return err } @@ -1075,7 +1074,7 @@ func (session *Session) readPacket() (PacketInterface, error) { if uint16(pck.length) <= pck.dataOffset { err = session.readPacketData() packetData = session.lastPacket.Bytes() - dataPck, err := newDataPacketFromData(packetData, session.Context, &session.mu) + dataPck, err := newDataPacketFromData(packetData, session.Context, session.tracer, &session.mu) if err != nil { return nil, err } @@ -1093,7 +1092,7 @@ func (session *Session) readPacket() (PacketInterface, error) { } return pck, nil case DATA: - dataPck, err := newDataPacketFromData(packetData, session.Context, &session.mu) + dataPck, err := newDataPacketFromData(packetData, session.Context, session.tracer, &session.mu) if dataPck != nil { if session.Context.connConfig.SSL && (dataPck.dataFlag&0x8000 > 0 || dataPck.flag&0x80 > 0) { session.negotiate() diff --git a/v2/ref_cursor.go b/v2/ref_cursor.go index 26a40cc..b255c1d 100644 --- a/v2/ref_cursor.go +++ b/v2/ref_cursor.go @@ -121,7 +121,7 @@ func (cursor *RefCursor) Query() (*DataSet, error) { if cursor.connection.State != Opened { return nil, driver.ErrBadConn } - tracer := cursor.connection.connOption.Tracer + tracer := cursor.connection.tracer tracer.Printf("Query RefCursor: %d", cursor.cursorID) cursor._noOfRowsToFetch = cursor.connection.connOption.PrefetchRows cursor._hasMoreRows = true diff --git a/v2/simple_object.go b/v2/simple_object.go index f4a9559..e65cbc1 100644 --- a/v2/simple_object.go +++ b/v2/simple_object.go @@ -52,7 +52,7 @@ func (obj *simpleObject) read() error { func (obj *simpleObject) exec() error { conn := obj.connection - tracer := conn.connOption.Tracer + tracer := conn.tracer obj.write() if obj.err != nil { return obj.err