Skip to content

Commit

Permalink
add ParseConfig and RegisterConfig functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sijms committed Apr 23, 2024
1 parent 74e4761 commit f442ab2
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 86 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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", "")

```


Expand Down Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions v2/advanced_nego/advanced_nego.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions v2/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
// }
//}()

Expand Down Expand Up @@ -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
Expand Down
31 changes: 16 additions & 15 deletions v2/configurations/connect_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package configurations
import (
"errors"
"fmt"
"github.com/sijms/go-ora/v2/trace"
"net"
"net/url"
"os"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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":
Expand Down
Loading

0 comments on commit f442ab2

Please sign in to comment.