Skip to content
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

support sql.Out for cursors #407

Open
dbalamo opened this issue Nov 13, 2020 · 1 comment
Open

support sql.Out for cursors #407

dbalamo opened this issue Nov 13, 2020 · 1 comment

Comments

@dbalamo
Copy link

dbalamo commented Nov 13, 2020

Hello,
I'm still experiencing the same issue described here
#188
using Oracle 12.

I have this stored Procedure, which returns a sys_refcursor :

create or replace PROCEDURE PROCSELECTDIPCURSOR2
( 
  outcur OUT SYS_REFCURSOR
) AS
    
BEGIN            
    OPEN outcur FOR SELECT PERSON_ID, FIRST_NAME,LAST_NAME from DIPENDENTI where LAST_NAME LIKE 'T%';    
END PROCSELECTDIPCURSOR2;

and the GO code calling the stored procedure is this :

func main() {
	db, err := sql.Open("oci8", "user/password@localhost:1521/orclsid")
	if err != nil {
		log.Fatal(fmt.Errorf("ERROR OPEN - %w", err))
	}
	defer db.Close()

	ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
	defer cancel()

	tx, err := db.BeginTx(ctx, nil)
	if err != nil {
		log.Fatal(fmt.Errorf("ERROR BeginTx - %w", err))
		log.Fatal(err)
	}
	defer tx.Commit()

	var dr interface{}
	qry := "BEGIN PROCSELECTDIPCURSOR2(:outcur); END;"

	_, sqlErr := tx.ExecContext(ctx, qry, sql.Out{Dest: &dr})
	if sqlErr != nil {
		log.Fatal(sqlErr)
	} else {
		fmt.Println("Went OK")
	}
}

I've tried using interface, sql.Rows and driver.Rows as return variable for the sys_refcursor, but no luck , it keeps saying

PLS-00306: wrong number or types of arguments in call to 'PROCSELECTDIPCURSOR2' .

The code above works ok if I call a stored procedure returning base types (a number, for example).
Is the sql.Out support still missing something about cursors, or it's my fault?

Thanks

@MichaelS11
Copy link
Contributor

I don't think cursor has been added to outputBoundParameters yet.
https://github.com/mattn/go-oci8/blob/master/statement.go#L766-L933

@MichaelS11 MichaelS11 changed the title support sql.Out for stored procedures support sql.Out for cursors Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants