We have an application that stores serialized JSON into our DB as a blob.
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?
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.
It's aok now.