Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #253 from raghumulukutla/master
Browse files Browse the repository at this point in the history
SQLite Exception: Update AwareSyncAdapter.java
  • Loading branch information
denzilferreira authored Jan 10, 2019
2 parents 4b141d6 + cfccff5 commit 2df2d90
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -458,55 +459,56 @@ 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();
}
} 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();
}
} 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();
Expand Down

0 comments on commit 2df2d90

Please sign in to comment.