Skip to content

Commit

Permalink
fix(r/adbcsqlite): Allow sqlite driver to link against sqlite3 that d…
Browse files Browse the repository at this point in the history
…oes not contain sqlite3_load_extension() (#1259)

Closes #1255.
  • Loading branch information
paleolimbot authored Nov 6, 2023
1 parent 313245b commit 89c19c3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions c/driver/sqlite/sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)");
Expand Down
13 changes: 13 additions & 0 deletions r/adbcsqlite/configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions r/adbcsqlite/tools/test_extension.c
Original file line number Diff line number Diff line change
@@ -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 <sqlite3.h>
#include <stddef.h>

void try_load_extension() { sqlite3_load_extension(NULL, NULL, NULL, NULL); }

0 comments on commit 89c19c3

Please sign in to comment.