-
Notifications
You must be signed in to change notification settings - Fork 637
Feature Request: Exposing C function sqlite3_load_extension to Java #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Although the direct call of sqlite3_load_extension is not supported, you can register some UDFs as shown in the examples in https://github.com/xerial/sqlite-jdbc/blob/master/src/test/java/org/sqlite/UDFTest.java#L309 And also we are pre-loading some extension functions (math related stuffs) around here: Lines 58 to 62 in 5105677
|
I think we have two (or three) options:
Anyway I don't have much interest in adding these options by myself, so PR based contribution is better for me. |
I'm going to look into adding a JNI interface. The Extension I want to load is a slightly modified version of sqlite3_icu. (I renamed the function names so that the original functions are not overridden.) |
OK. I once tried to link ICU statically, but gave it up because of that reason you mentioned and thedifficulty of building ICU for various architectures. If load_extention works through JNI, it would be good for your purpose. |
I created PR #319 . |
A possible solution is to use the import java.sql.Connection;
import java.sql.SQLException;
import org.sqlite.SQLiteConfig;
import org.sqlite.SQLiteConnection;
import org.sqlite.core.DB;
private Connection connect() throws SQLException {
final Connection connection = (new SQLiteConfig()).createConnection(":memory:");
final DB db = ((SQLiteConnection)connection).getDatabase();
try {
db.enable_load_extension(true);
// sql queries to load extensions
} finally {
db.enable_load_extension(false);
}
return connection;
} |
The downcast is not needed. final Connection connection = DriverManager.getConnection(":memory:");
if (connection.isWrapperFor(SQLiteConnection.class)) {
DB db = connection.unwrap(SQLiteConnection.class).getDatabase();
try {
db.enable_load_extension(true);
// sql queries to load extensions
} finally {
db.enable_load_extension(false);
}
} |
I need to load a SQLite extension.
With sqlite-jdbc, I can enable the SQL function load_extension to achieve this. However, this is not recommended as it increases the attack surface when a SQL injection is possible.
(SQL injections should be avoided anyway but humans make mistakes ...)
SQLite provides the C function
int sqlite3_load_extension(sqlite3 *db, const char *zFile, const char *zProc, char **pzErrMsg);
https://sqlite.org/c3ref/load_extension.html
to load extensions. This could be used to load extensions from Java but not from a SQL statement.
Loading of extensions can be enabled by C API and at the same time disabled by SQL queries.
https://www.sqlite.org/c3ref/enable_load_extension.html
https://www.sqlite.org/c3ref/c_dbconfig_enable_fkey.html (SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION)
The text was updated successfully, but these errors were encountered: