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 22, 2024
1 parent 21974da commit 74e4761
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 45 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,19 @@ complete code for mapping refcursor to sql.Rows is found in [example/refcursor_t
db = sql.OpenDB(connector)
```

* ### using custom configuration for connection
* another way to set connection configuration instead of using connection string (DSN)
* use as follow
```golang
config, err := go_ora.ParseConfig(DSN)
// modify config structure
go_ora.RegisterConnConfig(config)
// now open db note empty DSN
db, err := sql.Open("oracle", "")

```


* ### Use Custom String encode/decode
* if your database charset is not supported you can create a custom object that implement IStringConverter interface and pass it to the driver as follows
```golang
Expand Down Expand Up @@ -641,6 +654,15 @@ complete code for mapping refcursor to sql.Rows is found in [example/refcursor_t
### releases
<details>

### version 2.8.12
* add 2 functions
* ParseConfig
* RegisterConnConfig
* fix issue related to LONG and JSON data types
* fix issue related to using returning clause with prepared statement will hang
* complete fix for data race


### version 2.8.8
* introduce new connection break using go-routines thanks to @rheilek
* return BLOB as longRAW and CLOB,NCLOB as LONG in lob prefetch mode so supported
Expand Down
11 changes: 6 additions & 5 deletions v2/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/sijms/go-ora/v2/configurations"
"github.com/sijms/go-ora/v2/network"
"reflect"
"regexp"
Expand Down Expand Up @@ -118,7 +119,7 @@ func (stmt *defaultStmt) basicWrite(exeOp int, parse, define bool) error {
// break;
//}
// we use here int.MaxValue
if stmt.connection.connOption.Lob == 0 {
if stmt.connection.connOption.Lob == configurations.INLINE {
session.PutInt(0x3FFFFFFF, 4, true, true)
//session.PutUint(0, 4, true, true)
} else {
Expand Down Expand Up @@ -185,7 +186,7 @@ func (stmt *defaultStmt) basicWrite(exeOp int, parse, define bool) error {
default:
//this.m_al8i4[1] = !fetch ? 0L : noOfRowsToFetch;
//al8i4[1] = stmt._noOfRowsToFetch
if stmt.connection.connOption.Lob == 0 {
if stmt.connection.connOption.Lob == configurations.INLINE {
if parse {
al8i4[1] = 0
} else {
Expand Down Expand Up @@ -242,7 +243,7 @@ func (stmt *defaultStmt) writeDefine() error {
if col.DataType == OCIBlobLocator || col.DataType == OCIClobLocator {
num = 0
//temp.ContFlag |= 0x2000000
if stmt.connection.connOption.Lob == 0 && !col.IsJson {
if stmt.connection.connOption.Lob == configurations.INLINE && !col.IsJson {
num = 0x3FFFFFFF
//col.MaxCharLen = 0
if col.DataType == OCIBlobLocator {
Expand Down Expand Up @@ -674,7 +675,7 @@ func (stmt *defaultStmt) _fetch(dataSet *DataSet) error {
if err != nil {
return err
}
//if stmt.connection.connOption.Lob > 0 {
//if stmt.connection.connOption.Lob > configurations.INLINE {
//
//}
return stmt.decodePrim(dataSet)
Expand Down Expand Up @@ -2373,7 +2374,7 @@ func (stmt *Stmt) _query() (*DataSet, error) {
// }
//}
// deal with lobs
if (stmt._hasBLOB || stmt._hasLONG) && stmt.connection.connOption.Lob == 0 {
if (stmt._hasBLOB || stmt._hasLONG) && stmt.connection.connOption.Lob == configurations.INLINE {
stmt.define = true
stmt.execute = false
stmt.parse = false
Expand Down
3 changes: 2 additions & 1 deletion v2/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/sijms/go-ora/v2/configurations"
"math"
"strings"
"time"
Expand Down Expand Up @@ -1409,7 +1410,7 @@ func (par *ParameterInfo) decodeParameterValue(connection *Connection, temporary

func (par *ParameterInfo) decodeColumnValue(connection *Connection, temporaryLobs *[][]byte, udt bool) error {
//var err error
if !udt && connection.connOption.Lob == 0 && (par.DataType == OCIBlobLocator || par.DataType == OCIClobLocator) {
if !udt && connection.connOption.Lob == configurations.INLINE && (par.DataType == OCIBlobLocator || par.DataType == OCIClobLocator) {
session := connection.session
maxSize, err := session.GetInt(4, true, true)
if err != nil {
Expand Down
42 changes: 3 additions & 39 deletions v2/ref_cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package go_ora

import (
"database/sql/driver"
"github.com/sijms/go-ora/v2/configurations"
)

type RefCursor struct {
Expand Down Expand Up @@ -92,7 +93,7 @@ func (cursor *RefCursor) load() error {
return nil
}
func (cursor *RefCursor) getExeOptions() int {
if cursor.connection.connOption.Lob == 0 {
if cursor.connection.connOption.Lob == configurations.INLINE {
return 0x8050
} else {
return 0x8040
Expand All @@ -110,13 +111,6 @@ func (cursor *RefCursor) _query() (*DataSet, error) {
if err != nil {
return nil, err
}
// read lobs
//if cursor.connection.connOption.Lob != 0 {
// err = cursor.readLobs(dataSet)
// if err != nil {
// return nil, err
// }
//}
err = cursor.decodePrim(dataSet)
if err != nil {
return nil, err
Expand All @@ -135,10 +129,6 @@ func (cursor *RefCursor) Query() (*DataSet, error) {
copy(cursor.scnForSnapshot, cursor.parent.scnForSnapshot)
}

//failOver := cursor.connection.connOption.Failover
//if failOver == 0 {
// failOver = 1
//}
dataSet, err := cursor._query()
if err != nil {
if isBadConn(err) {
Expand All @@ -149,36 +139,10 @@ func (cursor *RefCursor) Query() (*DataSet, error) {
return nil, err
}
return dataSet, nil
//var dataSet *DataSet
//var err error
//var reconnect bool
//for writeTrials := 0; writeTrials < failOver; writeTrials++ {
// reconnect, err = cursor.connection.reConnect(nil, writeTrials+1)
// if err != nil {
// tracer.Print("Error: ", err)
// if !reconnect {
// return nil, err
// }
// continue
// }
// // call query
// dataSet, err = cursor._query()
// if err == nil {
// break
// }
// reconnect, err = cursor.connection.reConnect(err, writeTrials+1)
// if err != nil {
// tracer.Print("Error: ", err)
// if !reconnect {
// return nil, err
// }
// }
//}
//return dataSet, nil
}
func (cursor *RefCursor) write() error {
var define = false
if cursor.connection.connOption.Lob == 0 {
if cursor.connection.connOption.Lob == configurations.INLINE {
define = true
}
err := cursor.basicWrite(cursor.getExeOptions(), false, define)
Expand Down

0 comments on commit 74e4761

Please sign in to comment.