Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

The v16 & v17 documents (all versions including the SAP Help one) imply that the input to Base64_encode() should be a string - which seems to miss the whole point of the exercise :) In fact it takes a long binary quite happily:

create variable blah1 long binary;
create variable blah2 long varchar;
create variable blah3 long binary;
set blah1 = xp_read_file('c:\tmp\mark.tif');
set blah2 = base64_encode(blah1);
set blah3 = base64_decode(blah2);
call xp_write_file('c:\tmp\markOUT.tif',blah3 );
with an 8MB tiff

I know that a related issue was discussed in this question back in 2014. But it would avoid a lot of confusion if the documentation for the relevant functions could make it clear when they can handle binary data. (I've just spent some time explaining to someone that thye don't need to convert their binary data to a string so they can convert it to a string so that they .... you get the idea!)

asked 10 Jun '20, 10:42

Justin%20Willey's gravatar image

Justin Willey
7.6k137179249
accept rate: 20%

edited 10 Jun '20, 11:24

Volker%20Barth's gravatar image

Volker Barth
40.2k361550822

Comment Text Removed
Comment Text Removed

I agree on the doc topic. I have the impression that "strings" within the docs sometimes only refers to character strings and sometimes also includes binary strings, as here...

That being said, the sample for BASE64_ENCODE seems to hint that "real binary data" should be passed as argument:

SELECT BASE64_ENCODE( image_data ) FROM IMAGES;

FWIW, for non-ascii encodings, base64 is also required/helpful for "real character string" encoding, just to prevent problems with the most significant bit, think of SMTP and the like...

(10 Jun '20, 11:22) Volker Barth

I've recommended an update to the docs to help make this more clear. The difficulty with many of these functions is that they accept arguments of all sorts of types and then convert the input argument to whatever seems to be the most appropriate for that type.

permanent link

answered 11 Jun '20, 12:47

JBSchueler's gravatar image

JBSchueler
3.3k41564
accept rate: 19%

Thanks - that's great. Just an indication not to get too hung up on the word "string" would do the job!

(11 Jun '20, 13:49) Justin Willey
Replies hidden
1

FWIW the EXPRTYPE function is useful to answer the question "Just exactly what is the data type at this point?"

For grins and giggles, check the return data type for the STRING() function.

(11 Jun '20, 14:27) Breck Carter
1

Yikes. That's the function that returns different things based on atmospheric pressure.

(11 Jun '20, 15:08) JBSchueler

(11 Jun '20, 16:10) Breck Carter
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×93
×1
×1

question asked: 10 Jun '20, 10:42

question was seen: 935 times

last updated: 11 Jun '20, 16:11