Android中的SQLite中的变量为空

时间:2016-06-27 11:32:01

标签: android sqlite

我的提供者是

public Cursor query(Uri  uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if(uriMatcher.match(uri) == TEXTS_ID)  
        selection = DBOpenHelper.text_ID + "=" + uri.getLastPathSegment();
    return database.query(DBOpenHelper.TABLE_textS, DBOpenHelper.ALL_COLUMNS, selection, selectionArgs, null, null,DBOpenHelper.text_CREATED + " DESC");
}

我称之为:

String [] cursorArgs = new String [] {"0"};
String selection = "textId=";
return new CursorLoader(this, textsProvider.CONTENT_URI, null, selection, cursorArgs, null); 

如你所见,我想在textId = 0

时发短信
Caused by: android.database.sqlite.SQLiteException: near "ORDER": syntax error (code 1): , while compiling: SELECT _id, textId, textText, textCreate FROM texts WHERE textId= ORDER BY textCreated DESC

1 个答案:

答案 0 :(得分:0)

SQLite之后,?的选择必须为=,因此请尝试

String selection = "textId=?";