use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class ActivitiesTable method fetchTimelineEventsForContactById.
/**
* Fetches timeline events for a specific contact identified by local
* contact ID in chronological order.
* @param localContactId The local contact ID.
* @param readableDb Readable SQLite database.
* @return The cursor that can be read using
* {@link #getTimelineData(Cursor)}.
*/
public static Cursor fetchTimelineEventsForContactById(final Long localContactId, final SQLiteDatabase readableDb) {
DatabaseHelper.trace(false, "DatabaseHelper." + "fetchTimelineEventsForContact()");
Cursor cursor = null;
try {
final StringBuffer query = StringBufferPool.getStringBuffer();
query.append("SELECT ").append(Field.LOCAL_ACTIVITY_ID).append(",").append(Field.TIMESTAMP).append(",").append(Field.CONTACT_NAME).append(",").append(Field.CONTACT_AVATAR_URL).append(",").append(Field.LOCAL_CONTACT_ID).append(",").append(Field.TITLE).append(",").append(Field.DESCRIPTION).append(",").append(Field.CONTACT_NETWORK).append(",").append(Field.NATIVE_ITEM_TYPE).append(",").append(Field.NATIVE_ITEM_ID).append(",").append(Field.TYPE).append(",").append(Field.CONTACT_ID).append(",").append(Field.USER_ID).append(",").append(Field.NATIVE_THREAD_ID).append(",").append(Field.CONTACT_ADDRESS).append(",").append(Field.INCOMING).append(" FROM ").append(TABLE_NAME).append(" WHERE (").append(Field.FLAG).append("&").append(ActivityItem.TIMELINE_ITEM).append(") AND ").append(Field.LOCAL_CONTACT_ID).append("=").append(localContactId).append(" ORDER BY ").append(Field.TIMESTAMP).append(" DESC");
cursor = readableDb.rawQuery(StringBufferPool.toStringThenRelease(query), null);
} catch (SQLiteException e) {
LogUtils.logE("ActivitiesTable.fetchTimelineEventsForContactById() " + "Unable to fetch timeline event for contact", e);
}
return cursor;
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class ContactSummaryTable method fetchSummaryItem.
/**
* Fetches the contact summary for a particular contact
*
* @param localContactID The primary key ID of the contact to find
* @param summary A new ContactSummary object to be filled in
* @param readableDb Readable SQLite database
* @return SUCCESS or a suitable error code
*/
public static ServiceStatus fetchSummaryItem(long localContactId, ContactSummary summary, SQLiteDatabase readableDb) {
if (Settings.ENABLED_DATABASE_TRACE) {
DatabaseHelper.trace(false, "ContactSummeryTable.fetchSummaryItem() localContactId[" + localContactId + "]");
}
Cursor c1 = null;
try {
c1 = readableDb.rawQuery(getQueryStringSql(Field.LOCALCONTACTID + "=" + localContactId), null);
if (!c1.moveToFirst()) {
LogUtils.logW("ContactSummeryTable.fetchSummaryItem() localContactId[" + localContactId + "] not found in ContactSummeryTable.");
return ServiceStatus.ERROR_NOT_FOUND;
}
summary.copy(getQueryData(c1));
return ServiceStatus.SUCCESS;
} catch (SQLiteException e) {
LogUtils.logE("ContactSummeryTable.fetchSummaryItem() Exception - Unable to fetch contact summary", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
} finally {
CloseUtils.close(c1);
c1 = null;
}
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class ContactsTable method fetchSyncToPhone.
/**
* Fetches the syncToPhone flag for a particular contact.
*
* @param localContactId The primary key ID of the contact to find
* @param readableDb Readable SQLite database
* @return The state of the syncToPhone flag (true or false). Defaults to
* false if the contact is not found or a database error occurs.
*/
protected static boolean fetchSyncToPhone(long localContactId, SQLiteDatabase readableDb) {
DatabaseHelper.trace(false, "ContactsTable.fetchSyncToPhone()");
Cursor c = null;
try {
boolean syncToPhone = false;
c = readableDb.rawQuery("SELECT " + Field.SYNCTOPHONE + " FROM " + TABLE_NAME + " WHERE " + Field.LOCALID + "=" + localContactId, null);
while (c.moveToNext()) {
if (!c.isNull(0)) {
syncToPhone = (c.getInt(0) == 0 ? false : true);
}
}
return syncToPhone;
} catch (SQLiteException e) {
LogUtils.logE("ContactsTable.fetchSyncToPhone() Exception - Unable to run query:\n", e);
return false;
} finally {
CloseUtils.close(c);
}
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class ContactsTable method validateContactId.
/**
* Validates a contact exists and returns the relevant contact id
* information.
*
* @param localContactId The local Id of the contact to find
* @param readableDb Readable database object
* @return A ContactIdInfo object if successful, or NULL if the contact does
* not exist
*/
public static ContactIdInfo validateContactId(long localContactId, SQLiteDatabase readableDb) {
ContactIdInfo info = null;
String[] args = { String.format("%d", localContactId) };
Cursor c = null;
try {
c = readableDb.rawQuery("SELECT " + Field.SERVERID + "," + Field.NATIVECONTACTID + "," + Field.SYNCTOPHONE + " FROM " + TABLE_NAME + " WHERE " + Field.LOCALID + " = ?", args);
if (c.moveToFirst()) {
info = new ContactIdInfo();
if (!c.isNull(0)) {
info.serverId = c.getLong(0);
}
if (!c.isNull(1)) {
info.nativeId = c.getInt(1);
}
if (!c.isNull(2)) {
info.syncToPhone = (c.getInt(2) == 0 ? false : true);
}
info.localId = localContactId;
}
} catch (SQLiteException e) {
LogUtils.logE("ContactsTable.validateContactId() Exception - " + "Unable to validate contact ID", e);
return null;
} finally {
CloseUtils.close(c);
c = null;
}
if (Settings.ENABLED_DATABASE_TRACE) {
DatabaseHelper.trace(false, "ContactsTable.validateContactId() localContactId[" + localContactId + "] serverId[" + info.serverId + "] nativeId[" + info.nativeId + "]");
}
return info;
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class ContactsTable method fetchServerId.
/**
* Finds the server ID associated with a contact
*
* @param localContactId The primary key ID of the contact to find
* @param readableDb Readable SQLite database
* @return The server ID if found, otherwise null.
*/
public static Long fetchServerId(Long localContactId, SQLiteDatabase readableDb) {
DatabaseHelper.trace(false, "ContactsTable.fetchServerId() localContactId[" + localContactId + "]");
Long serverId = null;
String[] args = { String.format("%d", localContactId) };
Cursor c = null;
try {
c = readableDb.rawQuery("SELECT " + Field.SERVERID + " FROM " + TABLE_NAME + " WHERE " + Field.LOCALID + " = ?", args);
if (c.moveToFirst() && !c.isNull(0)) {
serverId = c.getLong(0);
}
} catch (SQLiteException e) {
LogUtils.logE("ContactsTable.fetchServerId() " + "Exception - Unable to validate contact ID", e);
return null;
} finally {
CloseUtils.close(c);
c = null;
}
return serverId;
}
Aggregations