From f2efb0a66e5937c1f3f2e1f7e0356b9e4fadba1f Mon Sep 17 00:00:00 2001 From: Luis Silva Date: Tue, 24 Nov 2020 10:17:23 +0000 Subject: [PATCH 1/3] fix: fix NullPointerException thrown by SQLiteGlueConnection constructor When running an app built with targetSdkVersion 30, the SQLiteGlueConnection constructor is failing to open the connection with the sqlite database in some devices, and a NullPointerException is being thrown. References https://outsystemsrd.atlassian.net/browse/RNMT-4515 --- src/io/liteglue/SQLiteGlueConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io/liteglue/SQLiteGlueConnection.java b/src/io/liteglue/SQLiteGlueConnection.java index d279013..3a79e0d 100644 --- a/src/io/liteglue/SQLiteGlueConnection.java +++ b/src/io/liteglue/SQLiteGlueConnection.java @@ -9,7 +9,7 @@ public SQLiteGlueConnection(String filename, int flags) throws java.sql.SQLExcep SQLDatabaseHandle mydb = new SQLGDatabaseHandle(filename, flags); int rc = mydb.open(); - if (rc != SQLCode.OK) throw new java.sql.SQLException("sqlite3_open_v2 failure: " + db.getLastErrorMessage(), "failure", rc); + if (rc != SQLCode.OK) throw new java.sql.SQLException("sqlite3_open_v2 failure: " + mydb.getLastErrorMessage(), "failure", rc); this.db = mydb; } From 0c94cdaa57a2fe5911d5d4a56b46d30c7a6b62a4 Mon Sep 17 00:00:00 2001 From: Luis Silva Date: Wed, 25 Nov 2020 17:53:35 +0000 Subject: [PATCH 2/3] feat: add a java class to match the complex type for the SQL handle References https://outsystemsrd.atlassian.net/browse/RNMT-4515 --- src/io/liteglue/SQLiteResponse.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/io/liteglue/SQLiteResponse.java diff --git a/src/io/liteglue/SQLiteResponse.java b/src/io/liteglue/SQLiteResponse.java new file mode 100644 index 0000000..cc6b9d4 --- /dev/null +++ b/src/io/liteglue/SQLiteResponse.java @@ -0,0 +1,20 @@ +package io.liteglue; + +public class SQLiteResponse { + private int result; + private long handle; + + public SQLiteResponse(int result, long handle) { + this.result = result; + this.handle = handle; + } + + public int getResult() { + return this.result; + } + + public long getHandle() { + return this.handle; + } + +} \ No newline at end of file From c4db58469edec06dbbe78caf13549b76bb61f1dc Mon Sep 17 00:00:00 2001 From: Luis Silva Date: Wed, 25 Nov 2020 17:57:50 +0000 Subject: [PATCH 3/3] feat: update SQLiteNative and SQLGDatabaseHandle to use SQLiteResponse References https://outsystemsrd.atlassian.net/browse/RNMT-4515 --- src/io/liteglue/SQLGDatabaseHandle.java | 16 ++++++++++------ src/io/liteglue/SQLiteNative.java | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/io/liteglue/SQLGDatabaseHandle.java b/src/io/liteglue/SQLGDatabaseHandle.java index 95a00e8..3e0c941 100644 --- a/src/io/liteglue/SQLGDatabaseHandle.java +++ b/src/io/liteglue/SQLGDatabaseHandle.java @@ -11,10 +11,12 @@ public int open() { /* check state (should be checked by caller): */ if (dbfilename == null || dbhandle != 0) return SQLCode.MISUSE; - long handle = SQLiteNative.sqlc_db_open(dbfilename, openflags); - if (handle < 0) return (int)(-handle); + SQLiteResponse response = SQLiteNative.sqlc_db_open(dbfilename, openflags); + if(response.getResult() != SQLCode.OK) { + return -response.getResult(); + } - dbhandle = handle; + dbhandle = response.getHandle(); return SQLCode.OK; /* 0 */ } @@ -81,10 +83,12 @@ public int prepare() { /* check state (should be checked by caller): */ if (sql == null || sthandle != 0) return SQLCode.MISUSE; - long sh = SQLiteNative.sqlc_db_prepare_st(dbhandle, sql); - if (sh < 0) return (int)(-sh); + SQLiteResponse response = SQLiteNative.sqlc_db_prepare_st(dbhandle, sql); + if(response.getResult() != SQLCode.OK) { + return -response.getResult(); + } - sthandle = sh; + sthandle = response.getHandle(); return SQLCode.OK; /* 0 */ } diff --git a/src/io/liteglue/SQLiteNative.java b/src/io/liteglue/SQLiteNative.java index 2a179f9..0f164f2 100644 --- a/src/io/liteglue/SQLiteNative.java +++ b/src/io/liteglue/SQLiteNative.java @@ -57,10 +57,10 @@ public class SQLiteNative { public static native long sqlc_db_last_insert_rowid(long db); /** Interface to C language function:
sqlc_handle_t sqlc_db_open(const char * filename, int flags); */ - public static native long sqlc_db_open(String filename, int flags); + public static native SQLiteResponse sqlc_db_open(String filename, int flags); /** Interface to C language function:
sqlc_handle_t sqlc_db_prepare_st(sqlc_handle_t db, const char * sql); */ - public static native long sqlc_db_prepare_st(long db, String sql); + public static native SQLiteResponse sqlc_db_prepare_st(long db, String sql); /** Interface to C language function:
int sqlc_db_total_changes(sqlc_handle_t db); */ public static native int sqlc_db_total_changes(long db);