K2InformaticsGmbH / oranif

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

Ref cursor support implementation #58

Closed acautin closed 5 years ago

acautin commented 5 years ago

There are a couple of missing features for ref cursor support.

To help with the testing the following snippet can be used to extract the ref cursor reference:

    #{var := Var, data := [Data]} = dpi:conn_newVar(Conn, Type, 'DPI_NATIVE_TYPE_STMT', 1, 0, false, false, undefined),
    dpi:stmt_bindByName(Stmt, Name, Var),
    RefCursor = dpi:data_get(Data)
    case dpi:stmt_fetch(RefCursor) of
            #{found := true} ->
                NumCols = dpi:stmt_getNumQueryColumns(RefCursor),
                {true, get_column_values(RefCursor, 1, NumCols)};
            #{found := false} ->
                {false, []}
        end

And the helper function to get the values:

get_column_values(_Stmt, ColIdx, Limit) when ColIdx > Limit -> [];
get_column_values(Stmt, ColIdx, Limit) ->
    #{data := Data} = dpi:stmt_getQueryValue(Stmt, ColIdx),
    [dpi:data_get(Data) | get_column_values(Stmt, ColIdx + 1, Limit)].