0

PREF_NAME、PREF_STATUS - 文本

它给了我这个错误:

07-02 14:08:07.457: E/AndroidRuntime(17295): android.database.sqlite.SQLiteException: near "?": syntax error: , while compiling: SELECT ? FROM ? WHERE ? = ?

我正在使用的代码是:

Cursor c = db.rawQuery("SELECT ? FROM ? WHERE ? = ?", new String[]{ PREF_STATUS,
   PREF_TABLE, PREF_NAME, assigned_pref_name });
4

3 回答 3

3

根据文档,您只能输入“?” 关于 where 子句:

public Cursor rawQuery (String sql, String[] selectionArgs)

Parameters
sql the SQL query. The SQL string must not be ; terminated
selectionArgs   You may include ?s in where clause in the query, which will be replaced by the values from selectionArgs. The values will be bound as Strings.
于 2012-07-02T12:24:47.630 回答
0

SELECT关键字之后你有一个?而不是类似的东西*

于 2012-07-02T12:24:53.493 回答
0

我猜您想将assigned_pref_name 作为字符串而不是变量名传递,所以:

   Cursor c = db.rawQuery(
              "SELECT ? FROM ? WHERE ? = ?",
                new String[]{
                PREF_STATUS,
                PREF_TABLE,
                PREF_NAME, 
                "assigned_pref_name" //as a string 
          });
于 2012-07-02T12:26:51.533 回答