android sqlite查询失败,android – 使用MATCH的SQLite查询错误

我正在使用以下查询在SQLite中执行搜索.

public MatrixCursor listViewCursor(String query) {

open();

Cursor dcursor = null;

MatrixCursor cursor = new MatrixCursor(listviewColumns);

Object[] listviewarray = null;

String[] selectionArgs = new String[] { query };

System.out.println("Selectionarg = "+selectionArgs.toString());

if (query == null) {

try {// this works

dcursor = database.query(LA_DATABASE_TABLE, listviewColumns,

null, null, null, null, LA_TEST_NAME);

} catch (Exception e) {

e.printStackTrace();

}

} else

try {// this don't work!!!

dcursor = database.query(LA_DATABASE_TABLE, listviewColumns,

LA_TEST_NAME + " MATCH ?", new String[] { query }, null, null, null);

} catch (Exception e) {

e.printStackTrace();

}

System.out.println("dcursor count = "+dcursor.getCount());

listviewarray = new Object[dcursor.getColumnCount()];

if (dcursor.moveToFirst()) {

do {

for (int i = 0; i < dcursor.getColumnCount(); i++) {

listviewarray[i] = dcursor.getString(i);

}

cursor.addRow(listviewarray);

System.out.println(dcursor.getString(1));

} while (dcursor.moveToNext());

} else

return null;

close();

return cursor;

}

但是我收到以下错误.

0

1-01 04:36:27.376: I/SqliteDatabaseCpp(3171): sqlite returned: error code = 1, msg = statement aborts at 7: [SELECT _id, suggest_text_1, test_value_1, test_value_2, test_type_1 FROM la_table WHERE suggest_text_1 MATCH ?] unable to use function MATCH in the requested context, db=/data/data/com.assistant.lab.royale/databases/la_db

01-01 04:36:27.376: E/SQLiteQuery(3171): exception: SQL logic error or missing database; query: SELECT _id, suggest_text_1, test_value_1, test_value_2, test_type_1 FROM la_table WHERE suggest_text_1 MATCH ?

01-01 04:36:27.376: D/AndroidRuntime(3171): Shutting down VM

01-01 04:36:27.376: W/dalvikvm(3171): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)

01-01 04:36:27.465: E/AndroidRuntime(3171): FATAL EXCEPTION: main

01-01 04:36:27.465: E/AndroidRuntime(3171): android.database.sqlite.SQLiteException: SQL logic error or missing database

01-01 04:36:27.465: E/AndroidRuntime(3171): at android.database.sqlite.SQLiteQuery.nativeFillWindow(Native Method)

01-01 04:36:27.465: E/AndroidRuntime(3171): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:86)

01-01 04:36:27.465: E/AndroidRuntime(3171): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:164)

01-01 04:36:27.465: E/AndroidRuntime(3171): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:156)

01-01 04:36:27.465: E/AndroidRuntime(3171): at com.assistant.lab.royale.DataSource.listViewCursor(DataSource.java:52)

01-01 04:36:27.465: E/AndroidRuntime(3171): at com.assistant.lab.royale.LabAssistant.filterListView(LabAssistant.java:32)

01-01 04:36:27.465: E/AndroidRuntime(3171): at com.assistant.lab.royale.LabAssistant.onQueryTextChange(LabAssistant.java:54)

01-01 04:36:27.465: E/AndroidRuntime(3171): at android.widget.SearchView.onTextChanged(SearchView.java:1091)

01-01 04:36:27.465: E/AndroidRuntime(3171): at android.widget.SearchView.access$2000(SearchView.java:90)

01-01 04:36:27.465: E/AndroidRuntime(3171): at android.widget.SearchView$11.onTextChanged(SearchView.java:1548)

01-01 04:36:27.465: E/AndroidRuntime(3171): at android.widget.TextView.sendOnTextChanged(TextView.java:7634)

为什么会这样呢?

编辑:

我使用dcursor = database.query修复它(LA_DATABASE_TABLE,listviewColumns,LA_TEST_NAME“LIKE’%”查询“%’”,null,null,null,null);但我想知道为什么上面的代码不起作用.似乎 ?没有得到适当的替换.

解决方法:

并确保您创建了这样的虚拟表

CREATE VIRTUAL TABLE enrondata1 USING fts3(content TEXT);

这不是一般的

CREATE TABLE enrondata2(content TEXT);

标签:android,sqlite

来源: https://codeday.me/bug/20190902/1790130.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值