feat: implement Oracle-compatible UTL_ENCODE package#1338
Conversation
…nd BASE64_DECODE) Add UTL_ENCODE built-in package to ivorysql_ora extension, providing Oracle-compatible base64 encoding and decoding via RAW (bytea) input/output. BASE64_ENCODE: - Encodes binary data to base64 ASCII using 64-character lines with LF terminator after each line (RFC 1521 MIME format, matching Oracle's convention) - Empty input returns empty RAW; NULL input returns NULL (STRICT) BASE64_DECODE: - Decodes base64-encoded RAW data back to binary - Strips embedded whitespace (\n, \r, \t, space) before decoding so that output from BASE64_ENCODE (which inserts LF every 64 chars) round-trips correctly - Whitespace-only input returns empty RAW; NULL input returns NULL (STRICT) - Invalid base64 characters raise ERRCODE_INVALID_PARAMETER_VALUE Implementation: - C functions ivorysql_utl_encode_base64_encode / _base64_decode in utl_encode.c - PL/iSQL package spec and body wrap the C functions as utl_encode.base64_encode / utl_encode.base64_decode with RAW parameter types - Build system wired in Makefile, meson.build, and ivorysql_ora_merge_sqls - Regression tests cover: NULL, empty, known values, round-trips at line-break boundaries (48 / 49 / 200 bytes), CRLF handling, whitespace-only input, and PL/iSQL package interface
📝 WalkthroughWalkthroughThis PR adds UTL_ENCODE, an Oracle-compatible package providing BASE64_ENCODE and BASE64_DECODE functions for binary data encoding/decoding. It includes C implementations with proper line-break handling, SQL registration, build configuration updates, and comprehensive test coverage with expected output validation. ChangesUTL_ENCODE Oracle Compatibility Feature
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
contrib/ivorysql_ora/sql/utl_encode.sql (1)
11-73: ⚡ Quick winAdd explicit tests for empty RAW and mixed embedded whitespace decode paths.
Line 11 onward validates most behavior, but the feature contract for empty input and embedded whitespace stripping is not asserted directly. Please add those cases and update expected output accordingly.
As per coding guidelines `**/sql/*.sql`: Test SQL files. Ensure comprehensive coverage of features.✅ Proposed test additions
-- NULL input returns NULL (STRICT modifier) SELECT utl_encode.base64_encode(NULL) IS NULL; +-- Empty input returns empty RAW +SELECT rawtohex(utl_encode.base64_encode(hextoraw(''))) IS NULL; @@ -- NULL input returns NULL (STRICT modifier) SELECT utl_encode.base64_decode(NULL) IS NULL; +-- Empty input returns empty RAW +SELECT rawtohex(utl_encode.base64_decode(hextoraw(''))) IS NULL; @@ -- Decode known base64 string: 'SGVsbG8=\n' -> 'Hello' bytes -- hextoraw('534756736247383D0A') = 'SGVsbG8=\n', hextoraw('48656C6C6F') = 'Hello' SELECT rawtohex(utl_encode.base64_decode(hextoraw('534756736247383D0A'))) = '48656C6C6F'; +-- Embedded whitespace tolerance (LF/CR/TAB/SPACE inside payload) +-- 'SGV s\r\nbG8=\t' -> 'Hello' +SELECT rawtohex(utl_encode.base64_decode(hextoraw('53475620730D0A6247383D09'))) = '48656C6C6F';🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@contrib/ivorysql_ora/sql/utl_encode.sql` around lines 11 - 73, Add explicit tests asserting empty-RAW behavior and the whitespace-stripping decode path: add a case that invokes utl_encode.base64_encode and utl_encode.base64_decode with an empty RAW input and assert the result is an empty RAW (use rawtohex checks consistent with existing tests), and add tests that feed base64 inputs containing embedded whitespace/CR/LF/tabs into utl_encode.base64_decode and assert they decode to the same binary as the equivalent whitespace-free base64 string; reference the existing tests around utl_encode.base64_encode and utl_encode.base64_decode to place these new assertions adjacent to the NULL and round-trip checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@contrib/ivorysql_ora/sql/utl_encode.sql`:
- Around line 11-73: Add explicit tests asserting empty-RAW behavior and the
whitespace-stripping decode path: add a case that invokes
utl_encode.base64_encode and utl_encode.base64_decode with an empty RAW input
and assert the result is an empty RAW (use rawtohex checks consistent with
existing tests), and add tests that feed base64 inputs containing embedded
whitespace/CR/LF/tabs into utl_encode.base64_decode and assert they decode to
the same binary as the equivalent whitespace-free base64 string; reference the
existing tests around utl_encode.base64_encode and utl_encode.base64_decode to
place these new assertions adjacent to the NULL and round-trip checks.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5682c4cc-0f49-4798-9f84-ae348a9f7f2d
📒 Files selected for processing (7)
contrib/ivorysql_ora/Makefilecontrib/ivorysql_ora/expected/utl_encode.outcontrib/ivorysql_ora/ivorysql_ora_merge_sqlscontrib/ivorysql_ora/meson.buildcontrib/ivorysql_ora/sql/utl_encode.sqlcontrib/ivorysql_ora/src/builtin_packages/utl_encode/utl_encode--1.0.sqlcontrib/ivorysql_ora/src/builtin_packages/utl_encode/utl_encode.c
(BASE64_ENCODE and BASE64_DECODE)
Add UTL_ENCODE built-in package to ivorysql_ora extension, providing Oracle-compatible base64 encoding and decoding via RAW (bytea) input/output.
BASE64_ENCODE:
BASE64_DECODE:
Implementation:
resolve #1053
Summary by CodeRabbit
New Features
UTL_ENCODEpackage for Oracle compatibility withBASE64_ENCODEandBASE64_DECODEfunctions, supporting encoding and decoding of binary data with proper whitespace handling and error detection for invalid input.Tests
UTL_ENCODEfunctionality including NULL handling, round-trip verification, boundary cases, and error scenarios.