gpt4 book ai didi

android - queryBuilder.appendWhere() 的意义何在?安卓

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:48 26 4
gpt4 key购买 nike

这里使用 queryBuilder.appendWhere() 有什么意义?在Cursor cursor = queryBuilder.query()中设置where子句是不是简单多了?还是两种设置“where”子句的方式不同?

  public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {

// Uisng SQLiteQueryBuilder instead of query() method
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();

// Check if the caller has requested a column which does not exists
checkColumns(projection);

// Set the table
queryBuilder.setTables(TodoTable.TABLE_TODO);

int uriType = sURIMatcher.match(uri);
switch (uriType) {
case TODOS:
break;
case TODO_ID:
// Adding the ID to the original query
queryBuilder.appendWhere(TodoTable.COLUMN_ID + "="
+ uri.getLastPathSegment());
break;
default:
throw new IllegalArgumentException("Unknown URI: " + uri);
}

SQLiteDatabase db = database.getWritableDatabase();
Cursor cursor = queryBuilder.query(db, projection, selection,
selectionArgs, null, null, sortOrder);
// Make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(), uri);

return cursor;
}

最佳答案

如果您要根据条件构建 WHERE 子句的各个部分,则可以使用 appendWhere()

关于android - queryBuilder.appendWhere() 的意义何在?安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13543023/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com