summaryrefslogtreecommitdiff
path: root/subprojects/boost-sqlite/test/extension
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-09-14 00:16:10 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-09-14 00:16:10 -0400
commit13e0821fd783a1d5083d825af53cf20e8dcbfd76 (patch)
tree1ea363b0f13b3e87d177100e6ae6b9f30a2de1b8 /subprojects/boost-sqlite/test/extension
parentaa55cb93036a89c64c08e08f4e1de4fa1fd5a775 (diff)
parentefcea3a80da7c4479d5fe168435ecc9fd06bdc72 (diff)
downloadsqlite-kv-bench-13e0821fd783a1d5083d825af53cf20e8dcbfd76.tar.gz
Merge commit 'efcea3a80da7c4479d5fe168435ecc9fd06bdc72' as 'subprojects/boost-sqlite'
Diffstat (limited to 'subprojects/boost-sqlite/test/extension')
-rw-r--r--subprojects/boost-sqlite/test/extension/CMakeLists.txt19
-rw-r--r--subprojects/boost-sqlite/test/extension/simple_scalar.cpp27
-rw-r--r--subprojects/boost-sqlite/test/extension/simple_scalar.sql4
3 files changed, 50 insertions, 0 deletions
diff --git a/subprojects/boost-sqlite/test/extension/CMakeLists.txt b/subprojects/boost-sqlite/test/extension/CMakeLists.txt
new file mode 100644
index 0000000..a52a92c
--- /dev/null
+++ b/subprojects/boost-sqlite/test/extension/CMakeLists.txt
@@ -0,0 +1,19 @@
+
+file(GLOB_RECURSE ALL_SQLITE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.sql)
+file(GLOB_RECURSE ALL_CPP_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
+
+foreach(module ${ALL_CPP_FILES})
+ get_filename_component(stem ${module} NAME_WE)
+ add_library(boost_sqlite_test_extension_${stem} SHARED ${module})
+ target_link_libraries(boost_sqlite_test_extension_${stem} PUBLIC Boost::sqlite_ext)
+ target_include_directories(boost_sqlite_test_extension_${stem} PUBLIC ../../include)
+ set_property(TARGET boost_sqlite_test_extension_${stem} PROPERTY PREFIX "")
+ set_target_properties(boost_sqlite_test_extension_${stem} PROPERTIES OUTPUT_NAME ${stem})
+endforeach()
+
+foreach(script ${ALL_SQLITE_FILES})
+ get_filename_component(stem ${script} NAME_WE)
+ add_test(NAME boost_sqlite_test_extension_${stem} COMMAND
+ sqlite3 :memory: ".read ${CMAKE_CURRENT_SOURCE_DIR}/${script}"
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+endforeach()
diff --git a/subprojects/boost-sqlite/test/extension/simple_scalar.cpp b/subprojects/boost-sqlite/test/extension/simple_scalar.cpp
new file mode 100644
index 0000000..4a05afe
--- /dev/null
+++ b/subprojects/boost-sqlite/test/extension/simple_scalar.cpp
@@ -0,0 +1,27 @@
+//
+// Copyright (c) 2022 Klemens Morgenstern (klemens.morgenstern@gmx.net)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <boost/sqlite/extension.hpp>
+#include <boost/sqlite/function.hpp>
+
+BOOST_SQLITE_EXTENSION(simplescalar, conn)
+{
+ create_scalar_function(
+ conn, "assert",
+ [](boost::sqlite::context<>, boost::span<boost::sqlite::value, 1u> sp)
+ {
+ if (sp.front().get_int() == 0)
+ throw std::logic_error("test failed");
+ });
+
+ create_scalar_function(
+ conn, "my_add",
+ [](boost::sqlite::context<>, boost::span<boost::sqlite::value, 2u> sp)-> sqlite3_int64
+ {
+ return sp[0].get_int() + sp[1].get_int();
+ });
+}
diff --git a/subprojects/boost-sqlite/test/extension/simple_scalar.sql b/subprojects/boost-sqlite/test/extension/simple_scalar.sql
new file mode 100644
index 0000000..00064ef
--- /dev/null
+++ b/subprojects/boost-sqlite/test/extension/simple_scalar.sql
@@ -0,0 +1,4 @@
+SELECT load_extension('./simple_scalar');
+
+select assert(5 = (select my_add(2, 3)));
+select assert(7 = (select my_add(4, 3)));