-1

sqlite android の LIKE ステートメントに問題がありました。私は理解するのに1時間かかりましたが、エラー部分を取得できません。誰が私の間違いを知っていますか?

    public Cursor getSearch(String id) {

        String[] args = { id };


        return (database.rawQuery("SELECT " + SQLiteHelper.product_id
                + " as _id," 
                + SQLiteHelper.productName + " ," +SQLiteHelper.productDesp
                + "," + SQLiteHelper.productQtty + ","
                +SQLiteHelper.product_CategoryF+" FROM " 
                + SQLiteHelper.productTable+"  WHERE "
                + SQLiteHelper.productName +" LIKE 'id%'",null));
}

エラーメッセージ

 bind or column index out of range: handle 0x5e3ec0

誰かが私の間違いを知っていますか?

解決

return (database.rawQuery("SELECT " + SQLiteHelper.product_id
                + " as _id," 
                + SQLiteHelper.productName + " ," +SQLiteHelper.productDesp
                + "," + SQLiteHelper.productQtty + ","
                +SQLiteHelper.product_CategoryF+" FROM " 
                + SQLiteHelper.productTable+"  WHERE "
                + SQLiteHelper.productName +" LIKE '"+id+"%'",null));
4

1 に答える 1

2

そのような SQL を作成する必要はありません。rawQuery引数のバインドが非常に簡単になります。

rawQuery("SELECT ? as _id, ?, ?, ?, ? FROM ? WHERE ? LIKE 'id%'", new String[] {SQLiteHelper.product_id, SQLiteHelper.productName, SQLiteHelper.productDesp, SQLiteHelper.productQtty, SQLiteHelper.product_CategoryF, SQLiteHelper.productTable, SQLiteHelper.productName});

コードに関する限り、,"+CategoryF 行の通知は+",

    return (database.rawQuery("SELECT " + SQLiteHelper.product_id
            + " as _id," 
            + SQLiteHelper.productName + " ," +SQLiteHelper.productDesp
            + "," + SQLiteHelper.productQtty + ","
            ,"+SQLiteHelper.product_CategoryF+" FROM " 
            + SQLiteHelper.productTable+"  WHERE "
            + SQLiteHelper.productName +" LIKE 'id%'",null));
于 2012-12-07T15:15:09.957 に答える