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

RNMT-4515 Fixes an issue with recent devices running Android 11 #1

Merged
merged 3 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/io/liteglue/SQLGDatabaseHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}

Expand Down Expand Up @@ -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 */
}

Expand Down
2 changes: 1 addition & 1 deletion src/io/liteglue/SQLiteGlueConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/io/liteglue/SQLiteNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public class SQLiteNative {
public static native long sqlc_db_last_insert_rowid(long db);

/** Interface to C language function: <br> <code> sqlc_handle_t sqlc_db_open(const char * filename, int flags); </code> */
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: <br> <code> sqlc_handle_t sqlc_db_prepare_st(sqlc_handle_t db, const char * sql); </code> */
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: <br> <code> int sqlc_db_total_changes(sqlc_handle_t db); </code> */
public static native int sqlc_db_total_changes(long db);
Expand Down
20 changes: 20 additions & 0 deletions src/io/liteglue/SQLiteResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.liteglue;

public class SQLiteResponse {
private int result;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, previously the errors were also returned as long
shouldn't we keep it the same way?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, SQLite result codes are integers. They were returned as long because the return type had to match either the SQLite codes and the handle value. Also, the consumer was always casting the error value to a int value as you can see here

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;
}

}