【问题标题】:SQLite SELECT no longer works in Android API 21 but did in 18SQLite SELECT 不再适用于 Android API 21,但适用于 18
【发布时间】:2015-01-22 06:00:10
【问题描述】:

我编写了一个访问外部存储上的 SQLite 数据库的应用程序。该应用程序在我的 Nexus 4 和模拟器上运行良好,适用于 Android 4.4。由于我将手机升级到 Android 5,它不再显示 SQLite 数据库中的任何数据。 API 21 上的模拟器也没有显示任何数据。

没有抛出错误或异常。 API 21 上的数据库游标只是空的。

数据库是这样打开的:

String path = myContext.getExternalFilesDir(null).getAbsolutePath() + File.separator + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READWRITE);

查询是这样执行的:

Cursor cur = myDataBase.rawQuery("SELECT * FROM employee WHERE employee match ? " +
    "ORDER BY firstname, lastname LIMIT 100",
    new String[] { "*" + queryString+ "*" });

while (cur.moveToNext()) {
    persons.add(getPerson(cur)); // never reaches this since API 21
}
cur.close();

从 18 到 21 发生了什么变化?

完整的源代码可以在这里找到:https://github.com/sebastianhaeni/Contacts

【问题讨论】:

  • Manifest 中的目标 sdk?
  • 用 21 和 18 试过,结果一样
  • dbHelper 的 onCreate 是否被调用?
  • 该路径还在被应用访问吗?
  • 看这个。这可能是因为 Android Lollipop 为 SQLite 引入了重大更改:stackoverflow.com/questions/26816561/…

标签: java android sqlite android-5.0-lollipop


【解决方案1】:

Android 5 中的 SQLite MATCH 与 Android

前缀 '*' 在 5.0 之前被简单地忽略了。从 5.0 开始,它会搜索以 '*' 开头的字符串。通配符只能用作后缀。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 2019-10-14
    • 1970-01-01
    • 2019-06-09
    • 2019-07-27
    • 2011-12-24
    • 1970-01-01
    相关资源
    最近更新 更多