sijms / go-ora

Pure go oracle client
MIT License
796 stars 177 forks source link

ORA-03146 on successive call to a prepared statement with out parameter #589

Closed bauchpinsel closed 3 weeks ago

bauchpinsel commented 1 month ago

I just used dbms_output as an example here.

Oracle version: 19.23.0.0.0 go-ora version: 2.8.1.19

func TestOraError(t *testing.T) {
    db, err := sql.Open("oracle", connect)
    if err != nil {
        t.Fatalf("Could not connect: %v", err)
    }
    defer db.Close()
    s, err := db.PrepareContext(context.Background(), "BEGIN dbms_output.get_lines(:1, :2); END;")
    if err != nil {
        t.Fatalf("Could not prepare statement: %v", err)
    }
    defer s.Close()
    var (
        p1 = make([]string, 16)
        p2 = len(p1)
    )
    _, err = s.ExecContext(context.Background(), sql.Out{Dest: &p1}, sql.Out{Dest: &p2, In: true})
    if err != nil {
        t.Fatalf("Could not execute first: %v", err)
    }
    p2 = len(p1)
    _, err = s.ExecContext(context.Background(), sql.Out{Dest: &p1}, sql.Out{Dest: &p2, In: true})
    if err != nil {
        t.Fatalf("Could not execute second: %v", err)
    }
}
=== RUN   TestOraError
    dbms_output_test.go:65: Could not execute second: ORA-03146: invalid buffer length for TTC field
stle04 commented 3 weeks ago

Hi You need to use go_ora.Out instead of sql.Out

bauchpinsel commented 3 weeks ago

I should have mentioned that I already tried this. Changing sql.Out to go_ora.Out does nothing. Even playing with various combinations of the Size field does nothing. Would you be so kind providing a working example, like how you think it should work? Thanks.

Just to be clear. The example works fine without the Prepared statement. Even when using sql.Out.

sijms commented 3 weeks ago

issue fixed in next release 2.8.21 you can test in last commit

bauchpinsel commented 3 weeks ago

Works fine now