READ-JSON from LongChar back into DB - Forum - OpenEdge Development - Progress Community

READ-JSON from LongChar back into DB

 Forum

READ-JSON from LongChar back into DB

This question is not answered

We have an application that stores serialized JSON into our DB as a blob. 

BUFFER tt{&Table}:HANDLE:SERIALIZE-ROW('JSON','LONGCHAR',lcRecord,NO,'UTF-8',TRUE,TRUE).  

COPY-LOB FROM lcRecord  TO  <blobfield>

We then read this data back into a logging application, and one of the functions we're trying to do is restore deleted records.

So we grab that blobfield back out of the DB and so something like this:

    DEF VAR lcJson as LONGCHAR NO-UNDO.

oJson = NEW JsonObject().
oJsonParser = NEW ObjectModelParser().

lcJson = ?.
FIX-CODEPAGE(lcJson) = 'UTF-8'.

COPY-LOB FROM <blobfield> TO lcJson.
oJson = CAST(oJsonParser:Parse(lcJson), JsonObject).

CREATE TEMP-TABLE hTempTable.
hTempTable:READ-JSON("JsonObject", oJson, "EMPTY").

hTTdefault = hTempTable:DEFAULT-BUFFER-HANDLE.
CREATE QUERY hQuery.
hQuery:SET-BUFFERS(hTTdefault).
hQuery:QUERY-PREPARE('for each ' + hTempTable:NAME).
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().

DO TRANSACTION:
    CREATE BUFFER hBuffer FOR TABLE ttDatasetLog.tablename.

    hbuffer:BUFFER-CREATE().
    hbuffer:BUFFER-COPY(hTTdefault).
END.

The record gets restored to the DB just fine, but for some reason that escapes me integer and date fields aren't restored properly.  They are 0 / ?.

Decimals, characters, logicals all seem to be ok.

Was wondering if anyone's come across this before, and what they did to fix it?

TIA,

Brad

All Replies
  • Managed to figure it out already...

    Move this up after the CREATE TEMP-TABLE ..

           CREATE BUFFER hBuffer FOR TABLE ttDatasetLog.tablename.

    then added these 2.

           hTempTable:CREATE-LIKE(hBuffer).

           hTempTable:TEMP-TABLE-PREPARE("restoreTT").

    It's aok now.