json and rowids

Posted by jmls on 18-Jul-2014 12:49

leaving aside the evils of rowids .... 

given that I have a jsonObject, and that I add a property thus:

myJson:add("rowid",rowid(table)).


I get in the json file

{ rowid: "AAAAAAAAgQE=" , ..[snip] .. }


from the data type mapping, I am surmising that this is a base-64 encoded string.

so, my question is - how to convert this back to a rowid value ? base64-decode gives me a memptr with a binary value  

All Replies

Posted by jmls on 18-Jul-2014 12:51

and, I forgot to ask, why is the mapping a base64-encoded string ? wouldn't a "number" or plain old "string" be better ?

Posted by jmls on 18-Jul-2014 13:04

before anyone asks .. ;)

to-rowid(<<base64-encodedString>>)  gives a ?

Posted by Peter Judge on 18-Jul-2014 13:07

What about
 
To-rowid(
    Get-string(
     Base64-decoded(strRowid), 1))
 
?
 
[collapse]
From: jmls [mailto:bounce-jmls@community.progress.com]
Sent: Friday, 18 July, 2014 14:05
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] json and rowids
 
Reply by jmls

before anyone asks .. ;)

to-rowid(<<base64-encodedString>>)  gives a ?

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by jmls on 18-Jul-2014 13:11

also tried that. gives you a ? as well.

Posted by gus on 18-Jul-2014 13:46

julian: rtfm. it is not a number because it is not an integer and isn't representable as such in the 4gl.

recall that recids /are/ represntable as integers and 4gl applications often use them more or less interchangeably.

a rowid, on the other hand is a variable-size byte array that can only sometimes be converted into an integer.

the stringified for of a rowid is /not/ a base 64 encoded value. that's why it doesn't work.

but you can do

def var s as char.

def var r as rowid.

s = string(rowid(customer)).

r = to-rowid(s).

Posted by jmls on 18-Jul-2014 15:03

yeah,

old habits die hard ;)

however, you can string(rowid) and to-rowid(string), so why isn't the default mapping of a rowid the stringified version ?

add("rowid",string(rowid(customer))

gives you

rowid: "0x0000000000008101"

which can be converted back into a rowid using to-rowid()

the problem that I've got is that once converted to json, I can't seem to convert it back

Posted by Richard.Kelters on 19-Jul-2014 04:31

I may be missing the point but you should not convert is yourself but leave it to OpenEdge. Like this:

def temp-table tt no-undo

field rw as rowid.

create tt.

tt.rw = rowid(tt).

temp-table tt:handle:write-json("file","c:\temp\tt.json").

/* strange tt is not available anymore */

for each tt:

delete tt.

end.

temp-table tt:handle:read-json("file","c:\temp\tt.json").

find first tt.

message rowid(tt) eq tt.rw

view-as alert-box.

Posted by jmls on 19-Jul-2014 05:05

I think that you are missing the point ;)

I am constructing a json object, manually using the progress,json classes

I am not using a temp-table, so write-json is not applicable.

however, perhaps I just need to getRowid() on the inbound json object
. that may work



On 19 July 2014 10:32, Richard.Kelters
wrote:
> RE: json and rowids
> Reply by Richard.Kelters
>
> I may be missing the point but you should not convert is yourself but leave
> it to OpenEdge. Like this:
>
> def temp-table tt no-undo
>
> field rw as rowid.
>
> create tt.
>
> tt.rw = rowid(tt).
>
> temp-table tt:handle:write-json("file","c:\temp\tt.json").
>
> /* strange tt is not available anymore */
>
> for each tt:
>
> delete tt.
>
> end.
>
> temp-table tt:handle:read-json("file","c:\temp\tt.json").
>
> find first tt.
>
> message rowid(tt) eq tt.rw
>
> view-as alert-box.
>
> Stop receiving emails on this subject.
>
> Flag this post as spam/abuse.



--
Julian Lyndon-Smith
IT Director,
dot.r
http://www.dotr.com

Posted by gus on 21-Jul-2014 15:49

julian:

when you say "the problem that I've got is that once converted to json, I can't seem to convert it back" how are you attempting to do it? a code snippet might give me a clue (i am quite clueless, you know).

Posted by jmls on 22-Jul-2014 00:46

so, it appears that I am *much* more clueless than you are ..

the answer has been staring me right in the face - there is a getRowid() method on the jsonObject .... doh ....

however, I would also like to know if it is possible to convert a string like

"AAAAAAAAAGE="

back into a rowid value ?

Posted by gus on 22-Jul-2014 08:50

how did you get the string "AAAAAAAAAGE=" and what makes you think such a conversion might be possible?

string(rowid) produces hexadecimal digits, two per byte of rowid. "G" is not a hexadecimal digit.

Posted by Peter Judge on 22-Jul-2014 09:13

The JsonObject converts ROWIDs to base64-encoded strings (per the doc). This is where Julian's quest started, I believe, before he discovered GetRowid().
 
-- peter
 
[collapse]
From: gus [mailto:bounce-gus@community.progress.com]
Sent: Tuesday, 22 July, 2014 09:51
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] json and rowids
 
Reply by gus

how did you get the string "AAAAAAAAAGE=" and what makes you think such a conversion might be possible?

string(rowid) produces hexadecimal digits, two per byte of rowid. "G" is not a hexadecimal digit.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by gus on 22-Jul-2014 10:52

well, that's a pretty stupid thing to do.

Posted by jmls on 22-Jul-2014 13:19

Who? Me? :(

[collapse]
On 22 Jul 2014 16:53, "gus" <bounce-gus@community.progress.com> wrote:
Reply by gus

well, that's a pretty stupid thing to do.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

This thread is closed