Skip to content

Commit 0b56007

Browse files
Adding rawExecSQL to SQLiteDatabase that will not throw exceptions on SELECT statements that don't return rows from the command (such as calling custom functions that are loaded from load_extension)
1 parent 2b2aca3 commit 0b56007

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

jni/net_sqlcipher_database_SQLiteDatabase.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ static void registerLoggingFunc(const char *path) {
9292
loggingFuncSet = true;
9393
}
9494

95+
void native_rawExecSQL(JNIEnv* env, jobject object, jstring sql)
96+
{
97+
sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
98+
char const * sqlCommand = env->GetStringUTFChars(sql, NULL);
99+
int status = sqlite3_exec(handle, sqlCommand, NULL, NULL, NULL);
100+
env->ReleaseStringUTFChars(sql, sqlCommand);
101+
if(status != SQLITE_OK){
102+
throw_sqlite3_exception(env, handle);
103+
}
104+
}
105+
95106
/* public native void setICURoot(String path); */
96107
void setICURoot(JNIEnv* env, jobject object, jstring ICURoot)
97108
{
@@ -467,6 +478,7 @@ static JNINativeMethod sMethods[] =
467478
{"native_getDbLookaside", "()I", (void *)native_getDbLookaside},
468479
{"releaseMemory", "()I", (void *)native_releaseMemory},
469480
{"setICURoot", "(Ljava/lang/String;)V", (void *)setICURoot},
481+
{"native_rawExecSQL", "(Ljava/lang/String;)V", (void *)native_rawExecSQL},
470482
};
471483

472484
int register_android_database_SQLiteDatabase(JNIEnv *env)

src/net/sqlcipher/database/SQLiteDatabase.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,32 @@ public void execSQL(String sql) throws SQLException {
18051805
}
18061806
}
18071807

1808+
public void rawExecSQL(String sql){
1809+
long timeStart = SystemClock.uptimeMillis();
1810+
lock();
1811+
if (!isOpen()) {
1812+
throw new IllegalStateException("database not open");
1813+
}
1814+
logTimeStat(mLastSqlStatement, timeStart, GET_LOCK_LOG_PREFIX);
1815+
try {
1816+
native_rawExecSQL(sql);
1817+
} catch (SQLiteDatabaseCorruptException e) {
1818+
onCorruption();
1819+
throw e;
1820+
} finally {
1821+
unlock();
1822+
}
1823+
1824+
// Log commit statements along with the most recently executed
1825+
// SQL statement for disambiguation. Note that instance
1826+
// equality to COMMIT_SQL is safe here.
1827+
if (sql == COMMIT_SQL) {
1828+
logTimeStat(mLastSqlStatement, timeStart, COMMIT_SQL);
1829+
} else {
1830+
logTimeStat(sql, timeStart, null);
1831+
}
1832+
}
1833+
18081834
/**
18091835
* Execute a single SQL statement that is not a query. For example, CREATE
18101836
* TABLE, DELETE, INSERT, etc. Multiple statements separated by ;s are not
@@ -2355,4 +2381,6 @@ private static ArrayList<Pair<String, String>> getAttachedDbs(SQLiteDatabase dbO
23552381
* @return int value of SQLITE_DBSTATUS_LOOKASIDE_USED
23562382
*/
23572383
private native int native_getDbLookaside();
2384+
2385+
private native void native_rawExecSQL(String sql);
23582386
}

0 commit comments

Comments
 (0)