use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class ActivitiesTable method fetchActivitiesIds.
/**
* Returns a list of activity IDs already synced, in reverse chronological
* order Fetches from the given timestamp.
*
* @param actIdList An empty list which will be filled with the result
* @param timeStamp The time stamp to start the fetch
* @param readableDb Readable SQLite database
* @return SUCCESS or a suitable error code
*/
public static ServiceStatus fetchActivitiesIds(final List<Long> actIdList, final Long timeStamp, final SQLiteDatabase readableDb) {
DatabaseHelper.trace(false, "DatabaseHelper.fetchActivitiesIds()");
Cursor cursor = null;
try {
long queryTimeStamp;
if (timeStamp != null) {
queryTimeStamp = timeStamp;
} else {
queryTimeStamp = 0;
}
cursor = readableDb.rawQuery("SELECT " + Field.ACTIVITY_ID + " FROM " + TABLE_NAME + " WHERE " + Field.TIMESTAMP + " >= " + queryTimeStamp + " ORDER BY " + Field.TIMESTAMP + " DESC", null);
while (cursor.moveToNext()) {
actIdList.add(cursor.getLong(0));
}
} catch (SQLiteException e) {
LogUtils.logE("ActivitiesTable.fetchActivitiesIds()" + "Unable to fetch group list", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
} finally {
CloseUtils.close(cursor);
}
return ServiceStatus.SUCCESS;
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class ContactChangeLogTable method fetchContactChangeLog.
/**
* Fetches a list of changes from the table for a specific type. The list is
* ordered by local contact ID.
*
* @param contactChangeList The list to be populated
* @param type The type of change to return
* @param firstIndex An index of the first record to return (0 based)
* @param count The number of records to return (or -1 to return all)
* @param readableDb Readable SQLite database
* @return true if successful, false otherwise
*/
public static boolean fetchContactChangeLog(List<ContactChangeInfo> contactChangeList, ContactChangeType type, long firstIndex, long count, SQLiteDatabase readableDb) {
if (Settings.ENABLED_DATABASE_TRACE)
DatabaseHelper.trace(false, "ContactChangeLogTable.fetchContactChangeLog() " + "firstIndex[" + firstIndex + "] count[" + count + "]");
Cursor c1 = null;
try {
c1 = readableDb.rawQuery(getQueryStringSql(Field.CHANGETYPE + "=" + type.ordinal() + " ORDER BY " + Field.LOCALCHANGECONTACTID + " LIMIT " + firstIndex + "," + count), null);
contactChangeList.clear();
while (c1.moveToNext()) {
contactChangeList.add(getQueryData(c1));
}
} catch (SQLiteException e) {
LogUtils.logE("ContactChangeLogTable.fetchContactChangeLog() throw e; - Unable to fetch main contact change log", e);
return false;
} finally {
CloseUtils.close(c1);
}
return true;
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class ContactDetailsTable method fetchDetail.
/**
* Fetches the first contact detail found for a contact and key.
*
* @param localContactId The local contact ID
* @param key The contact detail key value
* @param readableDb A readable SQLite database object.
* @return The contact detail, or NULL if it could not be found.
*/
public static ContactDetail fetchDetail(long localContactId, DetailKeys key, SQLiteDatabase readableDb) {
DatabaseHelper.trace(false, "ContactDetailsTable.fetchDetail()");
String[] args = { String.format("%d", localContactId), String.format("%d", key.ordinal()) };
ContactDetail detail = null;
Cursor c = null;
try {
c = readableDb.rawQuery(getQueryStringSql(Field.LOCALCONTACTID + "=? AND " + Field.KEY + "=?"), args);
if (c.moveToFirst()) {
detail = getQueryData(c);
}
} catch (SQLiteException e) {
LogUtils.logE("ContactDetailsTable.fetchDetail() Exception - Unable to fetch contact detail", e);
return null;
} finally {
CloseUtils.close(c);
c = null;
}
return detail;
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class ContactSourceTable method fetchContactSources.
/**
* Fetches all the sources for the specified contact
*
* @param localContactId The local Contact ID from Contacts table
* @param sourceList A list that will be populated with the source strings
* @param readableDb A readable SQLite database
* @return true if successful, false otherwise
*/
public static boolean fetchContactSources(long localContactId, List<String> sourceList, SQLiteDatabase readableDb) {
if (Settings.ENABLED_DATABASE_TRACE) {
DatabaseHelper.trace(false, "ContactSourceTable.fetchContactSources() localContactId[" + localContactId + "]");
}
String[] args = { String.format("%d", localContactId) };
Cursor c1 = null;
sourceList.clear();
try {
c1 = readableDb.rawQuery("SELECT " + Field.SOURCE + " FROM " + TABLE_NAME + " WHERE " + Field.LOCALCONTACTID + " = ?", args);
while (c1.moveToNext()) {
if (!c1.isNull(0)) {
sourceList.add(c1.getString(0));
}
}
} catch (SQLiteException e) {
LogUtils.logE("ContactSourceTable.fetchContactSources() " + "Exception - Unable to fetch contact sources", e);
return false;
} finally {
CloseUtils.close(c1);
c1 = null;
}
return true;
}
use of android.database.sqlite.SQLiteException in project qksms by moezbhatti.
the class ContactHelper method getPhoneNumber.
/**
* Get the phone number of a contact given their id
* TODO: The logic for picking the best phone number could be better
*/
public static String getPhoneNumber(Context context, String contactId) {
String number = "";
Cursor cursor;
try {
cursor = context.getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + " = " + contactId, null, null);
while (cursor.moveToNext()) {
number = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
int type = cursor.getInt(cursor.getColumnIndex(Phone.TYPE));
switch(type) {
case Phone.TYPE_MOBILE:
// Return right away if it's a mobile number
cursor.close();
return number;
}
}
cursor.close();
} catch (SQLiteException e) {
e.printStackTrace();
}
// Return whatever number we found last, since we don't know which is best
return number;
}
Aggregations