Search in sources :

Example 46 with SQLException

use of android.database.SQLException in project 360-Engine-for-Android by 360.

the class ContactDetailsTable method fetchContactDetails.

/**
     * Fetch details for a given contact
     * 
     * @param localContactId The local ID of the contact
     * @param detailList A list which will be populated with the details
     * @param readableDb A readable SQLite database object.
     * @return SUCCESS or a suitable error code.
     */
public static ServiceStatus fetchContactDetails(Long localContactId, List<ContactDetail> detailList, SQLiteDatabase readableDb) {
    DatabaseHelper.trace(false, "ContactDetailsTable.fetchContactDetails() localContactId[" + localContactId + "]");
    String[] args = { String.format("%d", localContactId) };
    Cursor c = null;
    try {
        c = readableDb.rawQuery(ContactDetailsTable.getQueryStringSql(ContactDetailsTable.Field.LOCALCONTACTID + " = ?"), args);
        detailList.clear();
        while (c.moveToNext()) {
            detailList.add(ContactDetailsTable.getQueryData(c));
        }
    } catch (SQLException e) {
        LogUtils.logE("ContactDetailsTable.fetchContactDetails() Exception - Unable to fetch contact details for contact", e);
        return ServiceStatus.ERROR_DATABASE_CORRUPT;
    } finally {
        CloseUtils.close(c);
    }
    return ServiceStatus.SUCCESS;
}
Also used : SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 47 with SQLException

use of android.database.SQLException in project 360-Engine-for-Android by 360.

the class ActivitiesTable method getLatestContactStatusForContact.

/**
     * This method gets the latest contact status entry for a timeline
     * entry identified by localContactId and timestamp value.
     *
     * @param localContactId Given contact ID.
     * @param timeStamp the timeStamp value for a timeline.
     * @param readableDb Readable SQLite database.
     */
private static int getLatestContactStatusForContact(Long localContactId, Long timeStamp, SQLiteDatabase readableDb) {
    DatabaseHelper.trace(false, "DatabaseHelper." + "getLatestContactStatusForContact()");
    int localContactStatus = 0;
    if (localContactId == null) {
        LogUtils.logE("getLatestContactStatusForContact()" + " localContactId is NULL");
        return localContactStatus;
    }
    Cursor cursor = null;
    try {
        String[] args = { localContactId.toString(), timeStamp.toString() };
        final StringBuffer query = StringBufferPool.getStringBuffer();
        query.append("SELECT ").append(Field.LATEST_CONTACT_STATUS).append(" FROM ").append(TABLE_NAME).append(" WHERE ").append(Field.LOCAL_CONTACT_ID).append("=? AND (").append(Field.FLAG).append("&").append(ActivityItem.TIMELINE_ITEM).append(") AND ").append(Field.TIMESTAMP).append("=?");
        cursor = readableDb.rawQuery(StringBufferPool.toStringThenRelease(query), args);
        if (cursor != null && cursor.moveToFirst()) {
            localContactStatus = cursor.getInt(0);
        }
    } catch (SQLException e) {
        LogUtils.logE("ActivitiesTable.getLatestContactStatusForContact() " + "Unable to fetch latestcontactstatus from Activities table", e);
    } finally {
        CloseUtils.close(cursor);
    }
    return localContactStatus;
}
Also used : SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 48 with SQLException

use of android.database.SQLException in project 360-Engine-for-Android by 360.

the class ActivitiesTable method addChatTimelineEvent.

/**
     * The method returns the ROW_ID i.e. the INTEGER PRIMARY KEY AUTOINCREMENT
     * field value for the inserted row, i.e. LOCAL_ID.
     *
     * @param item TimelineSummaryItem.
     * @param read - TRUE if the chat message is outgoing or gets into the
     *            timeline history view for a contact with LocalContactId.
     * @param writableDb Writable SQLite database.
     * @return LocalContactID or -1 if the row was not inserted.
     */
public static long addChatTimelineEvent(final TimelineSummaryItem item, final boolean read, final SQLiteDatabase writableDb) {
    DatabaseHelper.trace(true, "DatabaseHelper.addChatTimelineEvent()");
    try {
        writableDb.beginTransaction();
        int latestStatusVal = 0;
        if (item.mContactName != null || item.mLocalContactId != null) {
            latestStatusVal |= removeContactGroup(item.mLocalContactId, item.mContactName, item.mTimestamp, ActivityItem.TIMELINE_ITEM, null, writableDb);
            latestStatusVal |= removeContactGroup(item.mLocalContactId, item.mContactName, item.mTimestamp, ActivityItem.TIMELINE_ITEM, new TimelineNativeTypes[] { TimelineNativeTypes.ChatLog }, writableDb);
        }
        ContentValues values = new ContentValues();
        values.put(Field.CONTACT_NAME.toString(), item.mContactName);
        values.put(Field.CONTACT_ID.toString(), item.mContactId);
        values.put(Field.USER_ID.toString(), item.mUserId);
        values.put(Field.LOCAL_CONTACT_ID.toString(), item.mLocalContactId);
        values.put(Field.CONTACT_NETWORK.toString(), item.mContactNetwork);
        values.put(Field.DESCRIPTION.toString(), item.mDescription);
        /** Chat message body. **/
        values.put(Field.TITLE.toString(), item.mTitle);
        values.put(Field.CONTACT_ADDRESS.toString(), item.mContactAddress);
        if (read) {
            values.put(Field.FLAG.toString(), ActivityItem.TIMELINE_ITEM | ActivityItem.ALREADY_READ);
        } else {
            values.put(Field.FLAG.toString(), ActivityItem.TIMELINE_ITEM | 0);
        }
        values.put(Field.NATIVE_ITEM_ID.toString(), item.mNativeItemId);
        values.put(Field.NATIVE_ITEM_TYPE.toString(), item.mNativeItemType);
        values.put(Field.TIMESTAMP.toString(), item.mTimestamp);
        if (item.mType != null) {
            values.put(Field.TYPE.toString(), item.mType.getTypeCode());
        }
        values.put(Field.LATEST_CONTACT_STATUS.toString(), latestStatusVal);
        values.put(Field.NATIVE_THREAD_ID.toString(), item.mNativeThreadId);
        // 0 for incoming, 1 for outgoing
        if (item.mIncoming != null) {
            values.put(Field.INCOMING.toString(), item.mIncoming.ordinal());
        }
        final long itemId = writableDb.insert(TABLE_NAME, null, values);
        if (itemId < 0) {
            LogUtils.logE("ActivitiesTable.addTimelineEvents() - " + "Unable to add timeline list to database, index<0:" + itemId);
            return -1;
        }
        writableDb.setTransactionSuccessful();
        return itemId;
    } catch (SQLException e) {
        LogUtils.logE("ActivitiesTable.addTimelineEvents() SQLException - " + "Unable to add timeline list to database", e);
        return -1;
    } finally {
        writableDb.endTransaction();
    }
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException)

Example 49 with SQLException

use of android.database.SQLException in project 360-Engine-for-Android by 360.

the class FetchNativeContactsTest method fetchSyncNativeId.

private Integer fetchSyncNativeId(Long localDetailID) {
    Integer value = null;
    SQLiteDatabase readableDb = mDb.getReadableDatabase();
    try {
        Cursor c = readableDb.rawQuery("SELECT " + ContactDetailsTable.Field.NATIVESYNCCONTACTID + " FROM " + ContactDetailsTable.TABLE_NAME + " WHERE " + Field.DETAILLOCALID + "=" + localDetailID, null);
        if (c.moveToFirst()) {
            if (!c.isNull(0)) {
                value = c.getInt(0);
            }
        }
        c.close();
    } catch (SQLException e) {
    }
    return value;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 50 with SQLException

use of android.database.SQLException in project 360-Engine-for-Android by 360.

the class TestModule method addNativeContactMethod.

public NativeDetail addNativeContactMethod(ContentResolver cr, int id, int kind, boolean isPrimary) {
    ContentValues cv = new ContentValues();
    cv.put(Contacts.ContactMethods.PERSON_ID, id);
    String data = null;
    switch(kind) {
        case CONTACT_METHODS_KIND_EMAIL:
            data = "testtesttest@test.com";
            break;
        case CONTACT_METHODS_KIND_ADDRESS:
            data = generateNativeAddress();
            break;
        default:
            data = generateRandomString();
            break;
    }
    int type = generateRandomInt() & 3;
    if (type == 0) {
        cv.put(Contacts.ContactMethods.LABEL, generateRandomString());
    }
    cv.put(Contacts.ContactMethods.DATA, data);
    cv.put(Contacts.ContactMethods.TYPE, type);
    cv.put(Contacts.ContactMethods.KIND, kind);
    cv.put(Contacts.ContactMethods.ISPRIMARY, (isPrimary ? 1 : 0));
    Uri uriCm;
    try {
        uriCm = cr.insert(Contacts.ContactMethods.CONTENT_URI, cv);
        if (uriCm == null) {
            return null;
        }
    } catch (SQLException e) {
        return null;
    }
    NativeDetail nd = new NativeDetail();
    nd.mValue1 = data;
    nd.mValue2 = String.valueOf(kind);
    nd.mValue3 = String.valueOf(type);
    nd.mIsPrimary = isPrimary;
    nd.mId = (int) ContentUris.parseId(uriCm);
    return nd;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Uri(android.net.Uri)

Aggregations

SQLException (android.database.SQLException)154 Cursor (android.database.Cursor)51 ContentValues (android.content.ContentValues)50 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)31 Uri (android.net.Uri)30 SQLiteStatement (android.database.sqlite.SQLiteStatement)13 ArrayList (java.util.ArrayList)10 DatabaseUtils (android.database.DatabaseUtils)8 Gson (com.google.gson.Gson)8 RAction (io.github.mthli.Bitocle.Database.Repo.RAction)7 Repo (io.github.mthli.Bitocle.Database.Repo.Repo)6 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 IOException (java.io.IOException)5 BAction (io.github.mthli.Bitocle.Database.Bookmark.BAction)4 Test (org.junit.Test)4 Activity (android.app.Activity)3 ContentResolver (android.content.ContentResolver)3 Context (android.content.Context)3 LayoutInflater (android.view.LayoutInflater)3