use of android.database.sqlite.SQLiteDatabase in project ListenerMusicPlayer by hefuyicoder.
the class RecentStore method removeItem.
/**
* 删除某曲目的播放记录
* @param ids
*/
public void removeItem(final long[] ids) {
final SQLiteDatabase database = mMusicDatabase.getWritableDatabase();
StringBuilder selection = new StringBuilder();
selection.append(RecentStoreColumns.ID);
selection.append(" IN (");
for (int i = 0; i < ids.length - 1; i++) {
selection.append(ids[i]);
selection.append(",");
}
if (ids.length != 0) {
selection.append(ids[ids.length - 1]);
}
selection.append(")");
database.delete(RecentStoreColumns.NAME, selection.toString(), null);
}
use of android.database.sqlite.SQLiteDatabase in project iosched by google.
the class ScheduleProvider method delete.
/** {@inheritDoc} */
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
String accountName = getCurrentAccountName(uri, false);
LOGV(TAG, "delete(uri=" + uri + ", account=" + accountName + ")");
if (uri == ScheduleContract.BASE_CONTENT_URI) {
// Handle whole database deletes (e.g. when signing out)
deleteDatabase();
notifyChange(uri);
return 1;
}
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
final SelectionBuilder builder = buildSimpleSelection(uri);
ScheduleUriEnum matchingUriEnum = mUriMatcher.matchUri(uri);
if (matchingUriEnum == ScheduleUriEnum.MY_SCHEDULE) {
builder.where(MySchedule.MY_SCHEDULE_ACCOUNT_NAME + "=?", accountName);
}
if (matchingUriEnum == ScheduleUriEnum.MY_VIEWED_VIDEOS) {
builder.where(MyViewedVideos.MY_VIEWED_VIDEOS_ACCOUNT_NAME + "=?", accountName);
}
if (matchingUriEnum == ScheduleUriEnum.MY_FEEDBACK_SUBMITTED) {
builder.where(MyFeedbackSubmitted.MY_FEEDBACK_SUBMITTED_ACCOUNT_NAME + "=?", accountName);
}
int retVal = builder.where(selection, selectionArgs).delete(db);
notifyChange(uri);
return retVal;
}
use of android.database.sqlite.SQLiteDatabase in project iosched by google.
the class ScheduleProvider method applyBatch.
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
use of android.database.sqlite.SQLiteDatabase in project iosched by google.
the class ScheduleProvider method update.
/** {@inheritDoc} */
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
String accountName = getCurrentAccountName(uri, false);
LOGV(TAG, "update(uri=" + uri + ", values=" + values.toString() + ", account=" + accountName + ")");
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
ScheduleUriEnum matchingUriEnum = mUriMatcher.matchUri(uri);
if (matchingUriEnum == ScheduleUriEnum.SEARCH_INDEX) {
// update the search index
ScheduleDatabase.updateSessionSearchIndex(db);
return 1;
}
final SelectionBuilder builder = buildSimpleSelection(uri);
if (matchingUriEnum == ScheduleUriEnum.MY_SCHEDULE) {
values.remove(MySchedule.MY_SCHEDULE_ACCOUNT_NAME);
builder.where(MySchedule.MY_SCHEDULE_ACCOUNT_NAME + "=?", accountName);
}
if (matchingUriEnum == ScheduleUriEnum.MY_VIEWED_VIDEOS) {
values.remove(MyViewedVideos.MY_VIEWED_VIDEOS_ACCOUNT_NAME);
builder.where(MyViewedVideos.MY_VIEWED_VIDEOS_ACCOUNT_NAME + "=?", accountName);
}
if (matchingUriEnum == ScheduleUriEnum.MY_FEEDBACK_SUBMITTED) {
values.remove(MyFeedbackSubmitted.MY_FEEDBACK_SUBMITTED_ACCOUNT_NAME);
builder.where(MyFeedbackSubmitted.MY_FEEDBACK_SUBMITTED_ACCOUNT_NAME + "=?", accountName);
}
int retVal = builder.where(selection, selectionArgs).update(db, values);
notifyChange(uri);
return retVal;
}
use of android.database.sqlite.SQLiteDatabase in project iosched by google.
the class ScheduleProvider method query.
/** {@inheritDoc} */
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
final SQLiteDatabase db = mOpenHelper.getReadableDatabase();
String tagsFilter = uri.getQueryParameter(Sessions.QUERY_PARAMETER_TAG_FILTER);
String categories = uri.getQueryParameter(Sessions.QUERY_PARAMETER_CATEGORIES);
ScheduleUriEnum matchingUriEnum = mUriMatcher.matchUri(uri);
// Avoid the expensive string concatenation below if not loggable.
if (Log.isLoggable(TAG, Log.VERBOSE)) {
LOGV(TAG, "uri=" + uri + " code=" + matchingUriEnum.code + " proj=" + Arrays.toString(projection) + " selection=" + selection + " args=" + Arrays.toString(selectionArgs) + ")");
}
switch(matchingUriEnum) {
default:
{
// Most cases are handled with simple SelectionBuilder.
final SelectionBuilder builder = buildExpandedSelection(uri, matchingUriEnum.code);
// If a special filter was specified, try to apply it.
if (!TextUtils.isEmpty(tagsFilter) && !TextUtils.isEmpty(categories)) {
addTagsFilter(builder, tagsFilter, categories);
}
boolean distinct = ScheduleContractHelper.isQueryDistinct(uri);
Cursor cursor = builder.where(selection, selectionArgs).query(db, distinct, projection, sortOrder, null);
Context context = getContext();
if (null != context) {
cursor.setNotificationUri(context.getContentResolver(), uri);
}
return cursor;
}
case SEARCH_SUGGEST:
{
final SelectionBuilder builder = new SelectionBuilder();
// Adjust incoming query to become SQL text match.
selectionArgs[0] = selectionArgs[0] + "%";
builder.table(Tables.SEARCH_SUGGEST);
builder.where(selection, selectionArgs);
builder.map(SearchManager.SUGGEST_COLUMN_QUERY, SearchManager.SUGGEST_COLUMN_TEXT_1);
projection = new String[] { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_QUERY };
final String limit = uri.getQueryParameter(SearchManager.SUGGEST_PARAMETER_LIMIT);
return builder.query(db, false, projection, SearchSuggest.DEFAULT_SORT, limit);
}
case SEARCH_TOPICS_SESSIONS:
{
if (selectionArgs == null || selectionArgs.length == 0) {
return createMergedSearchCursor(null, null);
}
String selectionArg = selectionArgs[0] == null ? "" : selectionArgs[0];
// First we query the Tags table to find any tags that match the given query
Cursor tags = query(Tags.CONTENT_URI, SearchTopicsSessions.TOPIC_TAG_PROJECTION, SearchTopicsSessions.TOPIC_TAG_SELECTION, new String[] { Config.Tags.CATEGORY_TRACK, selectionArg + "%" }, SearchTopicsSessions.TOPIC_TAG_SORT);
// Then we query the sessions_search table and get a list of sessions that match
// the given keywords.
Cursor search = null;
if (selectionArgs[0] != null) {
// dont query if there was no selectionArg.
search = query(ScheduleContract.Sessions.buildSearchUri(selectionArg), SearchTopicsSessions.SEARCH_SESSIONS_PROJECTION, null, null, ScheduleContract.Sessions.SORT_BY_TYPE_THEN_TIME);
}
// of the two result sets.
return createMergedSearchCursor(tags, search);
}
}
}
Aggregations