Search in sources :

Example 56 with SQLiteException

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;
}
Also used : Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 57 with SQLiteException

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;
}
Also used : Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 58 with SQLiteException

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;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 59 with SQLiteException

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;
}
Also used : Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 60 with SQLiteException

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;
}
Also used : Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException) Paint(android.graphics.Paint)

Aggregations

SQLiteException (android.database.sqlite.SQLiteException)122 Cursor (android.database.Cursor)72 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)36 ContentValues (android.content.ContentValues)28 SQLException (android.database.SQLException)17 Intent (android.content.Intent)14 HandlerThread (android.os.HandlerThread)10 File (java.io.File)10 HashMap (java.util.HashMap)8 Account (android.accounts.Account)7 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)7 SyncStatusInfo (android.content.SyncStatusInfo)6 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)6 BufferedWriter (java.io.BufferedWriter)6 FileWriter (java.io.FileWriter)6 Uri (android.net.Uri)5 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)4 SQLiteStatement (android.database.sqlite.SQLiteStatement)3 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)3