sqlite_bignum is a cross-platform SQLite extension that provides support for working with 64-bit unsigned integers (big numbers) as text, including collation and conversion functions. This makes it possible to safely and efficiently store, compare, and convert 64-bit values within SQLite databases, especially in contexts where binary and standard integer types may not be suitable.
- Provides custom collation for 64-bit unsigned integers stored as text in SQLite.
- Includes utility functions for converting between numeric and text representations of unsigned 64-bit integers.
- Can be dynamically loaded as a shared library (
.so
,.dll
, or.dylib
) on Linux, Windows, or macOS. - Includes a dedicated test suite built with cmocka.
First, build the extension for your platform (see Building).
Then, you can load it in SQLite:
sql .load './sqlite_bignum.dll'
u64_to_text(INT)
: Converts a 64-bit unsigned integer to its text representation.text_to_u64(TEXT)
: Parses a text representing an unsigned 64-bit integer and returns its integer value.is_u64text(TEXT)
: Returns 1 if the text is a valid 64-bit unsigned integer, 0 otherwise.u64text_display(TEXT)
: Returns an unpadded representation of the 64-bit integer text value
The extension registers a collation sequence that allows correct sorting of 64-bit unsigned integers stored as text.
-- Example usage:
CREATE TABLE data
(
value TEXT COLLATE U64TEXT
);
INSERT INTO data
VALUES ('18446744073709551615'),
('1'),
('42');
SELECT *
FROM data
ORDER BY value COLLATE u64text;
- CMake 3.31 or newer
- C compiler (GCC/Clang/MSVC)
- Git
- Clone the repository:
git clone <your-repo-url>
cd sqlite_bignum
- Configure and build:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
The shared library will be found in the build/
directory as:
- Linux:
libsqlite_bignum.so
- macOS:
libsqlite_bignum.dylib
- Windows:
sqlite_bignum.dll
cmake --build build --target test
Or, if you want to run the tests directly:
ctest --test-dir build
You can use this extension with any SQLite application that supports loading external extensions.
.load '<path-to-shared-library>'
SELECT u64_to_text(42), text_to_u64('18446744073709551615'), is_u64text('invalid_value');
MIT or your license of choice.
Contributions, bug reports, and suggestions are welcome!