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;
}
}
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;
}
}
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;
}
}
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;
}
}
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();
}
}
Aggregations