sijms / go-ora

Pure go oracle client
MIT License
767 stars 168 forks source link

go_ora.AddSessionParam(db, k, v) put values to global driver hashmap #536

Closed rheilek closed 3 months ago

rheilek commented 3 months ago

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:

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?

sijms commented 3 months ago

hi @rheilek sorry for late the issue will not be restricted to session parameters also you will face same issue with user defined type (UDT) I use the driver to pass data between connections in connection pool

so if you want to use multiple database you should use separate driver for each one, I explain this here

rheilek commented 3 months ago

thanks, I hadn't seen that, sorry