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