首页 > 解决方案 > 如何在 SQLite db 中搜索多个列?

问题描述

尝试在 SQLite 数据库的多个列中搜索时遇到问题。这是我当前的代码

String whereClause;
    if (!suchwort.contains("%")){  // Abfrage mit Wildcard?
        whereClause = WoerterbuchContract.WoerterbuchEintraege.COLUMN_NAME_WORT_DEUTSCH
                        + " = '"+suchwort+"'" ;}


    else {
        whereClause = WoerterbuchContract.WoerterbuchEintraege.COLUMN_NAME_WORT_DEUTSCH
                        +" like '"+suchwort+"'";}


    Cursor ergCursor = db.query(
            WoerterbuchContract.WoerterbuchEintraege.TABLE_NAME,  // The table to query
            projection,                               // The columns to return
            whereClause,                              // WHERE clause
            null,                                     // no values for the WHERE clause
            null,                                     // don't group the rows
            null,                                     // don't filter by row groups
            sortOrder                                 // The sort order
    );

我尝试在 whereClause 中添加列,但总是出现编译器错误。

标签: androiddatabasesqliteandroid-sqlite

解决方案


推荐阅读