Search in sources :

Example 51 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Zom-Android by zom.

the class ImpsProvider method insert.

@Override
public final Uri insert(final Uri url, final ContentValues values) {
    Uri result = null;
    if (getDBHelper() != null) {
        try {
            SQLiteDatabase db = getDBHelper().getWritableDatabase();
            if (db.isOpen()) {
                db.beginTransaction();
                try {
                    result = insertInternal(url, values);
                    db.setTransactionSuccessful();
                } finally {
                    db.endTransaction();
                }
                if (result != null) {
                    getContext().getContentResolver().notifyChange(url, null, /* observer */
                    false);
                }
            }
        } catch (IllegalStateException ise) {
            log("database closed when insert attempted: " + url.toString());
        }
    }
    return result;
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) Uri(android.net.Uri)

Example 52 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Zom-Android by zom.

the class ImpsProvider method updateBulkContacts.

// package scope for testing.
int updateBulkContacts(ContentValues values, String userWhere) {
    ArrayList<String> usernames = getStringArrayList(values, Imps.Contacts.USERNAME);
    ArrayList<String> nicknames = getStringArrayList(values, Imps.Contacts.NICKNAME);
    int usernameCount = usernames.size();
    int nicknameCount = nicknames.size();
    if (usernameCount != nicknameCount) {
        LogCleaner.warn(LOG_TAG, "[ImProvider] updateBulkContacts: input bundle " + "username & nickname lists have diff. length!");
        return 0;
    }
    ArrayList<String> contactTypeArray = getStringArrayList(values, Imps.Contacts.TYPE);
    ArrayList<String> subscriptionStatusArray = getStringArrayList(values, Imps.Contacts.SUBSCRIPTION_STATUS);
    ArrayList<String> subscriptionTypeArray = getStringArrayList(values, Imps.Contacts.SUBSCRIPTION_TYPE);
    ArrayList<String> quickContactArray = getStringArrayList(values, Imps.Contacts.QUICK_CONTACT);
    ArrayList<String> rejectedArray = getStringArrayList(values, Imps.Contacts.REJECTED);
    final SQLiteDatabase db = getDBHelper().getWritableDatabase();
    db.beginTransaction();
    int sum = 0;
    try {
        Long provider = values.getAsLong(Imps.Contacts.PROVIDER);
        Long account = values.getAsLong(Imps.Contacts.ACCOUNT);
        for (int i = 0; i < usernameCount; i++) {
            ContentValues contactValues = new ContentValues();
            contactValues.put(Imps.Contacts.PROVIDER, provider);
            contactValues.put(Imps.Contacts.ACCOUNT, account);
            String username = usernames.get(i);
            String nickname = nicknames.get(i);
            int type = 0;
            int subscriptionStatus = 0;
            int subscriptionType = 0;
            int quickContact = 0;
            int rejected = 0;
            contactValues.put(Imps.Contacts.USERNAME, username);
            contactValues.put(Imps.Contacts.NICKNAME, nickname);
            try {
                if (contactTypeArray != null) {
                    type = Integer.parseInt(contactTypeArray.get(i));
                    contactValues.put(Imps.Contacts.TYPE, type);
                }
                if (subscriptionStatusArray != null) {
                    subscriptionStatus = Integer.parseInt(subscriptionStatusArray.get(i));
                    contactValues.put(Imps.Contacts.SUBSCRIPTION_STATUS, subscriptionStatus);
                }
                if (subscriptionTypeArray != null) {
                    subscriptionType = Integer.parseInt(subscriptionTypeArray.get(i));
                    contactValues.put(Imps.Contacts.SUBSCRIPTION_TYPE, subscriptionType);
                }
                if (quickContactArray != null) {
                    quickContact = Integer.parseInt(quickContactArray.get(i));
                    contactValues.put(Imps.Contacts.QUICK_CONTACT, quickContact);
                }
                if (rejectedArray != null) {
                    rejected = Integer.parseInt(rejectedArray.get(i));
                    contactValues.put(Imps.Contacts.REJECTED, rejected);
                }
            } catch (NumberFormatException ex) {
                LogCleaner.error(LOG_TAG, "insertBulkContacts: caught ", ex);
            }
            log("updateBulkContacts[" + i + "] username=" + username + ", nickname=" + nickname + ", type=" + type + ", subscriptionStatus=" + subscriptionStatus + ", subscriptionType=" + subscriptionType + ", qc=" + quickContact);
            StringBuffer updateSelection = new StringBuffer();
            updateSelection.append(Imps.Contacts.USERNAME);
            updateSelection.append(" LIKE ?");
            String[] updateSelectionArgs = new String[1];
            updateSelectionArgs[0] = username;
            int numUpdated = db.update(TABLE_CONTACTS, contactValues, updateSelection.toString(), updateSelectionArgs);
            if (numUpdated == 0) {
                LogCleaner.warn(LOG_TAG, "[ImProvider] updateBulkContacts: " + " update failed for selection = " + updateSelection);
            } else {
                sum += numUpdated;
            }
            // yield the lock if anyone else is trying to
            // perform a db operation here.
            db.yieldIfContended();
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    log("updateBulkContacts: " + sum + " entries updated");
    return sum;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 53 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Zom-Android by zom.

the class ImpsProvider method queryInternal.

public Cursor queryInternal(Uri url, String[] projectionIn, String selection, String[] selectionArgs, String sort) {
    Debug.onServiceStart();
    if (!mLoadedLibs) {
        SQLiteDatabase.loadLibs(this.getContext().getApplicationContext());
        mLoadedLibs = true;
    }
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    StringBuilder whereClause = new StringBuilder();
    if (selection != null) {
        whereClause.append(selection);
    }
    String groupBy = null;
    String limit = null;
    // Generate the body of the query
    int match = mUrlMatcher.match(url);
    switch(match) {
        case MATCH_PROVIDERS_BY_ID:
            appendWhere(whereClause, Imps.Provider._ID, "=", url.getPathSegments().get(1));
        case MATCH_PROVIDERS:
            qb.setTables(TABLE_PROVIDERS);
            break;
        case MATCH_PROVIDERS_WITH_ACCOUNT:
            qb.setTables(PROVIDER_JOIN_ACCOUNT_TABLE);
            qb.setProjectionMap(sProviderAccountsProjectionMap);
            break;
        case MATCH_ACCOUNTS_WITH_DOMAIN:
            qb.setTables(DOMAIN_JOIN_ACCOUNT_TABLE);
            qb.setProjectionMap(sAccountsByDomainProjectionMap);
            break;
        case MATCH_ACCOUNTS_BY_ID:
            appendWhere(whereClause, Imps.Account._ID, "=", url.getPathSegments().get(1));
        // falls down
        case MATCH_ACCOUNTS:
            qb.setTables(TABLE_ACCOUNTS);
            break;
        case MATCH_CONTACTS:
            qb.setTables(CONTACT_JOIN_PRESENCE_CHAT_AVATAR_TABLE);
            qb.setProjectionMap(sContactsProjectionMap);
            break;
        case MATCH_CONTACTS_JOIN_PRESENCE:
            qb.setTables(CONTACT_JOIN_PRESENCE_TABLE);
            qb.setProjectionMap(sContactsProjectionMap);
            break;
        case MATCH_CONTACTS_BAREBONE:
            qb.setTables(TABLE_CONTACTS);
            break;
        case MATCH_CHATTING_CONTACTS:
            qb.setTables(CONTACT_JOIN_PRESENCE_CHAT_AVATAR_TABLE);
            qb.setProjectionMap(sContactsProjectionMap);
            appendWhere(whereClause, "chats.last_message_date IS NOT NULL");
            // blocked contacts can't have conversations.
            break;
        case MATCH_CONTACTS_BY_PROVIDER:
            buildQueryContactsByProvider(qb, whereClause, url);
            appendWhere(whereClause, NON_BLOCKED_CONTACTS_WHERE_CLAUSE);
            break;
        case MATCH_CHATTING_CONTACTS_BY_PROVIDER:
            buildQueryContactsByProvider(qb, whereClause, url);
            appendWhere(whereClause, "chats.last_message_date IS NOT NULL");
            // blocked contacts can't have conversations.
            break;
        case MATCH_NO_CHATTING_CONTACTS_BY_PROVIDER:
            buildQueryContactsByProvider(qb, whereClause, url);
            appendWhere(whereClause, "chats.last_message_date IS NULL");
            appendWhere(whereClause, NON_BLOCKED_CONTACTS_WHERE_CLAUSE);
            break;
        case MATCH_ONLINE_CONTACTS_BY_PROVIDER:
            buildQueryContactsByProvider(qb, whereClause, url);
            appendWhere(whereClause, Imps.Contacts.PRESENCE_STATUS, "!=", Imps.Presence.OFFLINE);
            appendWhere(whereClause, NON_BLOCKED_CONTACTS_WHERE_CLAUSE);
            break;
        case MATCH_OFFLINE_CONTACTS_BY_PROVIDER:
            buildQueryContactsByProvider(qb, whereClause, url);
            appendWhere(whereClause, Imps.Contacts.PRESENCE_STATUS, "=", Imps.Presence.OFFLINE);
            appendWhere(whereClause, NON_BLOCKED_CONTACTS_WHERE_CLAUSE);
            break;
        case MATCH_BLOCKED_CONTACTS:
            qb.setTables(CONTACT_JOIN_PRESENCE_CHAT_AVATAR_TABLE);
            qb.setProjectionMap(sContactsProjectionMap);
            appendWhere(whereClause, BLOCKED_CONTACTS_WHERE_CLAUSE);
            break;
        case MATCH_CONTACT:
            qb.setTables(CONTACT_JOIN_PRESENCE_CHAT_AVATAR_TABLE);
            qb.setProjectionMap(sContactsProjectionMap);
            appendWhere(whereClause, "contacts._id", "=", url.getPathSegments().get(1));
            break;
        case MATCH_ONLINE_CONTACT_COUNT:
            qb.setTables(CONTACT_JOIN_PRESENCE_CHAT_TABLE);
            qb.setProjectionMap(sContactsProjectionMap);
            appendWhere(whereClause, Imps.Contacts.PRESENCE_STATUS, "!=", Imps.Presence.OFFLINE);
            appendWhere(whereClause, "chats.last_message_date IS NULL");
            appendWhere(whereClause, NON_BLOCKED_CONTACTS_WHERE_CLAUSE);
            groupBy = Imps.Contacts.CONTACTLIST;
            break;
        case MATCH_CONTACTLISTS_BY_PROVIDER:
            appendWhere(whereClause, Imps.ContactList.ACCOUNT, "=", url.getPathSegments().get(2));
        // fall through
        case MATCH_CONTACTLISTS:
            qb.setTables(TABLE_CONTACT_LIST);
            qb.setProjectionMap(sContactListProjectionMap);
            break;
        case MATCH_CONTACTLIST:
            qb.setTables(TABLE_CONTACT_LIST);
            appendWhere(whereClause, Imps.ContactList._ID, "=", url.getPathSegments().get(1));
            break;
        case MATCH_BLOCKEDLIST:
            qb.setTables(BLOCKEDLIST_JOIN_AVATAR_TABLE);
            qb.setProjectionMap(sBlockedListProjectionMap);
            break;
        case MATCH_BLOCKEDLIST_BY_PROVIDER:
            qb.setTables(BLOCKEDLIST_JOIN_AVATAR_TABLE);
            qb.setProjectionMap(sBlockedListProjectionMap);
            appendWhere(whereClause, Imps.BlockedList.ACCOUNT, "=", url.getPathSegments().get(2));
            break;
        case MATCH_CONTACTS_ETAGS:
            qb.setTables(TABLE_CONTACTS_ETAG);
            break;
        case MATCH_CONTACTS_ETAG:
            qb.setTables(TABLE_CONTACTS_ETAG);
            appendWhere(whereClause, "_id", "=", url.getPathSegments().get(1));
            break;
        case MATCH_MESSAGES_BY_THREAD_ID:
            appendWhere(whereClause, Imps.Messages.THREAD_ID, "=", url.getPathSegments().get(1));
        case MATCH_MESSAGES:
            qb.setTables(TABLE_MESSAGES);
            final String selectionClause = whereClause.toString();
            final String query1 = qb.buildQuery(projectionIn, selectionClause, null, null, null, null, null);
            // Build the second query for frequent
            qb = new SQLiteQueryBuilder();
            qb.setTables(TABLE_IN_MEMORY_MESSAGES);
            final String query2 = qb.buildQuery(projectionIn, selectionClause, null, null, null, null, null);
            // Put them together
            final String query = qb.buildUnionQuery(new String[] { query1, query2 }, sort, null);
            final SQLiteDatabase db = getDBHelper().getWritableDatabase();
            String[] doubleArgs = null;
            if (selectionArgs != null) {
                // Arrays.copyOf(selectionArgs, selectionArgs.length * 2);
                doubleArgs = new String[selectionArgs.length * 2];
                System.arraycopy(selectionArgs, 0, doubleArgs, 0, selectionArgs.length);
                System.arraycopy(selectionArgs, 0, doubleArgs, selectionArgs.length, selectionArgs.length);
            }
            Cursor c = db.rawQueryWithFactory(null, query, doubleArgs, TABLE_MESSAGES);
            if ((c != null) && !isTemporary()) {
                c.setNotificationUri(getContext().getContentResolver(), url);
            }
            return c;
        case MATCH_MESSAGES_BY_PACKET_ID:
        case MATCH_OTR_MESSAGES_BY_PACKET_ID:
            appendWhere(whereClause, Imps.Messages.PACKET_ID, "=", url.getPathSegments().get(1));
            qb.setTables(TABLE_MESSAGES);
            final String selectionClausePacketId = whereClause.toString();
            final String query1PacketId = qb.buildQuery(projectionIn, selectionClausePacketId, null, null, null, null, null);
            // Build the second query for frequent
            qb = new SQLiteQueryBuilder();
            qb.setTables(TABLE_IN_MEMORY_MESSAGES);
            final String query2PacketId = qb.buildQuery(projectionIn, selectionClausePacketId, null, null, null, null, null);
            // Put them together
            final String queryPacketId = qb.buildUnionQuery(new String[] { query1PacketId, query2PacketId }, sort, null);
            final SQLiteDatabase dbPacketId = getDBHelper().getWritableDatabase();
            String[] doubleArgsPacketId = null;
            if (selectionArgs != null) {
                // Arrays.copyOf(selectionArgs, selectionArgs.length * 2);
                doubleArgsPacketId = new String[selectionArgs.length * 2];
                System.arraycopy(selectionArgs, 0, doubleArgsPacketId, 0, selectionArgs.length);
                System.arraycopy(selectionArgs, 0, doubleArgsPacketId, selectionArgs.length, selectionArgs.length);
            }
            Cursor cPacketId = dbPacketId.rawQueryWithFactory(null, queryPacketId, doubleArgsPacketId, TABLE_MESSAGES);
            if ((cPacketId != null) && !isTemporary()) {
                cPacketId.setNotificationUri(getContext().getContentResolver(), url);
            }
            return cPacketId;
        case MATCH_MESSAGE:
            qb.setTables(TABLE_MESSAGES);
            appendWhere(whereClause, Imps.Messages._ID, "=", url.getPathSegments().get(1));
            break;
        case MATCH_MESSAGES_BY_CONTACT:
            qb.setTables(MESSAGE_JOIN_CONTACT_TABLE);
            qb.setProjectionMap(sMessagesProjectionMap);
            appendWhere(whereClause, Imps.Contacts.ACCOUNT, "=", url.getPathSegments().get(1));
            appendWhere(whereClause, "contacts.username", "=", decodeURLSegment(url.getPathSegments().get(2)));
            final String sel = whereClause.toString();
            final String q1 = qb.buildQuery(projectionIn, sel, null, null, null, null, null);
            // Build the second query for frequent
            qb = new SQLiteQueryBuilder();
            qb.setTables(IN_MEMORY_MESSAGES_JOIN_CONTACT_TABLE);
            qb.setProjectionMap(sInMemoryMessagesProjectionMap);
            final String q2 = qb.buildQuery(projectionIn, sel, null, null, null, null, null);
            // Put them together
            final String q3 = qb.buildUnionQuery(new String[] { q1, q2 }, sort, null);
            final SQLiteDatabase db2 = getDBHelper().getWritableDatabase();
            Cursor c2 = db2.rawQueryWithFactory(null, q3, null, MESSAGE_JOIN_CONTACT_TABLE);
            if ((c2 != null) && !isTemporary()) {
                c2.setNotificationUri(getContext().getContentResolver(), url);
            }
            return c2;
        case MATCH_MESSAGES_BY_SEARCH:
            qb.setTables(MESSAGE_JOIN_CONTACT_TABLE);
            qb.setProjectionMap(sMessagesProjectionMap);
            limit = "20";
            final String q4 = qb.buildQuery(projectionIn, whereClause.toString(), null, null, null, null, null);
            // Build the second query for frequent
            qb = new SQLiteQueryBuilder();
            qb.setTables(IN_MEMORY_MESSAGES_JOIN_CONTACT_TABLE);
            qb.setProjectionMap(sInMemoryMessagesProjectionMap);
            final String q5 = qb.buildQuery(projectionIn, whereClause.toString(), null, null, null, null, null);
            // Put them together
            final String q6 = qb.buildUnionQuery(new String[] { q4, q5 }, sort, limit);
            final SQLiteDatabase db3 = getDBHelper().getWritableDatabase();
            Cursor c3 = db3.rawQueryWithFactory(null, q6, null, MESSAGE_JOIN_CONTACT_TABLE);
            if ((c3 != null) && !isTemporary()) {
                c3.setNotificationUri(getContext().getContentResolver(), url);
            }
            return c3;
        case MATCH_INVITATIONS:
            qb.setTables(TABLE_INVITATIONS);
            break;
        case MATCH_INVITATION:
            qb.setTables(TABLE_INVITATIONS);
            appendWhere(whereClause, Imps.Invitation._ID, "=", url.getPathSegments().get(1));
            break;
        case MATCH_GROUP_MEMBERS:
            qb.setTables(TABLE_GROUP_MEMBERS);
            break;
        case MATCH_GROUP_MEMBERS_BY_GROUP:
            qb.setTables(TABLE_GROUP_MEMBERS);
            qb.setDistinct(true);
            appendWhere(whereClause, Imps.GroupMembers.GROUP, "=", url.getPathSegments().get(1));
            groupBy = Imps.GroupMembers.USERNAME;
            break;
        case MATCH_AVATARS:
            qb.setTables(TABLE_AVATARS);
            break;
        case MATCH_AVATAR_BY_PROVIDER:
            qb.setTables(TABLE_AVATARS);
            appendWhere(whereClause, Imps.Avatars.ACCOUNT, "=", url.getPathSegments().get(2));
            break;
        case MATCH_CHATS:
            qb.setTables(TABLE_CHATS);
            break;
        case MATCH_CHATS_ID:
            qb.setTables(TABLE_CHATS);
            appendWhere(whereClause, Imps.Chats.CONTACT_ID, "=", url.getPathSegments().get(1));
            break;
        case MATCH_CHATS_BY_ACCOUNT:
            qb.setTables(TABLE_CHATS);
            String accountStr = decodeURLSegment(url.getLastPathSegment());
            appendWhere(whereClause, buildContactIdSelection(Imps.Chats.CONTACT_ID, Imps.Contacts.ACCOUNT + "='" + accountStr + "'"));
            break;
        case MATCH_PRESENCE:
            qb.setTables(TABLE_PRESENCE);
            break;
        case MATCH_PRESENCE_ID:
            qb.setTables(TABLE_PRESENCE);
            appendWhere(whereClause, Imps.Presence.CONTACT_ID, "=", url.getPathSegments().get(1));
            break;
        case MATCH_SESSIONS:
            qb.setTables(TABLE_SESSION_COOKIES);
            break;
        case MATCH_SESSIONS_BY_PROVIDER:
            qb.setTables(TABLE_SESSION_COOKIES);
            appendWhere(whereClause, Imps.SessionCookies.ACCOUNT, "=", url.getPathSegments().get(2));
            break;
        case MATCH_PROVIDER_SETTINGS_BY_ID_AND_NAME:
            appendWhere(whereClause, Imps.ProviderSettings.NAME, "=", url.getPathSegments().get(2));
        // fall through
        case MATCH_PROVIDER_SETTINGS_BY_ID:
            appendWhere(whereClause, Imps.ProviderSettings.PROVIDER, "=", url.getPathSegments().get(1));
        // fall through
        case MATCH_PROVIDER_SETTINGS:
            qb.setTables(TABLE_PROVIDER_SETTINGS);
            break;
        case MATCH_ACCOUNTS_STATUS:
            qb.setTables(TABLE_ACCOUNT_STATUS);
            break;
        case MATCH_ACCOUNT_STATUS:
            qb.setTables(TABLE_ACCOUNT_STATUS);
            appendWhere(whereClause, Imps.AccountStatus.ACCOUNT, "=", url.getPathSegments().get(1));
            break;
        case MATCH_BRANDING_RESOURCE_MAP_CACHE:
            qb.setTables(TABLE_BRANDING_RESOURCE_MAP_CACHE);
            break;
        // mcs and rmq queries
        case MATCH_OUTGOING_RMQ_MESSAGES:
            qb.setTables(TABLE_OUTGOING_RMQ_MESSAGES);
            break;
        case MATCH_OUTGOING_HIGHEST_RMQ_ID:
            qb.setTables(TABLE_OUTGOING_RMQ_MESSAGES);
            sort = "rmq_id DESC";
            limit = "1";
            break;
        case MATCH_LAST_RMQ_ID:
            qb.setTables(TABLE_LAST_RMQ_ID);
            limit = "1";
            break;
        case MATCH_S2D_RMQ_IDS:
            qb.setTables(TABLE_S2D_RMQ_IDS);
            break;
        default:
            throw new IllegalArgumentException("Unknown URL " + url);
    }
    if (getDBHelper() == null)
        return null;
    // run the query
    SQLiteDatabase db;
    try {
        db = getDBHelper().getReadableDatabase();
    } catch (net.sqlcipher.database.SQLiteException e) {
        // Failed to actually open - the passphrase must have been wrong - reset the helper
        synchronized (mDbHelperLock) {
            mDbHelper = null;
            mDbHelperLock.notify();
        }
        throw e;
    }
    net.sqlcipher.Cursor c = null;
    if (!db.isOpen())
        return null;
    try {
        qb.setDistinct(true);
        c = qb.query(db, projectionIn, whereClause.toString(), selectionArgs, groupBy, null, sort, limit);
        if (c != null) {
            switch(match) {
                case MATCH_CHATTING_CONTACTS:
                case MATCH_CHATTING_CONTACTS_BY_PROVIDER:
                    url = Contacts.CONTENT_URI_CHAT_CONTACTS_BY;
                    break;
                case MATCH_CONTACTS_BY_PROVIDER:
                case MATCH_ONLINE_CONTACTS_BY_PROVIDER:
                case MATCH_OFFLINE_CONTACTS_BY_PROVIDER:
                case MATCH_CONTACTS_BAREBONE:
                case MATCH_CONTACTS_JOIN_PRESENCE:
                case MATCH_ONLINE_CONTACT_COUNT:
                    url = Imps.Contacts.CONTENT_URI;
                    break;
            }
            // log("set notify url " + url);
            c.setNotificationUri(getContext().getContentResolver(), url);
        }
        // c = new MyCrossProcessCursorWrapper(c);
        return c;
    } catch (Exception ex) {
        LogCleaner.error(LOG_TAG, "query exc db caught ", ex);
        return null;
    } catch (Error ex) {
        LogCleaner.error(LOG_TAG, "query error db caught ", ex);
        return null;
    }
}
Also used : Cursor(android.database.Cursor) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLiteConstraintException(net.sqlcipher.database.SQLiteConstraintException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) SQLiteQueryBuilder(net.sqlcipher.database.SQLiteQueryBuilder)

Example 54 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Zom-Android by zom.

the class ImpsProvider method performContactRemovalCleanup.

private void performContactRemovalCleanup(long contactId) {
    final SQLiteDatabase db = getDBHelper().getWritableDatabase();
    if (contactId > 0) {
        StringBuilder buf = new StringBuilder();
        // delete presence
        buf.append(Imps.Presence.CONTACT_ID).append('=').append(contactId);
        deleteWithSelection(db, TABLE_PRESENCE, buf.toString(), null);
        // delete group memebers
        buf.delete(0, buf.length());
        buf.append(Imps.GroupMembers.GROUP).append('=').append(contactId);
        deleteWithSelection(db, TABLE_GROUP_MEMBERS, buf.toString(), null);
    } else {
        // delete presence
        deleteWithSelection(db, TABLE_PRESENCE, DELETE_PRESENCE_SELECTION, null);
        // delete group members
        deleteWithSelection(db, TABLE_GROUP_MEMBERS, DELETE_GROUP_MEMBER_SELECTION, null);
    }
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 55 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Zom-Android by zom.

the class ImpsProvider method delete.

@Override
public final int delete(final Uri url, final String selection, final String[] selectionArgs) {
    int result = -1;
    if (getDBHelper() != null) {
        SQLiteDatabase db = getDBHelper().getWritableDatabase();
        if (// db can be closed if service sign out takes longer than app/cacheword lock
        db.isOpen()) {
            try {
                db.beginTransaction();
                result = deleteInternal(url, selection, selectionArgs);
                db.setTransactionSuccessful();
                db.endTransaction();
            } catch (Exception e) {
            // could not delete
            }
            if (result > 0) {
                getContext().getContentResolver().notifyChange(url, null, /* observer */
                false);
            }
        }
    }
    return result;
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLiteConstraintException(net.sqlcipher.database.SQLiteConstraintException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)124 Cursor (android.database.Cursor)37 ContentValues (android.content.ContentValues)32 IOException (java.io.IOException)15 LinkedList (java.util.LinkedList)12 NonNull (android.support.annotation.NonNull)7 MergeCursor (android.database.MergeCursor)6 Nullable (android.support.annotation.Nullable)6 Pair (android.util.Pair)6 File (java.io.File)5 SQLiteConstraintException (net.sqlcipher.database.SQLiteConstraintException)5 FileNotFoundException (java.io.FileNotFoundException)4 StreamCorruptedException (java.io.StreamCorruptedException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 AudioClipTable (org.storymaker.app.model.AudioClipTable)4 AuthTable (org.storymaker.app.model.AuthTable)4 JobTable (org.storymaker.app.model.JobTable)4 LessonTable (org.storymaker.app.model.LessonTable)4 MediaTable (org.storymaker.app.model.MediaTable)4 ProjectTable (org.storymaker.app.model.ProjectTable)4