First of all, you have a write function that checks if an id exists in a particular table:
public boolean isServerIdExist(String table_name, int server_id) { long line = DatabaseUtils.longForQuery(mDB, "SELECT COUNT(*) FROM " + table_name + " WHERE id=?", new String[]{Integer.toString(server_id)}); return line > 0; }
You need to pass table_name and id what you like
public long insertOrUpdateAccountDevice(int server_id, int account_id, String device_name, String device_id, String last_active, String itp, String utp, int status) { ContentValues values = new ContentValues(); values.put(ACCOUNT_DEVICE_ACCOUNT_ID, account_id); values.put(ACCOUNT_DEVICE_DEVICE_NAME, device_name); values.put(ACCOUNT_DEVICE_DEVICE_ID, device_id); values.put(ACCOUNT_DEVICE_LAST_ACTIVE, last_active); values.put(ACCOUNT_DEVICE_ITP, itp); values.put(ACCOUNT_DEVICE_UTP, utp); values.put(ACCOUNT_DEVICE_STATUS, status);
Hope this helps you.
source share