New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add function Base64 (base64_encode, base64_decode) #2423
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
A good encoding function should have configuration options, because there are two character sets (regular and URL-safe) and both of them are very common, padding may be needed or not, and somebody way want to wrap lines in RFC2045-compatible way.
https://tools.ietf.org/html/rfc4648
https://tools.ietf.org/html/rfc2045
New functions need some documentation in h2/src/docsrc/help/help.csv
.
Initially I wanted to do as in postgresql I think creating a unique function (not the same as others) is bad practice as an option, I can add BASE64_URL_DECODE/ENCODE, it is not difficult, but I did not want to do garbage |
I meant that you can add some optional parameter to |
…t, change type: encode return string; decode input string.
Add optional parameter to BASE64_ENCODE function to control its output, change type: encode return string; decode input string. |
Add functions documentation in help.csv |
… edit help.csv, move test from TestFunctions to scripts
Del error code, del EncodingFactory, decode auto detection algorithm, edit help.csv, move test from TestFunctions to scripts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, resolve minor remaining problems and send a license statement as described here
https://h2database.com/html/build.html#providing_patches
to our mailing list
https://groups.google.com/forum/#!forum/h2-database
h2/src/test/org/h2/test/scripts/functions/string/base64_decode.sql
Outdated
Show resolved
Hide resolved
h2/src/test/org/h2/test/scripts/functions/string/base64_encode.sql
Outdated
Show resolved
Hide resolved
…th unsupported algorithm, call base64_decode with error base64 string, edit help, use only ASCII characters in test
call base64_decode and base64_encode with null, call base64_encode with unsupported algorithm, call base64_decode with error base64 string, edit help, use only ASCII characters in test |
@@ -2291,6 +2300,41 @@ private static Value oraHash(Value value, long bucket, long seed) { | |||
return ValueBigint.get((hc & Long.MAX_VALUE) % (bucket + 1)); | |||
} | |||
|
|||
private static Value base64encode(byte[] data, String algorithm) { | |||
if (data!=null){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data
is not expected to be null
here, if it can, something else is going wrong. If function does not declare NULL
support, getValueWithArgs()
returns NULL
if any of arguments is NULL
by itself at the beginning of the method.
} | ||
|
||
private static Value base64decode(String data) { | ||
if (data!=null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
No description provided.