use of android.database.SQLException in project 360-Engine-for-Android by 360.
the class ContactSummaryTable method syncSetNativeIds.
/**
* Updates the native IDs for a list of contacts.
*
* @param contactIdList A list of ContactIdInfo objects. For each object,
* the local ID must match a local contact ID in the table. The
* Native ID will be used for the update. Other fields are
* unused.
* @param writeableDb Writable SQLite database
* @return SUCCESS or a suitable error code
*/
public static ServiceStatus syncSetNativeIds(List<ContactIdInfo> contactIdList, SQLiteDatabase writableDb) {
DatabaseHelper.trace(true, "ContactSummaryTable.syncSetNativeIds()");
if (contactIdList.size() == 0) {
return ServiceStatus.SUCCESS;
}
final SQLiteStatement statement1 = writableDb.compileStatement("UPDATE " + TABLE_NAME + " SET " + Field.NATIVEID + "=? WHERE " + Field.LOCALCONTACTID + "=?");
for (int i = 0; i < contactIdList.size(); i++) {
final ContactIdInfo info = contactIdList.get(i);
try {
writableDb.beginTransaction();
if (info.nativeId == null) {
statement1.bindNull(1);
} else {
statement1.bindLong(1, info.nativeId);
}
statement1.bindLong(2, info.localId);
statement1.execute();
writableDb.setTransactionSuccessful();
} catch (SQLException e) {
LogUtils.logE("ContactSummaryTable.syncSetNativeIds() " + "SQLException - Unable to update contact native Ids", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
} finally {
writableDb.endTransaction();
}
}
return ServiceStatus.SUCCESS;
}
use of android.database.SQLException in project 360-Engine-for-Android by 360.
the class ContactSummaryTable method modifyPictureLoadedFlag.
/**
* Modifies the avatar loaded flag for a particular contact
*
* @param localContactID The primary key ID of the contact
* @param value Can be one of the following values:
* <ul>
* <li>true - The avatar has been loaded</li>
* <li>false - There contact has an avatar but it has not yet
* been loaded</li>
* <li>null - The contact does not have an avatar</li>
* </ul>
* @param writeableDb Writable SQLite database
* @return SUCCESS or a suitable error code
*/
public static ServiceStatus modifyPictureLoadedFlag(Long localContactId, Boolean value, SQLiteDatabase writeableDb) {
if (Settings.ENABLED_DATABASE_TRACE) {
DatabaseHelper.trace(true, "ContactSummeryTable.modifyPictureLoadedFlag() localContactId[" + localContactId + "] value[" + value + "]");
}
try {
ContentValues cv = new ContentValues();
cv.put(Field.PICTURELOADED.toString(), value);
String[] args = { String.format("%d", localContactId) };
if (writeableDb.update(TABLE_NAME, cv, Field.LOCALCONTACTID + "=?", args) <= 0) {
LogUtils.logE("ContactSummeryTable.modifyPictureLoadedFlag() " + "Unable to modify picture loaded flag");
return ServiceStatus.ERROR_NOT_FOUND;
}
} catch (SQLException e) {
LogUtils.logE("ContactSummeryTable.modifyPictureLoadedFlag() " + "SQLException - Unable to modify picture loaded flag", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
return ServiceStatus.SUCCESS;
}
use of android.database.SQLException in project 360-Engine-for-Android by 360.
the class ContactSummaryTable method addContact.
/**
* Adds contact summary information to the table for a new contact. If the
* contact has no name or no status, an alternative detail will be used such
* as telephone number or email address.
*
* @param contact The new contact
* @param writableDb Writable SQLite database
* @return SUCCESS or a suitable error code
*/
public static ServiceStatus addContact(Contact contact, SQLiteDatabase writableDb) {
if (Settings.ENABLED_DATABASE_TRACE) {
DatabaseHelper.trace(true, "ContactSummeryTable.addContact() contactID[" + contact.contactID + "]");
}
if (contact.localContactID == null) {
LogUtils.logE("ContactSummeryTable.addContact() Invalid parameters");
return ServiceStatus.ERROR_NOT_FOUND;
}
try {
final ContentValues values = new ContentValues();
values.put(Field.LOCALCONTACTID.toString(), contact.localContactID);
values.put(Field.NATIVEID.toString(), contact.nativeContactId);
values.put(Field.FRIENDOFMINE.toString(), contact.friendOfMine);
values.put(Field.SYNCTOPHONE.toString(), contact.synctophone);
ContactDetail altDetail = findAlternativeNameContactDetail(values, contact.details);
updateAltValues(values, altDetail);
addToPresenceMap(contact.localContactID);
if (writableDb.insertOrThrow(TABLE_NAME, null, values) < 0) {
LogUtils.logE("ContactSummeryTable.addContact() " + "Unable to insert new contact summary");
return ServiceStatus.ERROR_NOT_FOUND;
}
return ServiceStatus.SUCCESS;
} catch (SQLException e) {
LogUtils.logE("ContactSummeryTable.addContact() SQLException - " + "Unable to insert new contact summary", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
}
use of android.database.SQLException in project 360-Engine-for-Android by 360.
the class ContactsTable method fetchNativeFromLocalId.
/**
* Returns the native ID associated with a contact
*
* @param localContactId The primary key ID of the contact to find
* @param statement The statement provided by
* {@link #fetchNativeFromLocalIdStatement(SQLiteDatabase)}.
* @return Native Contact ID or NULL if the contact was not found.
* @see #fetchNativeFromLocalIdStatement(SQLiteDatabase)
*/
public static Integer fetchNativeFromLocalId(SQLiteDatabase readableDb, Long localContactId) {
Cursor c = null;
DatabaseHelper.trace(false, "ContactsTable.fetchNativeFromLocalId() localContactId[" + localContactId + "]");
if (readableDb == null || localContactId == null) {
return null;
}
try {
c = readableDb.rawQuery(QUERY_NATIVE_ID_BY_LOCAL_CONTACT_ID, new String[] { localContactId.toString() });
if (!c.moveToFirst()) {
LogUtils.logW("ContactsTable.fetchNativeFromLocalId() nativeID not found");
return null;
}
return (c.isNull(0)) ? null : c.getInt(0);
} catch (SQLException e) {
LogUtils.logE("ContactsTable.fetchNativeFromLocalId() Exception - Unable to run query:\n", e);
return null;
} finally {
CloseUtils.close(c);
}
}
use of android.database.SQLException in project 360-Engine-for-Android by 360.
the class NativeChangeLogTable method fetchNoOfChanges.
/**
* Fetches the number of changes listed in the table.
*
* @param type The type of change to count, if null all change types are
* included
* @param readableDb Readable SQLite database
* @return The number of records
*/
public static long fetchNoOfChanges(ContactChangeType type, SQLiteDatabase readableDb) {
DatabaseHelper.trace(false, "NativeChangeLogTable.fetchNoOfChanges()");
long noOfChanges = 0;
Cursor c = null;
try {
String query = "SELECT COUNT(*) FROM " + TABLE_NAME;
if (type != null) {
query += " WHERE " + Field.CHANGETYPE.toString() + "=" + type.ordinal();
}
c = readableDb.rawQuery(query, null);
if (c.moveToFirst()) {
noOfChanges = c.getLong(0);
}
} catch (SQLException e) {
LogUtils.logE("NativeChangeLogTable.fetchNoOfChanges() SQLException - Unable to fetch changes", e);
} finally {
CloseUtils.close(c);
c = null;
}
return noOfChanges;
}
Aggregations