From 89c19c3d1b27970dad4813f5dbcae87fa081a3c3 Mon Sep 17 00:00:00 2001 From: Dewey Dunnington Date: Mon, 6 Nov 2023 10:49:01 -0400 Subject: [PATCH] fix(r/adbcsqlite): Allow sqlite driver to link against sqlite3 that does not contain sqlite3_load_extension() (#1259) Closes #1255. --- c/driver/sqlite/sqlite.c | 7 +++++++ r/adbcsqlite/configure | 13 +++++++++++++ r/adbcsqlite/tools/test_extension.c | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 r/adbcsqlite/tools/test_extension.c diff --git a/c/driver/sqlite/sqlite.c b/c/driver/sqlite/sqlite.c index a6ca3f8105..b388ccf12b 100644 --- a/c/driver/sqlite/sqlite.c +++ b/c/driver/sqlite/sqlite.c @@ -297,6 +297,7 @@ AdbcStatusCode SqliteConnectionSetOption(struct AdbcConnection* connection, conn->extension_path = strdup(value); return ADBC_STATUS_OK; } else if (strcmp(key, kConnectionOptionLoadExtensionEntrypoint) == 0) { +#if !defined(ADBC_SQLITE_WITH_NO_LOAD_EXTENSION) if (!conn->conn) { SetError(error, "[SQLite] %s can only be set after AdbcConnectionInit", key); return ADBC_STATUS_INVALID_STATE; @@ -320,6 +321,12 @@ AdbcStatusCode SqliteConnectionSetOption(struct AdbcConnection* connection, free(conn->extension_path); conn->extension_path = NULL; return ADBC_STATUS_OK; +#else + SetError(error, + "[SQLite] This build of the ADBC SQLite driver does not support extension " + "loading"); + return ADBC_STATUS_NOT_IMPLEMENTED; +#endif } SetError(error, "[SQLite] Unknown connection option %s=%s", key, value ? value : "(NULL)"); diff --git a/r/adbcsqlite/configure b/r/adbcsqlite/configure index 95f48e83db..d26c794d68 100755 --- a/r/adbcsqlite/configure +++ b/r/adbcsqlite/configure @@ -50,6 +50,19 @@ if [ $? -ne 0 ] || [ ! -z "$FORCE_VENDORED_SQLITE3" ]; then else echo "Success!" PKG_LIBS="$PKG_LIBS -lsqlite3" + + # Apple -lsqlite3 does not contain sqlite3_load_extension() + echo "Testing SQLite for sqlite3_load_extension()" + PKG_CPPFLAGS="$PKG_CPPFLAGS" PKG_LIBS="$PKG_LIBS" \ + $R_HOME/bin/R CMD SHLIB tools/test_extension.c -o sqlite_test >sqlite_test.log 2>&1 + + if [ $? -ne 0 ]; then + echo "Compile of sqlite3_load_extension() test failed" + cat sqlite_test.log + PKG_CPPFLAGS="$PKG_CPPFLAGS -DADBC_SQLITE_WITH_NO_LOAD_EXTENSION" + else + echo "Success!" + fi fi # Add mingw printf flag if on Windows diff --git a/r/adbcsqlite/tools/test_extension.c b/r/adbcsqlite/tools/test_extension.c new file mode 100644 index 0000000000..6a35045afa --- /dev/null +++ b/r/adbcsqlite/tools/test_extension.c @@ -0,0 +1,21 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include +#include + +void try_load_extension() { sqlite3_load_extension(NULL, NULL, NULL, NULL); }