使用selectionArgs查询不起作用

时间:2018-01-20 14:59:49

标签: java android sqlite

我有以下代码,当我使用它时,我得到了?而不是selectionArgs。为什么会这样?

String enStr = "en", deStr= "de";
String[] projection = {
        _id,
        en_word,
        de_word};

String selection = "translate_id = ?" + " AND "
                + "en_id = ?" + " AND "
                + "de_id = ? ";
String[] selectionArgs = { String.valueOf("1"), "en", "de" };

return new CursorLoader(this,   // Parent activity context
        currentUri,
        projection,             // Columns to include in the resulting Cursor
        selection,              // No selection clause
        selectionArgs,          // No selection arguments
        null);                  // Default sort order

结果我得到了这个查询(参见?而不是selectionArgs):

SELECT
_id, en_word, de_word
from
translate, en, de
WHERE
translate_id = 1 AND en_id = ? AND de_id = ?;

如果我使用此代码,我会得到一个正常的查询(向我显示表的内容)。我刚刚用一个块选择更改了selectionArgs。

String enStr = "en", deStr= "de";
String selection = "translate_id = 1" + " AND "
                + "en_id = " + enStr + " AND "
                + "de_id = ? " + deStr;

return new CursorLoader(this,   // Parent activity context
        currentUri,
        projection,             // Columns to include in the resulting Cursor
        selection,              // No selection clause
        null,          // No selection arguments
        null);                  // Default sort order

SELECT
_id, en_word, de_word
from
translate, en, de
WHERE
translate_id = 1 AND en_id = "en" AND de_id = "de";

那么,为什么一切都在第二种情况下起作用,并且在第一种情况下不起作用。我在哪里弄错了?

0 个答案:

没有答案