I am using the following query to fetch a row with a particular mid.
Cursor mCursor = mDb.query(true, DATABASE_TABLE, new String[] { KEY_ROWID, "actionData", "mid" }, "mid" + "=" + mid, null, null, null, null, null);
I however get an 开发者_运维知识库sqlite
exception when I try to do the same. Any ideas?
The exception is -
Error: android.database.sqlite.SQLiteException: no such column: qVEl3: , while compiling: SELECT DISTINCT _id, actionData, mid FROM notifs WHERE mid=qVEl3
You missed the quotations:
SELECT DISTINCT _id, actionData, mid FROM notifs WHERE mid='qVEl3'
So your Android code should be :
Cursor mCursor = mDb.query(true, DATABASE_TABLE, new String[]
{ KEY_ROWID, "actionData", "mid" },
"mid=?", new String[] {mid}, null, null, null, null);
(that will prevent SQL injection too)
You'll want to use query parameters to avoid issues with quotes:
Cursor mCursor = mDb.query(
true,
DATABASE_TABLE,
new String[] { KEY_ROWID, "actionData", "mid" },
"mid = ?", // the ? is a placeholder.
new String[] { mid }, // sqlite will put the value of mid into the placeholder above.
null,
null,
null,
null);
精彩评论