本文整理汇总了Java中android.database.sqlite.SQLiteQueryBuilder.setProjectionMap方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteQueryBuilder.setProjectionMap方法的具体用法?Java SQLiteQueryBuilder.setProjectionMap怎么用?Java SQLiteQueryBuilder.setProjectionMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.sqlite.SQLiteQueryBuilder
的用法示例。
在下文中一共展示了SQLiteQueryBuilder.setProjectionMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
/**
* Query the database
*/
private Cursor query(String selection, String[] selectionArgs) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
// main INNER JOIN frequency ON (main._id=freq.pair_id)
qb.setTables(MAIN_TABLE_NAME + " INNER JOIN " + FREQ_TABLE_NAME + " ON ("
+ MAIN_TABLE_NAME + "." + MAIN_COLUMN_ID + "=" + FREQ_TABLE_NAME + "."
+ FREQ_COLUMN_PAIR_ID +")");
qb.setProjectionMap(sDictProjectionMap);
// Get the database and run the query
SQLiteDatabase db = sOpenHelper.getReadableDatabase();
Cursor c = qb.query(db,
new String[] { MAIN_COLUMN_WORD1, MAIN_COLUMN_WORD2, FREQ_COLUMN_FREQUENCY },
selection, selectionArgs, null, null, null);
return c;
}
示例2: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
/**
* Performs a database query.
* @param selection The selection clause
* @param selectionArgs Selection arguments for "?" components in the selection
* @param columns The columns to return
* @return A Cursor over all rows matching the query
*/
private Cursor query(String selection, String[] selectionArgs, String[] columns) {
/* The SQLiteBuilder provides a map for all possible columns requested to
* actual columns in the database, creating a simple column alias mechanism
* by which the ContentProvider does not need to know the real column names
*/
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
builder.setTables(FTS_VIRTUAL_TABLE);
builder.setProjectionMap(mColumnMap);
Cursor cursor = builder.query(mDatabaseOpenHelper.getReadableDatabase(),
columns, selection, selectionArgs, null, null, null);
if (cursor == null) {
return null;
} else if (!cursor.moveToFirst()) {
cursor.close();
return null;
}
return cursor;
}
示例3: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(TABLE_NAME);
qb.setProjectionMap(values);
switch (uriMatcher.match(uri)) {
case API:
break;
case API_GET:
qb.appendWhere(id + "=" + uri.getLastPathSegment());
break;
default:
throw new IllegalArgumentException("Unknown URI : " + uri);
}
if (sortOrder == null || sortOrder.equals("")) {
sortOrder = name;
}
Cursor c = qb.query(db, projection, selection, selectionArgs, null,
null, sortOrder);
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
示例4: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(sqLiteOpenHelper.TABLE_NAME);
switch (uriMatcher.match(uri)){
case PLACES_ID:
queryBuilder.setProjectionMap(PlaceMap);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (sortOrder == null || sortOrder == ""){
sortOrder = sqLiteOpenHelper.ID;
}
Cursor cursor = queryBuilder.query(database, projection, selection,
selectionArgs, null, null, sortOrder);
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
示例5: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(Settings.TABLE_NAME);
switch (sUriMatcher.match(uri)){
case SETTINGS:
qb.setProjectionMap(sProjectionMap);
break;
case SETTINGS_ID:
qb.setProjectionMap(sProjectionMap);
qb.appendWhere(
Settings._ID +"="+uri.getPathSegments().get(1)
);
break;
default:
throw new IllegalArgumentException("Unknown uri: "+uri);
}
SQLiteDatabase db = mOPenHelper.getReadableDatabase();
Cursor c = qb.query(db,projection,selection,selectionArgs,null,null,sortOrder);
c.setNotificationUri(getContext().getContentResolver(),uri);
return c;
}
示例6: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
switch (URI_MATCHER.match(uri)) {
case DEBUG_CONFIG_CODE:
qb.setTables(DEBUG_CONFIG_TABLE);
qb.setProjectionMap(projectionMap);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
if (getContext() != null && getContext().getContentResolver() != null) {
c.setNotificationUri(getContext().getContentResolver(), uri);
}
return c;
}
示例7: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
private Cursor query(String selection, String[] selectionArgs) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(AUTODICT_TABLE_NAME);
qb.setProjectionMap(sDictProjectionMap);
// Get the database and run the query
SQLiteDatabase db = sOpenHelper.getReadableDatabase();
Cursor c = qb.query(db, null, selection, selectionArgs, null, null,
DEFAULT_SORT_ORDER);
return c;
}
示例8: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder();
sqlBuilder.setTables(EVENTS_TABLE);
if(uriMatcher.match(uri) == 1){
sqlBuilder.setProjectionMap(mMap);
}else if(uriMatcher.match(uri) == 2){
sqlBuilder.setProjectionMap(mMap);
sqlBuilder.appendWhere(ID + "=?");
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,new String[] {uri.getLastPathSegment()});
}else if(uriMatcher.match(uri) == 3){
sqlBuilder.setProjectionMap(mMap);
sqlBuilder.appendWhere(START + ">=? OR ");
sqlBuilder.appendWhere(END + "<=?");
List<String> list = uri.getPathSegments();
String start = list.get(1);
String end = list.get(2);
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,new String[] {start,end});
}
if(sortOrder == null || sortOrder == "")
sortOrder = START + " COLLATE LOCALIZED ASC";
Cursor c = sqlBuilder.query(db, projection, selection, selectionArgs,null,null, sortOrder);
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
示例9: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
switch (sUriMatcher.match(uri)) {
case ITEMS:
qb.setTables(TABLE_NAME);
qb.setProjectionMap(sProjectionMap);
break;
case ITEM_ID:
qb.setTables(TABLE_NAME);
qb.setProjectionMap(sProjectionMap);
qb.appendWhere(ShoppingList._ID + "=" + uri.getPathSegments().get(1));
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
// If no sort order is specified use the default
String orderBy;
if (TextUtils.isEmpty(sortOrder)) {
orderBy = ShoppingList.DEFAULT_SORT_ORDER;
} else {
orderBy = sortOrder;
}
// Get the database and run the query
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
// Tell the cursor what uri to watch, so it knows when its source data changes
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
示例10: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(NOTES_TABLE_NAME);
switch (sUriMatcher.match(uri)) {
case NOTES:
qb.setProjectionMap(sNotesProjectionMap);
break;
case NOTE_ID:
qb.setProjectionMap(sNotesProjectionMap);
qb.appendWhere(NoteColumns._ID + "=" + uri.getPathSegments().get(1));
break;
case LIVE_FOLDER_NOTES:
qb.setProjectionMap(sLiveFolderProjectionMap);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
// If no sort order is specified use the default
String orderBy;
if (TextUtils.isEmpty(sortOrder)) {
orderBy = NoteColumns.DEFAULT_SORT_ORDER;
} else {
orderBy = sortOrder;
}
// Get the database and run the query
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
// Tell the cursor what uri to watch, so it knows when its source data changes
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
示例11: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
@Override
public Cursor query(Uri uri, String[] projection, String selection,String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(STUDENTS_TABLE_NAME);
switch (uriMatcher.match(uri)) {
case STUDENTS:
qb.setProjectionMap(STUDENTS_PROJECTION_MAP);
break;
case STUDENT_ID:
qb.appendWhere( _ID + "=" + uri.getPathSegments().get(1));
Log.e("appendWhere",uri.getPathSegments().get(1).toString());
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (sortOrder == null || sortOrder == ""){
/**
* By default sort on student names
*/
sortOrder = NAME;
}
Cursor c = qb.query(db, projection, selection, selectionArgs,null, null, sortOrder);
/**
* register to watch a content URI for changes
*/
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
开发者ID:OWASP,项目名称:MSTG-Hacking-Playground,代码行数:34,代码来源:OMTG_CODING_003_SQL_Injection_Content_Provider_Implementation.java
示例12: findIssueById
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
private Cursor findIssueById(Uri uri, String[] projection) {
final String issueId = uri.getLastPathSegment();
final SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(IssueEntry.TABLE_NAME
+ " INNER JOIN " + UserEntry.TABLE_NAME
+ " ON " + IssueEntry.TABLE_NAME + ".CREATED_USER_ID = " + UserEntry.TABLE_NAME + "._ID " +
"LEFT OUTER JOIN " + UserEntry.TABLE_NAME + " AS ASSIGNEE ON "
+ IssueEntry.TABLE_NAME + ".ASSIGNEE_ID = ASSIGNEE._ID " +
"INNER JOIN " + IssueTypeEntry.TABLE_NAME + " ON " + IssueEntry.TABLE_NAME +
".TYPE_ID = " + IssueTypeEntry.TABLE_NAME + "._ID");
final Map<String, String> columnMap = new HashMap<>();
columnMap.put(UserEntry.USER_PREFIX + UserEntry.THUMBNAIL_URL, UserEntry.TABLE_NAME + "." + UserEntry.THUMBNAIL_URL);
columnMap.put(UserEntry.USER_PREFIX + UserEntry.NAME, UserEntry.TABLE_NAME + "." + UserEntry.NAME);
columnMap.put(IssueEntry.CREATED_DATE, IssueEntry.CREATED_DATE);
columnMap.put(IssueEntry.DESCRIPTION, IssueEntry.DESCRIPTION);
columnMap.put(UserEntry.ASSIGNEE_PREFIX + UserEntry.NAME, UserEntry.ASSIGNEE_ALIAS + "." + UserEntry.NAME);
columnMap.put(IssueEntry.STATUS, IssueEntry.STATUS);
columnMap.put(IssueEntry.PRIORITY, IssueEntry.PRIORITY);
columnMap.put(IssueTypeEntry.PREFIX + IssueTypeEntry.NAME, IssueTypeEntry.TABLE_NAME + "." + IssueTypeEntry.NAME);
columnMap.put(IssueEntry.MILESTONES, IssueEntry.MILESTONES);
columnMap.put(IssueEntry.SUMMARY, IssueEntry.SUMMARY);
columnMap.put(IssueEntry.URL, IssueEntry.URL);
queryBuilder.setProjectionMap(columnMap);
queryBuilder.appendWhere(IssueEntry.TABLE_NAME + "." + IssueEntry._ID + "=");
queryBuilder.appendWhere("'" + issueId + "'");
final SQLiteDatabase db = mOpenHelper.getReadableDatabase();
return queryBuilder.query(
db,
projection,
null,
null,
null,
null,
null);
}
示例13: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
@Override
//查询操作
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
{
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
switch (sUriMatcher.match(uri))
{
case CALENDAR:
qb.setTables(CalendarColumn_TABLE_NAME);
qb.setProjectionMap(sCalendarColumnProjectionMap);
break;
case CALENDAR_ID:
qb.setTables(CalendarColumn_TABLE_NAME);
qb.setProjectionMap(sCalendarColumnProjectionMap);
qb.appendWhere(CalendarColumn._ID + "=" + uri.getPathSegments().get(1));
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
String orderBy;
if (TextUtils.isEmpty(sortOrder))
{
orderBy = CalendarColumns.CalendarColumn.DEFAULT_SORT_ORDER;
}
else
{
orderBy = sortOrder;
}
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
示例14: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
UriMatch match = UriMatch.get(uriMatcher.match(uri));
qb.setProjectionMap(null); //this should let all the columns through TODO change this later if necessary
qb.setTables(match.Table.Name);
//TODO implement the fallback default order later
// Get the database and run the query
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
return c;
}
示例15: query
import android.database.sqlite.SQLiteQueryBuilder; //导入方法依赖的package包/类
@Override
public synchronized Cursor query(Uri uri, String[] projection,
String selection, String[] selectionArgs, String sortOrder) {
if (Utils.doLog())
Log.d(CLASSNAME, String.format(
"query() >> uri = %s, selection = %s, sortOrder = %s", uri,
selection, sortOrder));
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(HistoryContract.TABLE_NAME);
qb.setProjectionMap(MAP_COLUMNS);
SQLiteDatabase db = null;
Cursor cursor = null;
/*
* Choose the projection and adjust the "where" clause based on URI
* pattern-matching.
*/
switch (URI_MATCHER.match(uri)) {
case URI_HISTORY: {
if (Arrays.equals(projection,
new String[] { HistoryContract._COUNT })) {
db = mHistoryHelper.getReadableDatabase();
cursor = db.rawQuery(
String.format(
"SELECT COUNT(*) AS %s FROM %s %s",
HistoryContract._COUNT,
HistoryContract.TABLE_NAME,
selection != null ? String.format("WHERE %s",
selection) : "").trim(), null);
}
break;
}// URI_HISTORY
/*
* If the incoming URI is for a single history item identified by its
* ID, chooses the history item ID projection, and appends
* "_ID = <history-item-ID>" to the where clause, so that it selects
* that single history item.
*/
case URI_HISTORY_ID: {
qb.appendWhere(DbUtils.SQLITE_FTS_COLUMN_ROW_ID + " = "
+ uri.getLastPathSegment());
break;
}// URI_HISTORY_ID
default:
throw new IllegalArgumentException("UNKNOWN URI " + uri);
}
if (TextUtils.isEmpty(sortOrder))
sortOrder = HistoryContract.DEFAULT_SORT_ORDER;
/*
* Opens the database object in "read" mode, since no writes need to be
* done.
*/
if (Utils.doLog())
Log.d(CLASSNAME,
String.format("Going to SQLiteQueryBuilder >> db = %s", db));
if (db == null) {
db = mHistoryHelper.getReadableDatabase();
/*
* Performs the query. If no problems occur trying to read the
* database, then a Cursor object is returned; otherwise, the cursor
* variable contains null. If no records were selected, then the
* Cursor object is empty, and Cursor.getCount() returns 0.
*/
cursor = qb.query(db, projection, selection, selectionArgs, null,
null, sortOrder);
}
cursor = appendNameAndRealUri(cursor);
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}