diff --git a/aware-core/src/main/java/com/aware/syncadapters/AwareSyncAdapter.java b/aware-core/src/main/java/com/aware/syncadapters/AwareSyncAdapter.java index 7697784cb..2524a35fe 100644 --- a/aware-core/src/main/java/com/aware/syncadapters/AwareSyncAdapter.java +++ b/aware-core/src/main/java/com/aware/syncadapters/AwareSyncAdapter.java @@ -13,6 +13,7 @@ import android.content.SyncResult; import android.database.Cursor; import android.database.DatabaseUtils; +import android.database.sqlite.SQLiteDatabase; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; @@ -151,7 +152,7 @@ private void offloadData(Context context, String database_table, String web_serv } if (Aware.DEBUG) - Log.d(Aware.TAG, "Synching " + database_table + " to: " + web_server + " in batches of " + MAX_POST_SIZE); + Log.d(Aware.TAG, "Syncing " + database_table + " to: " + web_server + " in batches of " + MAX_POST_SIZE); String device_id = Aware.getSetting(context, Aware_Preferences.DEVICE_ID); boolean DEBUG = Aware.getSetting(context, Aware_Preferences.DEBUG_FLAG).equals("true"); @@ -458,35 +459,36 @@ private int getNumberOfRecordsToSync(Uri CONTENT_URI, String[] columnsStr, Strin int TOTAL_RECORDS = 0; if (remoteData.length() == 0) { if (exists(columnsStr, "double_end_timestamp")) { - Cursor counter = mContext.getContentResolver().query(CONTENT_URI, new String[]{"count(*) as entries"}, "double_end_timestamp != 0" + study_condition, null, "_id ASC"); + Cursor counter = mContext.getContentResolver().query(CONTENT_URI, null, "double_end_timestamp != 0" + study_condition, null, "_id ASC"); if (counter != null && counter.moveToFirst()) { - TOTAL_RECORDS = counter.getInt(0); + TOTAL_RECORDS = counter.getCount(); counter.close(); } if (counter != null && !counter.isClosed()) counter.close(); } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) { - Cursor counter = mContext.getContentResolver().query(CONTENT_URI, new String[]{"count(*) as entries"}, "double_esm_user_answer_timestamp != 0" + study_condition, null, "_id ASC"); + Cursor counter = mContext.getContentResolver().query(CONTENT_URI, null, "double_esm_user_answer_timestamp != 0" + study_condition, null, "_id ASC"); if (counter != null && counter.moveToFirst()) { - TOTAL_RECORDS = counter.getInt(0); + TOTAL_RECORDS = counter.getCount(); counter.close(); } if (counter != null && !counter.isClosed()) counter.close(); } else { - Cursor counter = mContext.getContentResolver().query(CONTENT_URI, new String[]{"count(*) as entries"}, "1" + study_condition, null, "_id ASC"); + Cursor counter = mContext.getContentResolver().query(CONTENT_URI, null, "1" + study_condition, null, "_id ASC"); if (counter != null && counter.moveToFirst()) { - TOTAL_RECORDS = counter.getInt(0); + TOTAL_RECORDS = counter.getCount(); counter.close(); } if (counter != null && !counter.isClosed()) counter.close(); + } } else { long last; if (exists(columnsStr, "double_end_timestamp")) { if (remoteData.getJSONObject(0).has("double_end_timestamp")) { last = remoteData.getJSONObject(0).getLong("double_end_timestamp"); - Cursor counter = mContext.getContentResolver().query(CONTENT_URI, new String[]{"count(*) as entries"}, "timestamp > " + last + " AND double_end_timestamp != 0" + study_condition, null, "_id ASC"); + Cursor counter = mContext.getContentResolver().query(CONTENT_URI, null, "timestamp > " + last + " AND double_end_timestamp != 0" + study_condition, null, "_id ASC"); if (counter != null && counter.moveToFirst()) { - TOTAL_RECORDS = counter.getInt(0); + TOTAL_RECORDS = counter.getCount(); counter.close(); } if (counter != null && !counter.isClosed()) counter.close(); @@ -494,9 +496,9 @@ private int getNumberOfRecordsToSync(Uri CONTENT_URI, String[] columnsStr, Strin } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) { if (remoteData.getJSONObject(0).has("double_esm_user_answer_timestamp")) { last = remoteData.getJSONObject(0).getLong("double_esm_user_answer_timestamp"); - Cursor counter = mContext.getContentResolver().query(CONTENT_URI, new String[]{"count(*) as entries"}, "timestamp > " + last + " AND double_esm_user_answer_timestamp != 0" + study_condition, null, "_id ASC"); + Cursor counter = mContext.getContentResolver().query(CONTENT_URI, null, "timestamp > " + last + " AND double_esm_user_answer_timestamp != 0" + study_condition, null, "_id ASC"); if (counter != null && counter.moveToFirst()) { - TOTAL_RECORDS = counter.getInt(0); + TOTAL_RECORDS = counter.getCount(); counter.close(); } if (counter != null && !counter.isClosed()) counter.close(); @@ -504,9 +506,9 @@ private int getNumberOfRecordsToSync(Uri CONTENT_URI, String[] columnsStr, Strin } else { if (remoteData.getJSONObject(0).has("timestamp")) { last = remoteData.getJSONObject(0).getLong("timestamp"); - Cursor counter = mContext.getContentResolver().query(CONTENT_URI, new String[]{"count(*) as entries"}, "timestamp > " + last + study_condition, null, "_id ASC"); + Cursor counter = mContext.getContentResolver().query(CONTENT_URI, null, "timestamp > " + last + study_condition, null, "_id ASC"); if (counter != null && counter.moveToFirst()) { - TOTAL_RECORDS = counter.getInt(0); + TOTAL_RECORDS = counter.getCount(); counter.close(); } if (counter != null && !counter.isClosed()) counter.close();