Skip to Main Content

ORDS, SODA & JSON in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

If I "read" :body_text implicit param in plsql, json params don't bind. Why is that?

juliojgsJun 22 2022

Hi,
I created a quite simple post handler to insert a record in a database table.
I tested it with header parameters and it works, but if I do it with json payload, the in parameters are null.
After some debugging, I found that I was capturing the :body_text in a local variable (to log the calls).
Whenever I read the :body_text implicit parameter in the plsql, all the json parameters I'm sending in the json request unbind. That's even if I read the :body_text AFTER the custom parameters:

DECLARE
    l_json_doc  CLOB;
Begin
    insert into mytab values (:p_one, :p_two);
    :status_code := 201;
    :errmsg := 'Done! '||:p_one||' - '||:p_two;
    l_json_doc := :body_text;
end;

being the request json:

{
 "p_one": "hello",
 "p_two": "world" 
}

Well, if I comment the line

-- l_json_doc := :body_text;

the insert goes ok.
If not, it insert null values, just for having peeked inside :body_text.
This looks like some kind of quantum mechanics uncertainty ... cannot read both :body_text and parameter values?

This post has been answered by thatJeffSmith-Oracle on Jun 23 2022
Jump to Answer

Comments

John JB Brock-Oracle

The only thing I can think of to look at first would be if the keyAttributes value that you have set in your DataProvider is truly a uniqueId and you do not have duplicates in your dataset.

User_77VTN

I have faced similar issue and the suggestion solved. I was using a column 'code' as id Attribute where in reality it is not unique between rows. So changed the idAttribute to 'id' instead of 'code'.(Note: 'id' is not a column. It just took its own ref). Then the data got auto refreshed as soon as the observable is changed.

----------------------------------------------------------------------------------------- JS code -----------------------------------------

self.testArr = ko.observableArray();

//self.testDS = new PagingDataProviderView(new ArrayDataProvider(self.testArr, { idAttribute: 'code' }));  ===> REFRESH NOT WORKING

self.testDS = new PagingDataProviderView(new ArrayDataProvider(self.testArr, { idAttribute: 'id' })); //// REFRESH WORKING

self.testCols = ko.observable();

self.testCols([{

        "headerText": "code",

        "field": "code",

        "id": "test_code"

      },

      {

        "headerText": "amount",

        "field": "amnt",

        "id": "test_amnt"

      }

      ]);

var dir1 ={ "code":"c1","amnt":100 };

self.testArr.push(dir1);

var dir2 ={ "code":"c1","amnt":20 };

self.testArr.push(dir2);

-----------table------------------------------------------------------------------------------------------------------------------

<oj-table aria-label="Test Table" id="test-details-table" data='[[testDS]]'

                        selection-mode='{"row": "single", "column": "multiple"}' columns='[[testCols]]'

                        columns-default='{"sortable": "disabled" }' row-renderer="[[testTableRowRenderer]]"

                        scroll-policy='loadMoreOnScroll' class="width100">

                        <oj-paging-control class="lastTab" id="test_paging" data='[[testDS]]'

                            page-options='{"type":"Number"}' page-size='5' slot='bottom'>

                        </oj-paging-control>

                    </oj-table>

------------------------------------------------------------------------------------------------------------------------------------

User_77VTN

Check by changing keyAttributes --> from 'departmentId' ti 'id'

Philip Sommer

For completeness sake, let me make the following remarks:

  1. idAttribute is deprecated and you should use keyAttributes instead
  2. Specifying a non-existent field name as 1066874 recommends is not offically supported. Instead, you can simply not specify any keyAttributes, in which case the DataProvider will default to using the array index (which is guaranteed to be unique of course).

Source: https://www.oracle.com/webfolder/technetwork/jet/jsdocs/ArrayDataProvider.html#constructor-section

1 - 4

Post Details

Added on Jun 22 2022
4 comments
1,145 views