1

I have rowversion value that comes from Database in binary format. I need to convert that value to string in order to pass in my front-end code. Then when user submits data back to the server I need to convert that string back to binary. Here is example of my data:

Binary 00000010586 

Above output is what I see when my query result returns value. Then I tried this:

Encoded value looks like this: iV

Then I tried to decode value back and this is what I have used:

#charsetDecode( local.encodedVal, "utf-8" )#

Then I got this error message: ByteArray objects cannot be converted to strings.

In my database row version column has timestamp type. When query returns that value it's represented as binary in ColdFusion. I use this column as unique id for each row set in my table. Is there a way to handle this conversion in CldFusion adn what would be the best approach?

espresso_coffee
  • 5,980
  • 11
  • 83
  • 193
  • Add 4 space to your first code block so that it'll display. – Twillen Aug 27 '18 at 16:02
  • Arrgggh... didn't notice you'd already asked about the binary issue here too ;-) Just finished writing up how to handle that here: https://stackoverflow.com/questions/52040916/update-record-based-on-rowversion-value – SOS Aug 28 '18 at 01:46

1 Answers1

3

Your working with binary data, and not with string encodings. You will need to use binaryEncoded and binaryDecode to send your data as a string and convert it back to binary.

The following example converts some binary data into 2 string representations and converts them back into the same byte array with binaryDecodein the dump.

<cfscript>
    binaryData = toBinary("SomeBinaryData++");
    hexEncoded = binaryEncode(binaryData, "hex");
    base64Encoded = binaryEncode(binaryData, "base64");

    writeDump([
        binaryData,
        hexEncoded,
        base64Encoded,
        binaryDecode(hexEncoded, "hex"),
        binaryDecode(base64Encoded, "base64")
    ]);
</cfscript>

Run the example on TryCF.com

Twillen
  • 1,458
  • 15
  • 22