Search in sources :

Example 91 with SQLException

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

the class NativeChangeLogTable method addContactChange.

/**
 * Inserts a contact change into the table.
 *
 * @param info contact change info. This must have a valid type field and
 *            depending on type other fields may also be required (see
 *            {@link ContactChangeType}).
 * @param writableDb Writable SQLite database
 * @return true if successful, false otherwise
 */
private static boolean addContactChange(ContactChangeInfo info, SQLiteDatabase writableDb) {
    DatabaseHelper.trace(true, "NativeChangeLogTable.addContactChange()");
    try {
        ContentValues changeValues = new ContentValues();
        changeValues.put(Field.CHANGETYPE.toString(), info.mType.ordinal());
        changeValues.put(Field.LOCALCONTACTID.toString(), info.mLocalContactId);
        if (info.mDetailKey != null) {
            changeValues.put(Field.DETAILKEY.toString(), info.mDetailKey.ordinal());
        }
        if (info.mNativeContactId != null) {
            changeValues.put(Field.NATIVECONTACTID.toString(), info.mNativeContactId);
        }
        if (info.mNativeDetailId != null) {
            changeValues.put(Field.NATIVEDETAILID.toString(), info.mNativeDetailId);
        }
        if (info.mLocalDetailId != null) {
            changeValues.put(Field.LOCALDETAILID.toString(), info.mLocalDetailId);
        }
        Time time = new Time();
        time.setToNow();
        changeValues.put(Field.TIMESTAMP.toString(), time.format2445());
        long id = writableDb.insertOrThrow(TABLE_NAME, null, changeValues);
        if (id < 0) {
            LogUtils.logE("NativeChangeLogTable.addContactChange() Unable to add contact change to log table - a database error has occurred");
            return false;
        }
        info.mNativeChangeId = id;
        return true;
    } catch (SQLException e) {
        LogUtils.logE("NativeChangeLogTable.addContactChange() SQLException - Unable to add contact change to log table", e);
        return false;
    }
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Time(android.text.format.Time)

Example 92 with SQLException

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

the class NativeChangeLogTable method isContactChangeInList.

/**
 * @param nativeContactId
 * @param type
 * @param readableDb
 * @return
 */
public static boolean isContactChangeInList(long nativeContactId, ContactChangeType type, SQLiteDatabase readableDb) {
    DatabaseHelper.trace(false, "NativeChangeLogTable.isContactChangeInList()");
    Cursor c = null;
    try {
        c = readableDb.rawQuery("SELECT " + Field.LOCALCONTACTID + " FROM " + TABLE_NAME + " WHERE " + Field.NATIVECONTACTID + "=" + nativeContactId + " AND " + Field.CHANGETYPE + "=" + type.ordinal(), null);
        if (c.moveToFirst()) {
            return true;
        }
        return false;
    } catch (SQLException e) {
        return false;
    } finally {
        CloseUtils.close(c);
        c = null;
    }
}
Also used : SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 93 with SQLException

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

the class NativeChangeLogTable method isContactDetailChangeInList.

/**
 * Determines if a specific contact detail and change type exists in the
 * change log.
 *
 * @param localDetailId Local contact detail ID from ContactDetail table
 * @param type The change type to find
 * @param readableDb Readable SQLite database
 * @return true if the change is found, false otherwise
 */
private static boolean isContactDetailChangeInList(Long localDetailId, ContactChangeType type, SQLiteDatabase readableDb) {
    DatabaseHelper.trace(false, "NativeChangeLogTable.isContactDetailChangeInList()");
    Cursor c = null;
    try {
        c = readableDb.rawQuery("SELECT " + Field.LOCALDETAILID + " FROM " + TABLE_NAME + " WHERE " + Field.LOCALDETAILID + "=" + localDetailId + " AND " + Field.CHANGETYPE + "=" + type.ordinal(), null);
        if (c.moveToFirst()) {
            return true;
        }
        return false;
    } catch (SQLException e) {
        return false;
    } finally {
        CloseUtils.close(c);
        c = null;
    }
}
Also used : SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 94 with SQLException

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

the class NativeChangeLogTable method isContactChangeInList.

/**
 * Determines if a specific contact and change type exists in the change
 * log.
 *
 * @param localContactId Local contact ID from the Contacts table
 * @param type The change type to find
 * @param readableDb Readable SQLite database
 * @return true if the change is found, false otherwise
 */
public static boolean isContactChangeInList(Long localContactId, ContactChangeType type, SQLiteDatabase readableDb) {
    DatabaseHelper.trace(false, "NativeChangeLogTable.isContactChangeInList()");
    Cursor c = null;
    try {
        c = readableDb.rawQuery("SELECT " + Field.LOCALCONTACTID + " FROM " + TABLE_NAME + " WHERE " + Field.LOCALCONTACTID + "=" + localContactId + " AND " + Field.CHANGETYPE + "=" + type.ordinal(), null);
        if (c.moveToFirst()) {
            return true;
        }
        return false;
    } catch (SQLException e) {
        return false;
    } finally {
        CloseUtils.close(c);
        c = null;
    }
}
Also used : SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 95 with SQLException

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

the class NativeChangeLogTable method syncDeleteNativeChangeLog.

/**
 * Removes a list of changes from the change log table. This method is used
 * once the native has been successfully updated by the client.
 *
 * @param changeIdList A list of contact change IDs (can be obtained from
 *            {@link ContactChangeInfo#mNativeChangeId}.
 * @param writableDb Writable SQLite database
 * @return true if successful, false otherwise
 */
public static boolean syncDeleteNativeChangeLog(List<Long> changeIdList, SQLiteDatabase writableDb) {
    DatabaseHelper.trace(true, "NativeChangeLogTable.syncDeleteNativeChangeLog()");
    try {
        writableDb.beginTransaction();
        writableDb.execSQL("DROP TABLE IF EXISTS " + TEMP_CONTACT_CHANGE_TABLE);
        writableDb.execSQL("CREATE TEMPORARY TABLE " + TEMP_CONTACT_CHANGE_TABLE + "(" + TEMP_CONTACT_CHANGE_TABLE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + TEMP_CONTACT_CHANGE_LOG_ID + " LONG);");
        ContentValues values = new ContentValues();
        for (Long changeId : changeIdList) {
            values.put(TEMP_CONTACT_CHANGE_LOG_ID, changeId);
            if (writableDb.insertOrThrow(TEMP_CONTACT_CHANGE_TABLE, null, values) < 0) {
                return false;
            }
        }
        writableDb.execSQL("DELETE FROM " + TABLE_NAME + " WHERE " + Field.NATIVECHANGEID + " IN (SELECT " + TEMP_CONTACT_CHANGE_LOG_ID + " FROM " + TEMP_CONTACT_CHANGE_TABLE + ");");
        writableDb.setTransactionSuccessful();
        return true;
    } catch (SQLException e) {
        LogUtils.logE("NativeChangeLogTable.syncDeleteNativeChangeLog() " + "SQLException - Unable to remove contact detail change from log", e);
        return false;
    } finally {
        writableDb.endTransaction();
    }
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException)

Aggregations

SQLException (android.database.SQLException)224 ContentValues (android.content.ContentValues)114 Uri (android.net.Uri)60 Cursor (android.database.Cursor)57 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)39 SQLiteException (android.database.sqlite.SQLiteException)18 Intent (android.content.Intent)16 ArrayList (java.util.ArrayList)14 SQLiteStatement (android.database.sqlite.SQLiteStatement)13 HandlerThread (android.os.HandlerThread)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