From fb5ae92065de13a1c5d5020b47ffa5d3bc7ee98a Mon Sep 17 00:00:00 2001 From: Francesco Cattoglio Date: Fri, 13 Jun 2025 15:40:25 +0000 Subject: [PATCH 1/2] Added a compile time flag to compile SQLite with builtin math funcions --- .cargo/config.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..c0b267cf --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,4 @@ +[env] +# To use built-in math functions, this compile time flag must be set +# See https://www.sqlite.org/draft/lang_mathfunc.html as a reference +LIBSQLITE3_FLAGS = { value = "-DSQLITE_ENABLE_MATH_FUNCTIONS", force=true } From 37fb4beb156a907dc79128a0bf6e4e77abb9c821 Mon Sep 17 00:00:00 2001 From: Francesco Cattoglio Date: Fri, 20 Jun 2025 15:09:23 +0000 Subject: [PATCH 2/2] Added a test, improved the comments in cargo config file --- .cargo/config.toml | 5 ++++- tests/sql_test_files/it_works_sqrt.sql | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/sql_test_files/it_works_sqrt.sql diff --git a/.cargo/config.toml b/.cargo/config.toml index c0b267cf..d22ed76a 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,4 +1,7 @@ [env] # To use built-in math functions, this compile time flag must be set # See https://www.sqlite.org/draft/lang_mathfunc.html as a reference -LIBSQLITE3_FLAGS = { value = "-DSQLITE_ENABLE_MATH_FUNCTIONS", force=true } +# According to Cargo docs this will not overwrite any env var that was already +# set by the user, and this is a good thing. If the user already set some +# LIBSQLITE3_FLAGS, he probably knows what he is doing. +LIBSQLITE3_FLAGS = "-DSQLITE_ENABLE_MATH_FUNCTIONS" diff --git a/tests/sql_test_files/it_works_sqrt.sql b/tests/sql_test_files/it_works_sqrt.sql new file mode 100644 index 00000000..99c92383 --- /dev/null +++ b/tests/sql_test_files/it_works_sqrt.sql @@ -0,0 +1,7 @@ +set number_three = sqrt(9.0); + +select 'text' as component, + case $number_three + when '3.0' then 'It works !' + else 'error: ' || coalesce($number_three, 'NULL') + end AS contents;