When converting a Java exception to a db error message, use Throwable.toString() instead of getMessage() so that the exception type's name is included. More internal API renaming for consistency.
FossilOrigin-Name: 2d44720d06d9e50cb037e92981d2473a3ad0b7560f2f5923d428f59de6fd6aaa
This commit is contained in:
parent
be7aef1f85
commit
c7f7b45a15
@ -440,8 +440,8 @@ struct S3JniAutoExtension {
|
||||
#endif
|
||||
|
||||
/** State for various hook callbacks. */
|
||||
typedef struct S3JniHookState S3JniHookState;
|
||||
struct S3JniHookState{
|
||||
typedef struct S3JniHook S3JniHook;
|
||||
struct S3JniHook{
|
||||
jobject jObj /* global ref to Java instance */;
|
||||
jmethodID midCallback /* callback method. Signature depends on
|
||||
jObj's type */;
|
||||
@ -470,15 +470,15 @@ struct S3JniDb {
|
||||
to receive. */;
|
||||
char * zMainDbName /* Holds any string allocated on behave of
|
||||
SQLITE_DBCONFIG_MAINDBNAME. */;
|
||||
S3JniHookState busyHandler;
|
||||
S3JniHookState collation;
|
||||
S3JniHookState collationNeeded;
|
||||
S3JniHookState commitHook;
|
||||
S3JniHookState progress;
|
||||
S3JniHookState rollbackHook;
|
||||
S3JniHookState trace;
|
||||
S3JniHookState updateHook;
|
||||
S3JniHookState authHook;
|
||||
S3JniHook busyHandler;
|
||||
S3JniHook collation;
|
||||
S3JniHook collationNeeded;
|
||||
S3JniHook commitHook;
|
||||
S3JniHook progress;
|
||||
S3JniHook rollbackHook;
|
||||
S3JniHook trace;
|
||||
S3JniHook updateHook;
|
||||
S3JniHook authHook;
|
||||
#ifdef SQLITE_ENABLE_FTS5
|
||||
jobject jFtsApi /* global ref to s3jni_fts5_api_from_db() */;
|
||||
#endif
|
||||
@ -756,10 +756,18 @@ static jstring s3jni_text16_to_jstring(JNIEnv * const env, const void * const p,
|
||||
}
|
||||
|
||||
/**
|
||||
Requires jx to be a Throwable. Calls its getMessage() method and
|
||||
Requires jx to be a Throwable. Calls its toString() method and
|
||||
returns its value converted to a UTF-8 string. The caller owns the
|
||||
returned string and must eventually sqlite3_free() it. Returns 0
|
||||
if there is a problem fetching the info or on OOM.
|
||||
|
||||
Design note: we use toString() instead of getMessage() because the
|
||||
former includes the exception type's name:
|
||||
|
||||
Exception e = new RuntimeException("Hi");
|
||||
System.out.println(e.toString()); // java.lang.RuntimeException: Hi
|
||||
System.out.println(e.getMessage()); // Hi
|
||||
}
|
||||
*/
|
||||
static char * s3jni_exception_error_msg(JNIEnv * const env, jthrowable jx ){
|
||||
S3JniEnvCache * const jc = S3JniGlobal_env_cache(env);
|
||||
@ -767,7 +775,7 @@ static char * s3jni_exception_error_msg(JNIEnv * const env, jthrowable jx ){
|
||||
jstring msg;
|
||||
char * zMsg;
|
||||
jclass const klazz = (*env)->GetObjectClass(env, jx);
|
||||
mid = (*env)->GetMethodID(env, klazz, "getMessage", "()Ljava/lang/String;");
|
||||
mid = (*env)->GetMethodID(env, klazz, "toString", "()Ljava/lang/String;");
|
||||
IFTHREW{
|
||||
EXCEPTION_REPORT;
|
||||
EXCEPTION_CLEAR;
|
||||
@ -848,7 +856,7 @@ static void s3jni_call_xDestroy(JNIEnv * const env, jobject jObj, jclass klazz){
|
||||
cleared. It is legal to call this when the object has no Java
|
||||
references.
|
||||
*/
|
||||
static void S3JniHookState_unref(JNIEnv * const env, S3JniHookState * const s, int doXDestroy){
|
||||
static void S3JniHook_unref(JNIEnv * const env, S3JniHook * const s, int doXDestroy){
|
||||
if(doXDestroy && s->klazz && s->jObj){
|
||||
s3jni_call_xDestroy(env, s->jObj, s->klazz);
|
||||
}
|
||||
@ -876,7 +884,7 @@ static void S3JniDb_set_aside(S3JniDb * const s){
|
||||
S3JniGlobal.perDb.aUsed = s->pNext;
|
||||
}
|
||||
sqlite3_free( s->zMainDbName );
|
||||
#define UNHOOK(MEMBER,XDESTROY) S3JniHookState_unref(env, &s->MEMBER, XDESTROY)
|
||||
#define UNHOOK(MEMBER,XDESTROY) S3JniHook_unref(env, &s->MEMBER, XDESTROY)
|
||||
UNHOOK(trace, 0);
|
||||
UNHOOK(progress, 0);
|
||||
UNHOOK(commitHook, 0);
|
||||
@ -1473,7 +1481,7 @@ static int CollationState_xCompare(void *pArg, int nLhs, const void *lhs,
|
||||
/* Collation finalizer for use by the sqlite3 internals. */
|
||||
static void CollationState_xDestroy(void *pArg){
|
||||
S3JniDb * const ps = pArg;
|
||||
S3JniHookState_unref( ps->env, &ps->collation, 1 );
|
||||
S3JniHook_unref( ps->env, &ps->collation, 1 );
|
||||
}
|
||||
|
||||
/* State for sqlite3_result_java_object() and
|
||||
@ -2031,24 +2039,24 @@ JDECL(jint,1busy_1handler)(JENV_CSELF, jobject jDb, jobject jBusy){
|
||||
int rc = 0;
|
||||
if(!ps) return (jint)SQLITE_NOMEM;
|
||||
if(jBusy){
|
||||
S3JniHookState * const pHook = &ps->busyHandler;
|
||||
S3JniHook * const pHook = &ps->busyHandler;
|
||||
if(pHook->jObj && (*env)->IsSameObject(env, pHook->jObj, jBusy)){
|
||||
/* Same object - this is a no-op. */
|
||||
return 0;
|
||||
}
|
||||
S3JniHookState_unref(env, pHook, 1);
|
||||
S3JniHook_unref(env, pHook, 1);
|
||||
pHook->jObj = REF_G(jBusy);
|
||||
pHook->klazz = REF_G((*env)->GetObjectClass(env, jBusy));
|
||||
pHook->midCallback = (*env)->GetMethodID(env, pHook->klazz, "xCallback", "(I)I");
|
||||
IFTHREW {
|
||||
S3JniHookState_unref(env, pHook, 0);
|
||||
S3JniHook_unref(env, pHook, 0);
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
if(rc){
|
||||
return rc;
|
||||
}
|
||||
}else{
|
||||
S3JniHookState_unref(env, &ps->busyHandler, 1);
|
||||
S3JniHook_unref(env, &ps->busyHandler, 1);
|
||||
}
|
||||
return jBusy
|
||||
? sqlite3_busy_handler(ps->pDb, s3jni_busy_handler, ps)
|
||||
@ -2058,7 +2066,7 @@ JDECL(jint,1busy_1handler)(JENV_CSELF, jobject jDb, jobject jBusy){
|
||||
JDECL(jint,1busy_1timeout)(JENV_CSELF, jobject jDb, jint ms){
|
||||
S3JniDb * const ps = S3JniDb_for_db(env, jDb, 0, 0);
|
||||
if( ps ){
|
||||
S3JniHookState_unref(env, &ps->busyHandler, 1);
|
||||
S3JniHook_unref(env, &ps->busyHandler, 1);
|
||||
return sqlite3_busy_timeout(ps->pDb, (int)ms);
|
||||
}
|
||||
return SQLITE_MISUSE;
|
||||
@ -2132,7 +2140,7 @@ static void s3jni_collation_needed_impl16(void *pState, sqlite3 *pDb,
|
||||
ps->collationNeeded.midCallback,
|
||||
ps->jDb, (jint)eTextRep, jName);
|
||||
IFTHREW{
|
||||
s3jni_db_exception(env, ps, 0, "collation-needed callback");
|
||||
s3jni_db_exception(env, ps, 0, "collation-needed callback threw");
|
||||
}
|
||||
}
|
||||
UNREF_L(jName);
|
||||
@ -2143,7 +2151,7 @@ JDECL(jint,1collation_1needed)(JENV_CSELF, jobject jDb, jobject jHook){
|
||||
jclass klazz;
|
||||
jobject pOld = 0;
|
||||
jmethodID xCallback;
|
||||
S3JniHookState * const pHook = &ps->collationNeeded;
|
||||
S3JniHook * const pHook = &ps->collationNeeded;
|
||||
int rc;
|
||||
|
||||
if( !ps ) return SQLITE_MISUSE;
|
||||
@ -2154,7 +2162,7 @@ JDECL(jint,1collation_1needed)(JENV_CSELF, jobject jDb, jobject jHook){
|
||||
}
|
||||
if( !jHook ){
|
||||
UNREF_G(pOld);
|
||||
memset(pHook, 0, sizeof(S3JniHookState));
|
||||
memset(pHook, 0, sizeof(S3JniHook));
|
||||
sqlite3_collation_needed(ps->pDb, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
@ -2253,7 +2261,7 @@ static jobject s3jni_commit_rollback_hook(int isCommit, JNIEnv * const env,jobje
|
||||
jclass klazz;
|
||||
jobject pOld = 0;
|
||||
jmethodID xCallback;
|
||||
S3JniHookState * const pHook = isCommit ? &ps->commitHook : &ps->rollbackHook;
|
||||
S3JniHook * const pHook = isCommit ? &ps->commitHook : &ps->rollbackHook;
|
||||
if(!ps){
|
||||
s3jni_db_error(ps->pDb, SQLITE_NOMEM, 0);
|
||||
return 0;
|
||||
@ -2269,7 +2277,7 @@ static jobject s3jni_commit_rollback_hook(int isCommit, JNIEnv * const env,jobje
|
||||
UNREF_G(pOld);
|
||||
pOld = tmp;
|
||||
}
|
||||
memset(pHook, 0, sizeof(S3JniHookState));
|
||||
memset(pHook, 0, sizeof(S3JniHook));
|
||||
if( isCommit ) sqlite3_commit_hook(ps->pDb, 0, 0);
|
||||
else sqlite3_rollback_hook(ps->pDb, 0, 0);
|
||||
return pOld;
|
||||
@ -2396,7 +2404,7 @@ JDECL(jint,1create_1collation)(JENV_CSELF, jobject jDb,
|
||||
jclass klazz;
|
||||
int rc;
|
||||
const char *zName;
|
||||
S3JniHookState * pHook;
|
||||
S3JniHook * pHook;
|
||||
if(!ps) return (jint)SQLITE_NOMEM;
|
||||
pHook = &ps->collation;
|
||||
klazz = (*env)->GetObjectClass(env, oCollation);
|
||||
@ -2416,7 +2424,7 @@ JDECL(jint,1create_1collation)(JENV_CSELF, jobject jDb,
|
||||
pHook->jObj = REF_G(oCollation);
|
||||
pHook->klazz = REF_G(klazz);
|
||||
}else{
|
||||
S3JniHookState_unref(env, pHook, 1);
|
||||
S3JniHook_unref(env, pHook, 1);
|
||||
}
|
||||
return (jint)rc;
|
||||
}
|
||||
@ -2987,7 +2995,7 @@ static int s3jni_xAuth(void* pState, int op,const char*z0, const char*z1,
|
||||
jstring const s1 = z1 ? (*env)->NewStringUTF(env, z1) : 0;
|
||||
jstring const s2 = z2 ? (*env)->NewStringUTF(env, z2) : 0;
|
||||
jstring const s3 = z3 ? (*env)->NewStringUTF(env, z3) : 0;
|
||||
S3JniHookState const * const pHook = &ps->authHook;
|
||||
S3JniHook const * const pHook = &ps->authHook;
|
||||
int rc;
|
||||
|
||||
assert( pHook->jObj );
|
||||
@ -3006,11 +3014,11 @@ static int s3jni_xAuth(void* pState, int op,const char*z0, const char*z1,
|
||||
|
||||
JDECL(jint,1set_1authorizer)(JENV_CSELF,jobject jDb, jobject jHook){
|
||||
S3JniDb * const ps = S3JniDb_for_db(env, jDb, 0, 0);
|
||||
S3JniHookState * const pHook = ps ? &ps->authHook : 0;
|
||||
S3JniHook * const pHook = ps ? &ps->authHook : 0;
|
||||
|
||||
if( !ps ) return SQLITE_MISUSE;
|
||||
else if( !jHook ){
|
||||
S3JniHookState_unref(env, pHook, 0);
|
||||
S3JniHook_unref(env, pHook, 0);
|
||||
return (jint)sqlite3_set_authorizer( ps->pDb, 0, 0 );
|
||||
}else{
|
||||
int rc = 0;
|
||||
@ -3019,7 +3027,7 @@ JDECL(jint,1set_1authorizer)(JENV_CSELF,jobject jDb, jobject jHook){
|
||||
/* Same object - this is a no-op. */
|
||||
return 0;
|
||||
}
|
||||
S3JniHookState_unref(env, pHook, 0);
|
||||
S3JniHook_unref(env, pHook, 0);
|
||||
}
|
||||
pHook->jObj = REF_G(jHook);
|
||||
pHook->klazz = REF_G((*env)->GetObjectClass(env, jHook));
|
||||
@ -3032,12 +3040,12 @@ JDECL(jint,1set_1authorizer)(JENV_CSELF,jobject jDb, jobject jHook){
|
||||
"Ljava/lang/String;"
|
||||
")I");
|
||||
IFTHREW {
|
||||
S3JniHookState_unref(env, pHook, 0);
|
||||
S3JniHook_unref(env, pHook, 0);
|
||||
return s3jni_db_error(ps->pDb, SQLITE_ERROR,
|
||||
"Error setting up Java parts of authorizer hook.");
|
||||
}
|
||||
rc = sqlite3_set_authorizer(ps->pDb, s3jni_xAuth, ps);
|
||||
if( rc ) S3JniHookState_unref(env, pHook, 0);
|
||||
if( rc ) S3JniHook_unref(env, pHook, 0);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@ -3178,7 +3186,7 @@ JDECL(jobject,1update_1hook)(JENV_CSELF, jobject jDb, jobject jHook){
|
||||
jclass klazz;
|
||||
jobject pOld = 0;
|
||||
jmethodID xCallback;
|
||||
S3JniHookState * const pHook = &ps->updateHook;
|
||||
S3JniHook * const pHook = &ps->updateHook;
|
||||
if(!ps){
|
||||
s3jni_db_error(ps->pDb, SQLITE_MISUSE, 0);
|
||||
return 0;
|
||||
@ -3194,7 +3202,7 @@ JDECL(jobject,1update_1hook)(JENV_CSELF, jobject jDb, jobject jHook){
|
||||
UNREF_G(pOld);
|
||||
pOld = tmp;
|
||||
}
|
||||
memset(pHook, 0, sizeof(S3JniHookState));
|
||||
memset(pHook, 0, sizeof(S3JniHook));
|
||||
sqlite3_update_hook(ps->pDb, 0, 0);
|
||||
return pOld;
|
||||
}
|
||||
@ -3328,7 +3336,7 @@ JDECL(void,1do_1something_1for_1developer)(JENV_CSELF){
|
||||
#define SO(T) printf("\tsizeof(" #T ") = %u\n", (unsigned)sizeof(T))
|
||||
SO(void*);
|
||||
SO(S3JniEnvCache);
|
||||
SO(S3JniHookState);
|
||||
SO(S3JniHook);
|
||||
SO(S3JniDb);
|
||||
SO(S3JniClassNames);
|
||||
printf("\t(^^^ %u NativePointerHolder subclasses)\n",
|
||||
|
12
manifest
12
manifest
@ -1,5 +1,5 @@
|
||||
C Lots\sof\sJNI\sinternal\sAPI\srenaming,\sfor\sconsistency,\sand\smoving-around\sof\sutility\sfunctions.\sMake\sit\ssafe\sfor\smore\scallback\stypes\sto\sthrow.
|
||||
D 2023-08-07T10:59:27.774
|
||||
C When\sconverting\sa\sJava\sexception\sto\sa\sdb\serror\smessage,\suse\sThrowable.toString()\sinstead\sof\sgetMessage()\sso\sthat\sthe\sexception\stype's\sname\sis\sincluded.\sMore\sinternal\sAPI\srenaming\sfor\sconsistency.
|
||||
D 2023-08-07T11:18:44.649
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -232,7 +232,7 @@ F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282
|
||||
F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8
|
||||
F ext/jni/GNUmakefile 61d9bbc179a49523a142928455b3297779b9c40f25783ecf1538279e426cbc99
|
||||
F ext/jni/README.md e965674505e105626127ad45e628e4d19fcd379cdafc4d23c814c1ac2c55681d
|
||||
F ext/jni/src/c/sqlite3-jni.c f494d60a14182107758aeebdc967bb5ba344738de592373947fc511ec3a65841
|
||||
F ext/jni/src/c/sqlite3-jni.c e6463b3fc8ef000d9a5dd1649fe96a4cfc5aac21a43276424cf28d72548c5921
|
||||
F ext/jni/src/c/sqlite3-jni.h 6c06cdb1e43ce56544dfbe3335a46174dae15d03337d06e55aa7256f85d2ce1b
|
||||
F ext/jni/src/org/sqlite/jni/Authorizer.java 1308988f7f40579ea0e4deeaec3c6be971630566bd021c31367fe3f5140db892
|
||||
F ext/jni/src/org/sqlite/jni/AutoExtension.java 3409ad8954d6466bf772e6be9379e0e337312b446b668287062845755a16844d
|
||||
@ -2083,8 +2083,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 6e0bd03d0ba9ee8422853241ba1c4e963d158d1f042855c0cb0026701907896e
|
||||
R 2443bcafecde9596198577259670a0d3
|
||||
P 9a494394b9eb28cf88dc5e7075a4b8c682c8e14fdd6837b595bec8011d7e9e72
|
||||
R 482519d6e278134ac56541913ad9c20f
|
||||
U stephan
|
||||
Z 19c29c5513623f28912ff9f11aaa44c7
|
||||
Z 5c40003605167b9b55a6a352144a1fa7
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
9a494394b9eb28cf88dc5e7075a4b8c682c8e14fdd6837b595bec8011d7e9e72
|
||||
2d44720d06d9e50cb037e92981d2473a3ad0b7560f2f5923d428f59de6fd6aaa
|
Loading…
Reference in New Issue
Block a user