Skip to content

Commit d65072f

Browse files
committed
feat(sqlite): add hashing, UUID, encoding and compression functions
Add the remaining crypto, UUID and encoding functions from the coverage audit (#586): SHA1, SHA2, UUID, UUID_SHORT, UUID_TO_BIN, BIN_TO_UUID, IS_UUID, RANDOM_BYTES, CRC32, CONV, OCT, BIN, BIT_COUNT, COMPRESS, UNCOMPRESS and UNCOMPRESSED_LENGTH. CONV uses an exact digit walk instead of base_convert(), which loses precision on large values, and COMPRESS follows MySQL's byte layout so the round trip through UNCOMPRESS and UNCOMPRESSED_LENGTH holds. Two platform limits shaped the implementation and are documented in the code: the PDO UDF bridge truncates integer returns to 32-bit signed, so UUID_SHORT and CRC32 return numeric strings rather than corrupting roughly half their range; and SQLite's LENGTH() stops at the first NUL byte of a binary result, so COMPRESS and RANDOM_BYTES output is measured with HEX() in the tests. Review follow-ups addressed: - UUID_SHORT() seeds its counter with a random 24-bit value. MySQL keeps one counter for the whole server, but each connection gets its own UDF instance here, so two requests whose first call landed in the same second produced identical sequences. The random seed makes that unlikely; the docblock states that a strict guarantee would need a counter shared through the database. - Negative values are coerced to their 64-bit two's complement by magnitude and then negated. The previous code added 2^64 to a negative double, which rounds to exactly 2^64 for small values, so BIT_COUNT(-1.5) reported 1 instead of 64 and BIN(-12.5)/OCT(-12.5) rendered 2^64. Refs #586, #593.
1 parent 70bdaf3 commit d65072f

2 files changed

Lines changed: 986 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)