Search in sources :

Example 1 with DetailKeys

use of com.vodafone360.people.datatypes.ContactDetail.DetailKeys 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 2 with DetailKeys

use of com.vodafone360.people.datatypes.ContactDetail.DetailKeys in project 360-Engine-for-Android by 360.

the class ContactDetailsTable method fetchContactDetailsForNative.

/**
     * Fetches all contact details that need to be synced with the native
     * contacts database
     * 
     * @param detailList A list that will be populated with the contact details.
     * @param keyList A list of keys to filter the result
     * @param byDetailId true to order the details by native detail ID, false to
     *            order by native contact ID
     * @param firstIndex The index of the first record to fetch
     * @param count The number of records to fetch (or -1 to fetch all)
     * @param readableDb A readable SQLite database object.
     * @return true if the operation was successful, false otherwise
     */
public static boolean fetchContactDetailsForNative(List<ContactDetail> detailList, DetailKeys[] keyList, boolean byDetailId, int firstIndex, int count, SQLiteDatabase readableDb) {
    DatabaseHelper.trace(false, "ContactDetailsTable.fetchContactDetailsForNative()");
    detailList.clear();
    Cursor c = null;
    try {
        StringBuilder sb1 = new StringBuilder();
        for (int i = 0; i < keyList.length; i++) {
            sb1.append(Field.KEY + " = " + keyList[i].ordinal());
            if (i < keyList.length - 1) {
                sb1.append(" OR ");
            }
        }
        String orderByText = null;
        if (byDetailId) {
            orderByText = Field.NATIVEDETAILID.toString();
        } else {
            orderByText = Field.NATIVECONTACTID.toString();
        }
        c = readableDb.rawQuery("SELECT " + getFullQueryList() + ", " + Field.NATIVESYNCCONTACTID + " FROM " + TABLE_NAME + " WHERE " + Field.NATIVECONTACTID + " IS NOT NULL AND (" + sb1 + ") ORDER BY " + orderByText + " LIMIT " + firstIndex + "," + count, null);
        while (c.moveToNext()) {
            ContactDetail detail = getQueryData(c);
            final int fieldIdx = getQueryDataLength();
            if (!c.isNull(fieldIdx)) {
                detail.syncNativeContactId = c.getInt(fieldIdx);
            }
            detailList.add(detail);
        }
        return true;
    } catch (SQLException e) {
        return false;
    } finally {
        CloseUtils.close(c);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Aggregations

Cursor (android.database.Cursor)2 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)2 SQLException (android.database.SQLException)1 SQLiteException (android.database.sqlite.SQLiteException)1