[MDEV-5025] Merge TO_BASE64() and FROM_BASE64() from MySQL-5.6 Created: 2013-09-17  Updated: 2023-12-31  Resolved: 2013-11-14

Status: Closed
Project: MariaDB Server
Component/s: None
Fix Version/s: 10.0.6

Type: Task Priority: Minor
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Duplicate
duplicates MDEV-4387 UDF - Base64 encode/decode Closed
Relates
relates to MDEV-4800 base16, base32, base64 functions Open

 Description   

MySQL-5.6 implemented SQL functions TO_BASE64() and FROM_BASE64().
We should merge those two into MariaDB.



 Comments   
Comment by Alexander Barkov [ 2013-11-14 ]

Merged from MySQL-5.6. to MariaDB-10.0.5

Comment by Tom Miller [ 2023-12-30 ]

TO_BASE64 doesn't work on binaries. With web and HTML being king and embedded images usually being in BASE64, it would be nice if this works. It comes close but does a lot of extra "\" for some reason. Supposedly it works fine in MYSQL. I am not sure if this should be reported as a bug or an enhancement or maybe reconsider doing another merge from MYSQL to get the additional functionality of converting BLOB type along with strings.

Comment by roberto spadim [ 2023-12-31 ]

I’m using this for many years with blob, maybe you are using a wrong bytes encoding at client (ut8 or something like it is converting to string)

Comment by Tom Miller [ 2023-12-31 ]

CREATE OR REPLACE DATABASE `my-database` CHARACTER SET = 'utf8mb3' COLLATE = 'utf8mb3_general_ci';
Why would TO_BASE64 care about the character set? That sounds like a bug if it does.

There are no instructions on how to properly do this. The help page only talks about converting a string to BASE64, not a BLOB.
I take the result from a development tool (I think an ODBC driver), from the command line, and Thunder Test in VSCODE using MariaDb's node driver and all fail when I copy them to a website that converts BASE64 to an image.

This converts it every time in the Node.js / Express.js server we use:
var strBase64 = dbResponse[0][0].UserPictureBlob.toString("base64");

I copy the string to the webpage and the image shows up every time without error.

Generated at Thu Feb 08 07:01:04 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.