-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Driver doesn't support sys_refcursor parameter #53
Comments
go to the code in connection.go and examine function GetNLS() output parameter is supported when use the package directly as explained in readme file |
if your problem solved please close the issue |
Thank you, I'm trying, I will close after success and confirm. |
@sijms I'm sorry I lasted, I'm back. I read code in connection.go and examine function GetNLS() cmdText := `
DECLARE
o_cursor sys_refcursor;
BEGIN
dashboard.getTTVT(o_cursor);
END;`
stmt := go_ora.NewStmt(cmdText, db.oracleDB)
stmt.AddParam("o_cursor", "", 1000, go_ora.Output)
// defer stmt.Close()
result, err := stmt.Exec(nil)
if err != nil {
fmt.Printf("Error execute query: %s\n", err)
return nil, err
}
fmt.Println(result) I don't know how to add output sys_refcursor.
When run I receive error
If my cmdText is wrong, pls show me the correct. How to add output of sys_refcursor and how can I add output to units array? // Unit of list
type Unit struct {
unit_id int64
unit_name string
} |
I didn't test ref_cursor before only simple binding only |
If it just simple query, it's ok but almost all my procedure open sys_refcursor. Do you have a plan to update work with procedure open sys_refcursor now or near future? |
OK, no problem i will work on this and when finish i will update and inform you |
I add support for RefCursor |
Thank you for your support. Now with procedure get only output sys_refcursor, It work well but when I get input then it begin run forever without result or error. PROCEDURE getTTVT
(
i_unitID IN number,
i_unitName IN nvarchar(200),
o_data OUT sys_refcursor
); if I have a procedure with input is number or nvarchar2 and the output is sys_refcursor, my function is: units := []models.Unit{}
// Create statment
cmdText := `BEGIN test.getTTVT(:1, :2, :3); END;`
stmt := go_ora.NewStmt(cmdText, db.oracleDB)
stmt.AddParam("1", 41, 100, go_ora.Input)
stmt.AddParam("2", "BCH", 1000, go_ora.Input)
stmt.AddRefCursorParam("3")
defer stmt.Close()
// Query
_, err := stmt.Exec(nil)
if err != nil {
fmt.Println("Error query")
return nil, err
}
if cursor, ok := stmt.Pars[0].Value.(go_ora.RefCursor); ok {
defer cursor.Close()
rows, err := cursor.Query()
if err != nil {
return nil, err
}
var (
unit_id int64
unit_name string
)
unit := models.Unit{}
values := make([]driver.Value, 2)
for {
err = rows.Next(values)
// check for error and if == io.EOF break
if err == io.EOF {
break
}
if unit_id, ok = values[0].(int64); !ok {
return nil, errors.New("Not have value unit_id")
}
if unit_name , ok = values[1].(string); !ok {
return nil, errors.New("Not have value unit_name ")
}
unit.unit_id = unit_id
unit.unit_name = unit_name
units = append(units, unit)
}
}
return units, nil when I run I get a run forever nonstop. Do I add input AddParam wrong? @sijms |
here add check for other errors
|
did you get correct output? |
Yes, my procedure return two columns which are unit_id number and unit_name nvarchar2.
There is nothing happen. It just run forever. |
I make modification that solve the problem |
I have an oracle Procedure like, which returns a sys_refcursor:
My go function is:
When I run command:
I only get nil
@sijms Can you explain how to call Oracle Store Procedure?
The text was updated successfully, but these errors were encountered: