44import android .content .ContentValues ;
55import android .database .Cursor ;
66import android .database .sqlite .SQLiteDatabase ;
7+ import android .database .sqlite .SQLiteException ;
78import android .net .Uri ;
89import android .os .RemoteException ;
910import android .support .annotation .Nullable ;
1011import android .text .TextUtils ;
11-
12+ import fr .free .nrw .commons .settings .Prefs ;
13+ import fr .free .nrw .commons .utils .StringUtils ;
1214import java .util .Date ;
13-
1415import javax .inject .Inject ;
1516import javax .inject .Named ;
1617import javax .inject .Provider ;
17-
18- import fr .free .nrw .commons .settings .Prefs ;
19- import fr .free .nrw .commons .utils .StringUtils ;
18+ import timber .log .Timber ;
2019
2120import static fr .free .nrw .commons .contributions .ContributionDao .Table .ALL_FIELDS ;
2221import static fr .free .nrw .commons .contributions .ContributionDao .Table .COLUMN_WIKI_DATA_ENTITY_ID ;
@@ -262,16 +261,20 @@ public static void onUpdate(SQLiteDatabase db, int from, int to) {
262261 if (from == to ) {
263262 return ;
264263 }
264+
265+ //Considering the crashes we have been facing recently, lets blindly add this column to any table which has ever existed
266+ runQuery (db ,ADD_WIKI_DATA_ENTITY_ID_FIELD );
267+
265268 if (from == 1 ) {
266- db . execSQL ( ADD_DESCRIPTION_FIELD );
267- db . execSQL ( ADD_CREATOR_FIELD );
269+ runQuery ( db , ADD_DESCRIPTION_FIELD );
270+ runQuery ( db , ADD_CREATOR_FIELD );
268271 from ++;
269272 onUpdate (db , from , to );
270273 return ;
271274 }
272275 if (from == 2 ) {
273- db . execSQL ( ADD_MULTIPLE_FIELD );
274- db . execSQL ( SET_DEFAULT_MULTIPLE );
276+ runQuery ( db , ADD_MULTIPLE_FIELD );
277+ runQuery ( db , SET_DEFAULT_MULTIPLE );
275278 from ++;
276279 onUpdate (db , from , to );
277280 return ;
@@ -290,23 +293,34 @@ public static void onUpdate(SQLiteDatabase db, int from, int to) {
290293 }
291294 if (from == 5 ) {
292295 // Added width and height fields
293- db . execSQL ( ADD_WIDTH_FIELD );
294- db . execSQL ( SET_DEFAULT_WIDTH );
295- db . execSQL ( ADD_HEIGHT_FIELD );
296- db . execSQL ( SET_DEFAULT_HEIGHT );
297- db . execSQL ( ADD_LICENSE_FIELD );
298- db . execSQL ( SET_DEFAULT_LICENSE );
296+ runQuery ( db , ADD_WIDTH_FIELD );
297+ runQuery ( db , SET_DEFAULT_WIDTH );
298+ runQuery ( db , ADD_HEIGHT_FIELD );
299+ runQuery ( db , SET_DEFAULT_HEIGHT );
300+ runQuery ( db , ADD_LICENSE_FIELD );
301+ runQuery ( db , SET_DEFAULT_LICENSE );
299302 from ++;
300303 onUpdate (db , from , to );
301304 return ;
302305 }
303306 if (from > 5 ) {
304307 // Added place field
305- db .execSQL (ADD_WIKI_DATA_ENTITY_ID_FIELD );
306- from ++;
308+ from =to ;
307309 onUpdate (db , from , to );
308310 return ;
309311 }
310312 }
313+
314+ /**
315+ * perform the db.execSQl with handled exceptions
316+ */
317+ private static void runQuery (SQLiteDatabase db , String query ) {
318+ try {
319+ db .execSQL (query );
320+ } catch (SQLiteException e ) {
321+ Timber .e ("Exception performing query: " + query + " message: " + e .getMessage ());
322+ }
323+ }
324+
311325 }
312326}
0 commit comments