Search in sources :

Example 81 with SQLiteDatabase

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);
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 82 with SQLiteDatabase

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;
}
Also used : SelectionBuilder(com.google.samples.apps.iosched.util.SelectionBuilder) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 83 with SQLiteDatabase

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();
    }
}
Also used : ContentProviderResult(android.content.ContentProviderResult) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 84 with SQLiteDatabase

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;
}
Also used : SelectionBuilder(com.google.samples.apps.iosched.util.SelectionBuilder) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 85 with SQLiteDatabase

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);
            }
    }
}
Also used : Context(android.content.Context) SelectionBuilder(com.google.samples.apps.iosched.util.SelectionBuilder) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1658 Cursor (android.database.Cursor)527 ContentValues (android.content.ContentValues)350 ArrayList (java.util.ArrayList)111 File (java.io.File)65 Test (org.junit.Test)59 SQLiteException (android.database.sqlite.SQLiteException)48 SQLException (android.database.SQLException)44 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)44 Uri (android.net.Uri)44 IOException (java.io.IOException)43 ServiceStatus (com.vodafone360.people.service.ServiceStatus)42 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)38 RemoteException (android.os.RemoteException)36 Pair (android.util.Pair)31 MediumTest (android.test.suitebuilder.annotation.MediumTest)30 Account (android.accounts.Account)29 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)22 HashMap (java.util.HashMap)21