我正在使用以下查询在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

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐