0
votes

I have a stored procedure made in Oracle 9g that returns a cursor with different columns depending on a parameter, its something like this:

CREATE OR REPLACE PROCEDURE ASCHEMA.SP_TWOCURSORS
(
    aParam NUMBER,
    P_RETURN OUT SYS_REFCURSOR
)
IS
BEGIN
    IF aParam = 1 THEN
        OPEN P_RETURN FOR
            SELECT
                a.column1, (number)
                a.column2  (varchar2)
            FROM
                table1 a;
    ELSE
        OPEN P_RETURN FOR
            SELECT
                b.column1, (varchar2)
                b.column2, (number)
                b.column3  (number)
            FROM
                table1 b;
    END IF;
END;

I have to consume this procedure in PowerBuilder and pass the returned data to a DataWindow1 or DataWindow2, depending on the returned cursor, these datawindows are filled in runtime by the execution of another procedures coming from other source. I can't modify the database objects (like split the sp in two), just the PowerBuilder code. My problem is how to handle this scenario in an elegant way. I have some ideas but don't know if it will work:

  1. Create a DataWindow object that handles every column involved in both cursors returned from the sp, then copy each row to the expected DataWindow.
  2. Create a DataStore and pass the sp with the Create method, then copy the rows in the expected DataWindow.
  3. Execute the procedure dynamically, fetch every row and add each result into a new row of the expected DataWindow.

I haven't tried the first one because there are many columns and it will take a long time to do. The second looks good but I don't know how to handle a DataStore with no DataWindow object and don't know if this is possible (1). The third is my last option to solve this problem. I want to ask people before start implementing this solution because I'm new to PowerBuilder, and even if I won't work on it too long I want to do it in the right way.

Thanks for the help.

(1) I have found this article about using Custom DataStores but I don't know if I can use only 1 DataStore or I should use 2. Also, for the Oracle connection I don't use SQLCA but another transaction object, so I don't know how to do this.

1

1 Answers

1
votes

Keep It Simple.

You know the details of the stored proc. If you are calling this sp from PB, you are knowing its aParam already before the call. Why not defining 2 datawindows, one for each version of the results ?

Each DW would have a retrieval argument (the one that is passed to the stored proc) and will get its result from the sp.

At runtime, depending on the retrieval argument, and before retrieving the values, assign the corresponding dataobject to the datawindow object that is on : either the DW that suits the aParam = 1 or the DW that suits the else part.