go-ora
go-ora copied to clipboard
go_ora.AddSessionParam(db, k, v) put values to global driver hashmap
If the go program connect to more than one database/schema and using go_ora.AddSessionParam
the last call to AddSessionParam
overwrites other values.
for example:
-
db1 := db.Open("db1.example.com"
) -
go_ora.AddSessionParam(db1, "CURRENT_SCHEMA", "WS")
-
db2 := db.Open("db2.example.com")
-
AddSessionParam(db2, "CURRENT_SCHEMA", "TEST")
-
db1.Exec(..)
-> ORA-01435: user does not exist - because TEST was used atinitConnection
The cause of this is the global hashmap in OracleDriver
used in AddSessionParam
.
func AddSessionParam(db *sql.DB, key, value string) error {
...
if drv, ok := db.Driver().(*OracleDriver); ok {
drv.mu.Lock()
defer drv.mu.Unlock()
drv.sessionParam[key] = value # issue
...
func (driver *OracleDriver) init(conn *Connection) error {
...
for key, value := range driver.sessionParam {
_, err = conn.Exec(fmt.Sprintf("alter session set %s=%s", key, value))
...
Because of implementing database/sql
maybe the ConnectString might be the right place to do something like this. If you agree i can create a pull request. Otherwise AddSessionParam
should be removed from api and every developer must implement his own initialization. Or do you see another approach?