Kbase P126370: How can I convert a BASE64 encoded version of a ROWID value back into a ROWID?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  14/10/2007 |
|
Status: Unverified
GOAL:
How can I convert a BASE64 encoded version of a ROWID value back into a ROWID?
GOAL:
How can I convert a BASE64 encoded version of a ROWID value back into a valid string format of the ROWID value?
GOAL:
What format is a ROWID field when written to XML using WRITE-XML?
FACT(s) (Environment):
OpenEdge 10.1B
FIX:
When a field in a temp-table is defined as ROWID and that temp-table is serialized to XML using WRITE-XML the ROWID field is stored in the XML file as a BASE64 encoded value. If the serialized XML file is read back in using the READ-XML method the BASE64 encoded value will be converted back into a ROWID value automatically.
The following code gives two functions which will convert the BASE64 encoded version of a ROWID back into a usable ROWID value and into a character string value like you would get if you did STRING(ROWID(SomeTable)):
FUNCTION Base64ToRowid RETURNS ROWID (pBase64Value AS CHARACTER):
DEFINE VARIABLE vTempPointer AS MEMPTR NO-UNDO.
DEFINE VARIABLE vTempRaw AS RAW NO-UNDO.
DEFINE VARIABLE vTempString AS CHARACTER NO-UNDO.
ASSIGN vTempPointer = BASE64-DECODE(pBase64Value)
vTempRaw = GET-BYTES(vTempPointer,1,GET-SIZE(vTempPointer))
vTempString = '0x' + HEX-ENCODE(vTempRaw).
SET-SIZE(vTempPointer) = 0.
RETURN TO-ROWID(vTempString).
END FUNCTION.
FUNCTION Base64ToRowidAsString RETURNS CHARACTER (pBase64Value AS CHARACTER):
DEFINE VARIABLE vTempPointer AS MEMPTR NO-UNDO.
DEFINE VARIABLE vTempRaw AS RAW NO-UNDO.
DEFINE VARIABLE vTempString AS CHARACTER NO-UNDO.
ASSIGN vTempPointer = BASE64-DECODE(pBase64Value)
vTempRaw = GET-BYTES(vTempPointer,1,GET-SIZE(vTempPointer))
vTempString = '0x' + HEX-ENCODE(vTempRaw).
SET-SIZE(vTempPointer) = 0.
RETURN vTempString.
END FUNCTION.