databasesqlitefilterbase64

Base64 in SQLite?


Is there something like

SELECT * FROM foo WHERE base64(bar) LIKE '%bararar%'

in SQLite?

If not, are there other compareable functions in other SQL-style databases? (MySQL, MSSQL and so on)

I really need to know this because I have a huge database where some base64-encodings of strings contain a specific character which I have to filter out. Hope someone can help me.


Solution

  • As of sqlite 3.41, it is now supported out of the box, with the function BASE64().

    The function encodes or decodes based on the argument type (text is decoded into blob, blob is encoded into text):

    sqlite> SELECT BASE64(CAST('hello' as BLOB));
    aGVsbG8=
    
    sqlite> SELECT BASE64('aGVsbG8=');
    hello