Closed CharliePlate closed 11 months ago
code:
package main
import (
"database/sql"
"fmt"
go_ora "github.com/sijms/go-ora/v2"
"os"
"time"
)
func exec(db *sql.DB) error {
t := time.Now()
sqlText := `BEGIN
SELECT 'a', 'b' into :aVar, :bVar FROM DUAL;
END;`
var aVar, bVar string
_, err := db.Exec(sqlText, sql.Named("bVar", go_ora.Out{Dest: &bVar, Size: 5}),
sql.Named("aVar", go_ora.Out{Dest: &aVar, Size: 5}))
if err != nil {
return err
}
fmt.Println("aVar: ", aVar, "\tbVar: ", bVar)
fmt.Println("finish exec: ", time.Now().Sub(t))
return nil
}
func main() {
db, err := sql.Open("oracle", os.Getenv("DSN"))
if err != nil {
fmt.Println("can't connect: ", err)
return
}
defer func() {
err = db.Close()
if err != nil {
fmt.Println("can't close connection: ", err)
}
}()
err = exec(db)
if err != nil {
fmt.Println("can't exec: ", err)
return
}
}
result:
aVar: a bVar: b
finish exec: 1.286287703s
Thank you for the quick response.
It seems my project was using an old version, which seeing your response prompted me to double check. After updating, this is working as intended. Thank you for testing with me and apologies for my ignorance.
Hello,
First wanted to say thanks for the hard work that goes into this package. Packaging the entire driver into Go has made distribution of our application so much easier, so we really appreciate the time you have put in.
I am running into an issue with Named Args being passed Positionally, where I believe I am following the correct syntax. Some support would be greatly appreciated
Here is a really simplified example of what I am trying to accomplish:
The Expectation would be that
aVar
would containa
andbVar
would containb
. In practice, however, thisfmt.Printf
printsaVar: b, bVar: a
, meaning that the variables were passed positionally, (see in the example thatbVar
is first).Please let me know if there is anything I am missing here. This is with
Database Version: 19.0.0.0.0
Thank you!