Skip to content
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

How do I load an extension #908

Open
whatify-io opened this issue May 23, 2023 · 4 comments
Open

How do I load an extension #908

whatify-io opened this issue May 23, 2023 · 4 comments
Labels
question Further information is requested

Comments

@whatify-io
Copy link

whatify-io commented May 23, 2023

Describe the bug
I added memstat extension by copying code from https://sqlite.org/src/file/ext/misc/memstat.c and pasting it in src/main/ext.
Then i did:

  • update makefile with -DSQLITE_DEFAULT_MEMSTATUS=1 -DSQLITE_ENABLE_MEMSTATVTAB=1
  • make native (mine is linux x86_64)
  • mvn package

This produced the jar.

Now I copied the Sample.java, showing relevant section below:

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
 import org.sqlite.core.DB;
import org.sqlite.SQLiteConnection;
    import java.util.Properties;

    public class Sample
    {
      public static void main(String[] args)
      {
        Connection connection = null;
        Properties properties = new Properties();
        properties.setProperty("enable_load_extension", "true");

        try
        {
          // create a database connection
          connection = DriverManager.getConnection("jdbc:sqlite:memory:", properties);
            // sql queries to load extensions
        //  connection.prepareStatement("SELECT load_extension('memstat')").execute(); -> perhaps this is not needed?
          Statement sm = connection.createStatement();
          ResultSet rr = sm.executeQuery("select * from memstat"); -> throws no table , tried sqlite_memstat too
          while(rr.next()) {
                System.out.println(rr.getString("name"));
          }
        

I was able to use a .so file and load that but I want to compile it together as done for extension-functions

Expected behavior
I expected to see memstat table.

Logs
If applicable, provide logs.

Environment (please complete the following information):

  • OS: Linux
  • CPU architecture: x86_64
  • sqlite-jdbc version 3.39.2.0

Additional context
Add any other context about the problem here.

@gotson gotson added question Further information is requested and removed triage labels May 23, 2023
@whatify-io
Copy link
Author

whatify-io commented May 24, 2023

Hi can I get some help here would be really great, as this is blocking us from getting sqlite heap stats.
It would be good to add some example on how to add an extension to src/main/ext and use it.
I don't know if there is a JDBC way of doing this http://www.sqlite.org/c3ref/db_status.html

@whatify-io
Copy link
Author

Hello anything someone can come with?

@ieugen
Copy link

ieugen commented Jan 22, 2024

Hi @whatify-io , did you manage to find a solution to this?

@ieugen
Copy link

ieugen commented Jan 22, 2024

it seems there is load_extension in JNI to allow loading of extensions.

public synchronized native int enable_load_extension(boolean enable);

Have your tried it @whatify-io ?
After calling it I imagine sqlite should allow for extension loading - even via SQL function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants