ReviewOS

also looking at this

craft-native/craft

feat(android): dbExecute and dbQuery in Zig — ratchet 84 → 82

#160
Merged glennmichael123 wants to merge feat/android-sqlite into main
7 files +541 -3
packages/android/templates/CraftNative.kt.templatemodified+30-0
Changes to packages/android/templates/CraftNative.kt.template
@@ -2,6 +2,7 @@ package com.craft.runtime
22
33import android.app.Activity
44import android.content.SharedPreferences
5import android.database.sqlite.SQLiteDatabase
56import org.json.JSONObject
67
78/**
@@ -110,6 +111,8 @@ object CraftNative {
110111 private external fun nativeDeleteCalendarEvent(activity: Activity, eventId: String): Boolean
111112 private external fun nativeGetCalendarEvents(activity: Activity, startDateMs: Long, endDateMs: Long): Boolean
112113 private external fun nativeCreateCalendarEvent(activity: Activity, eventJson: String): Boolean
114 private external fun nativeDbExecute(database: SQLiteDatabase, sql: String, paramsJson: String): Boolean
115 private external fun nativeDbQuery(database: SQLiteDatabase, sql: String, paramsJson: String): Boolean
113116
114117 /**
115118 * `getDeviceInfo`, or null to use the Kotlin implementation.
@@ -385,4 +388,31 @@ object CraftNative {
385388 false
386389 }
387390 }
391
392 /**
393 * Returns whether Zig took the statement.
394 *
395 * The connection is passed in rather than opened: the Kotlin caches one
396 * `SQLiteDatabase` so that a BEGIN in one call and a COMMIT in the next
397 * reach the same connection, and a second one opened by Zig would take
398 * locks against the first for no visible reason.
399 */
400 fun dbExecute(database: SQLiteDatabase, sql: String, paramsJson: String): Boolean {
401 if (!isAvailable) return false
402 return try {
403 nativeDbExecute(database, sql, paramsJson)
404 } catch (e: UnsatisfiedLinkError) {
405 false
406 }
407 }
408
409 /** The same, for a statement that returns rows. */
410 fun dbQuery(database: SQLiteDatabase, sql: String, paramsJson: String): Boolean {
411 if (!isAvailable) return false
412 return try {
413 nativeDbQuery(database, sql, paramsJson)
414 } catch (e: UnsatisfiedLinkError) {
415 false
416 }
417 }
388418}