void deleteAllPayloads() { // TODO: Delete files too. SQLiteDatabase db; try { db = getWritableDatabase(); db.delete(PayloadEntry.TABLE_NAME, "", null); } catch (SQLException sqe) { ApptentiveLog.e(DATABASE, "deleteAllPayloads EXCEPTION: " + sqe.getMessage()); logException(sqe); } }
private void removeCorruptedPayloads() { Cursor cursor = null; try { SQLiteDatabase db = getWritableDatabase(); cursor = db.rawQuery(SQL_REMOVE_INCOMPLETE_PAYLOADS, null); cursor.moveToFirst(); // we need to move a cursor in order to update database ApptentiveLog.v(DATABASE, "Removed incomplete payloads"); } catch (SQLException e) { ApptentiveLog.e(e, "Exception while removing incomplete payloads"); logException(e); } finally { ensureClosed(cursor); } }
void deleteAssociatedFiles(String messageNonce) { SQLiteDatabase db = null; try { db = getWritableDatabase(); int deleted = db.delete(TABLE_COMPOUND_MESSAGE_FILESTORE, COMPOUND_FILESTORE_KEY_MESSAGE_NONCE + " = ?", new String[]{messageNonce}); ApptentiveLog.d(DATABASE, "Deleted %d stored files.", deleted); } catch (SQLException sqe) { ApptentiveLog.e(DATABASE, "deleteAssociatedFiles EXCEPTION: " + sqe.getMessage()); logException(sqe); } }
boolean addCompoundMessageFiles(List<StoredFile> associatedFiles) { String messageNonce = associatedFiles.get(0).getId(); SQLiteDatabase db = null; long ret = -1; try { db = getWritableDatabase(); db.beginTransaction(); // Always delete existing rows with the same nonce to ensure add/update both work db.delete(TABLE_COMPOUND_MESSAGE_FILESTORE, COMPOUND_FILESTORE_KEY_MESSAGE_NONCE + " = ?", new String[]{messageNonce}); for (StoredFile file : associatedFiles) { ContentValues values = new ContentValues(); values.put(COMPOUND_FILESTORE_KEY_MESSAGE_NONCE, file.getId()); values.put(COMPOUND_FILESTORE_KEY_LOCAL_CACHE_PATH, file.getLocalFilePath()); values.put(COMPOUND_FILESTORE_KEY_MIME_TYPE, file.getMimeType()); values.put(COMPOUND_FILESTORE_KEY_LOCAL_ORIGINAL_URI, file.getSourceUriOrPath()); values.put(COMPOUND_FILESTORE_KEY_REMOTE_URL, file.getApptentiveUri()); values.put(COMPOUND_FILESTORE_KEY_CREATION_TIME, file.getCreationTime()); ret = db.insert(TABLE_COMPOUND_MESSAGE_FILESTORE, null, values); } db.setTransactionSuccessful(); db.endTransaction(); } catch (SQLException sqe) { ApptentiveLog.e(DATABASE, "addCompoundMessageFiles EXCEPTION: " + sqe.getMessage()); logException(sqe); } return ret != -1; }
Cursor cursor = null; try { db = getWritableDatabase(); cursor = db.rawQuery(SQL_SELECT_PAYLOADS_IN_SEND_ORDER, null); int payloadCount = cursor.getCount();
void deletePayload(String payloadIdentifier) { if (payloadIdentifier == null) { throw new IllegalArgumentException("Payload identifier is null"); } // First delete the row SQLiteDatabase db; try { db = getWritableDatabase(); db.delete( PayloadEntry.TABLE_NAME, PayloadEntry.COLUMN_IDENTIFIER + " = ?", new String[]{payloadIdentifier} ); } catch (SQLException sqe) { ApptentiveLog.e(DATABASE, "deletePayload EXCEPTION: " + sqe.getMessage()); logException(sqe); } // Then delete the data file File dest = getPayloadBodyFile(payloadIdentifier); ApptentiveLog.v(DATABASE, "Deleted payload \"%s\" data file successfully? %b", payloadIdentifier, dest.delete()); if (ApptentiveLog.canLog(ApptentiveLog.Level.VERBOSE)) { printPayloadTable("Deleted payload"); } }
SQLiteDatabase db = null; try { db = getWritableDatabase(); db.beginTransaction();
void updateIncompletePayloads(String conversationId, String authToken, String localConversationId, boolean legacyPayloads) { if (ApptentiveLog.canLog(ApptentiveLog.Level.VERBOSE)) { printPayloadTable("updateIncompletePayloads BEFORE"); } if (StringUtils.isNullOrEmpty(conversationId)) { throw new IllegalArgumentException("Conversation id is null or empty"); } if (StringUtils.isNullOrEmpty(authToken)) { throw new IllegalArgumentException("Token is null or empty"); } try { SQLiteDatabase db = getWritableDatabase(); db.execSQL(legacyPayloads ? SQL_UPDATE_LEGACY_PAYLOADS : SQL_UPDATE_INCOMPLETE_PAYLOADS, new Object[] { encrypt(authToken), conversationId, localConversationId }); ApptentiveLog.v(DATABASE, "Updated missing conversation ids"); } catch (Exception e) { ApptentiveLog.e(e, "Exception while updating missing conversation ids"); logException(e); } // remove incomplete payloads which don't belong to an active conversation removeCorruptedPayloads(); if (ApptentiveLog.canLog(ApptentiveLog.Level.VERBOSE)) { printPayloadTable("updateIncompletePayloads AFTER"); } }
Cursor cursor = null; try { db = getWritableDatabase(); cursor = db.rawQuery(SQL_SELECT_PAYLOADS_IN_SEND_ORDER, null); int count = cursor.getCount();