Skip to content

Commit

Permalink
context for connection and transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
sijms committed Feb 25, 2022
1 parent 71a6f51 commit d6f0029
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
20 changes: 0 additions & 20 deletions examples/arrays/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,4 @@ func main() {
if err != nil {
fmt.Println("Can't call query2: ", err)
}
//
//err = query2(conn)
//if err != nil {
// fmt.Println("Can't call stored procedure 2: ", err)
//}
//err = query3(conn)
//if err != nil {
// fmt.Println("Can't call stored procedure 3: ", err)
// return
//}
//err = query4(conn)
//if err != nil {
// fmt.Println("Can't call stored procedure 4: ", err)
// return
//}
//err = query5(conn)
//if err != nil {
// fmt.Println("Can't call stored procedure 5: ", err)
// return
//}
}
21 changes: 18 additions & 3 deletions v2/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (connector *OracleConnector) Connect(ctx context.Context) (driver.Conn, err
if err != nil {
return nil, err
}
err = conn.Open(ctx)
err = conn.OpenWithContext(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func (drv *OracleDriver) Open(name string) (driver.Conn, error) {
//drv.UserId = conn.connOption.UserID
//drv.DBName = conn.connOption.DBName
//drv.m.Unlock()
err = conn.Open(context.Background())
err = conn.Open()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -335,7 +335,12 @@ func (conn *Connection) Ping(ctx context.Context) error {
//}

// Open open the connection = bring it online
func (conn *Connection) Open(ctx context.Context) error {
func (conn *Connection) Open() error {
return conn.OpenWithContext(context.Background())
}

// OpenWithContext open the connection with timeout context
func (conn *Connection) OpenWithContext(ctx context.Context) error {
tracer := conn.connOption.Tracer
switch conn.conStr.DBAPrivilege {
case SYSDBA:
Expand Down Expand Up @@ -1073,15 +1078,25 @@ func (conn *Connection) ExecContext(ctx context.Context, query string, args []dr
conn.connOption.Tracer.Print("Execute With Context")
stmt := NewStmt(query, conn)
valueArgs := make([]driver.Value, len(args))
for x := 0; x < len(valueArgs); x++ {
valueArgs[x] = args[x].Value
}
conn.session.StartContext(ctx)
defer conn.session.EndContext()
return stmt.Exec(valueArgs)
}

func (conn *Connection) CheckNamedValue(named *driver.NamedValue) error {
return nil
}

func (conn *Connection) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
conn.connOption.Tracer.Print("Query With Context")
stmt := NewStmt(query, conn)
valueArgs := make([]driver.Value, len(args))
for x := 0; x < len(valueArgs); x++ {
valueArgs[x] = args[x].Value
}
conn.session.StartContext(ctx)
defer conn.session.EndContext()
return stmt.Query(valueArgs)
Expand Down

0 comments on commit d6f0029

Please sign in to comment.