K2InformaticsGmbH / oranif

Oracle OCI driver using dirty NIF
Apache License 2.0
4 stars 2 forks source link

Fix ref cursor stmt res leak #63

Closed c-bik closed 5 years ago

c-bik commented 5 years ago
acautin commented 5 years ago

@c-bik in my local tests the reference doesn't change after doing an execute with the same bind variables so the reuse is working as expected:

mec_oc:fetch_stmt(RefCursor).
{true,[1.0,<<"a">>,null,null,null]}
(cpro1@127.0.0.1)15> mec_oc:fetch_stmt(RefCursor).
{true,[2.0,<<"b">>,null,null,null]}
(cpro1@127.0.0.1)16> dpi:safe(fun() -> dpi:stmt_execute(Stmt, []) end).    0                                                                          (cpro1@127.0.0.1)17> NewRefCursor = dpi:safe(fun() -> dpi:data_get(Data) end).
#Ref<42688.719746273.3376021508.226633>
(cpro1@127.0.0.1)18> RefCursor.
#Ref<42688.719746273.3376021508.226633>
(cpro1@127.0.0.1)19> RefCursor = NewRefCursor
(cpro1@127.0.0.1)19> .
#Ref<42688.719746273.3376021508.226633>
(cpro1@127.0.0.1)20> RefCursor =:= NewRefCursor.
true
(cpro1@127.0.0.1)21> mec_oc:fetch_stmt(NewRefCursor).
{true,[3.0,<<"something2">>,<<"something3">>,
       <<"something4">>,<<"something5">>]}
c-bik commented 5 years ago

@acautin I am wondering if this means, the lifetime of the Stmt from RefCursor is independent of the lifetime / state of the Stmt which returned the RefCursor!

@c-bik in my local tests the reference doesn't change after doing an execute with the same bind variables so the reuse is working as expected:

mec_oc:fetch_stmt(RefCursor).
{true,[1.0,<<"a">>,null,null,null]}
(cpro1@127.0.0.1)15> mec_oc:fetch_stmt(RefCursor).
{true,[2.0,<<"b">>,null,null,null]}
(cpro1@127.0.0.1)16> dpi:safe(fun() -> dpi:stmt_execute(Stmt, []) end).    0                                                                          (cpro1@127.0.0.1)17> NewRefCursor = dpi:safe(fun() -> dpi:data_get(Data) end).
#Ref<42688.719746273.3376021508.226633>
(cpro1@127.0.0.1)18> RefCursor.
#Ref<42688.719746273.3376021508.226633>
(cpro1@127.0.0.1)19> RefCursor = NewRefCursor
(cpro1@127.0.0.1)19> .
#Ref<42688.719746273.3376021508.226633>
(cpro1@127.0.0.1)20> RefCursor =:= NewRefCursor.
true
(cpro1@127.0.0.1)21> mec_oc:fetch_stmt(NewRefCursor).
{true,[3.0,<<"something2">>,<<"something3">>,
       <<"something4">>,<<"something5">>]}

In other words the second execute probably has no effect!

c-bik commented 5 years ago

@c-bik a test case with a re execution of the query to get a new ref cursor is missing.

Done!