You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android系统中SQLite执行PRAGMA compile_options无输出,如何获取编译选项?

Android平台获取SQLite compile_options无输出的解决办法

你的代码里用SQLiteDatabase.query()执行PRAGMA compile_options是问题根源——query()方法是为标准SELECT查询设计的,对PRAGMA这类特殊SQLite指令的兼容性很差,导致无法正确返回结果。

改用rawQuery()方法执行PRAGMA命令即可解决,同时建议用use块自动管理Cursor资源,避免内存泄漏:

private fun getChunkSizeFromSqlite() {
    val db = BundleStorageProvider.getDb(mPlatformType) ?: return

    db.rawQuery("PRAGMA compile_options", null).use { cursor ->
        while (cursor.moveToNext()) {
            val compileOption = cursor.getString(0)
            KxbLog.i("hello", compileOption)
        }
    }
}

额外注意点

  • 确保BundleStorageProvider.getDb()返回的是有效的、已打开的SQLiteDatabase实例,若数据库未正确初始化,也会导致无输出。
  • 部分定制Android ROM可能对SQLite做了裁剪,极少数情况下可能限制PRAGMA指令的访问,但这种情况非常罕见。

内容的提问来源于stack exchange,提问作者Chris.Jiang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 07:18:11