4
4
import android .content .ContentValues ;
5
5
import android .database .Cursor ;
6
6
import android .database .sqlite .SQLiteDatabase ;
7
+ import android .database .sqlite .SQLiteException ;
7
8
import android .net .Uri ;
8
9
import android .os .RemoteException ;
9
10
import android .support .annotation .Nullable ;
10
11
import android .text .TextUtils ;
11
-
12
+ import fr .free .nrw .commons .settings .Prefs ;
13
+ import fr .free .nrw .commons .utils .StringUtils ;
12
14
import java .util .Date ;
13
-
14
15
import javax .inject .Inject ;
15
16
import javax .inject .Named ;
16
17
import 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 ;
20
19
21
20
import static fr .free .nrw .commons .contributions .ContributionDao .Table .ALL_FIELDS ;
22
21
import 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) {
262
261
if (from == to ) {
263
262
return ;
264
263
}
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
+
265
268
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 );
268
271
from ++;
269
272
onUpdate (db , from , to );
270
273
return ;
271
274
}
272
275
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 );
275
278
from ++;
276
279
onUpdate (db , from , to );
277
280
return ;
@@ -290,23 +293,34 @@ public static void onUpdate(SQLiteDatabase db, int from, int to) {
290
293
}
291
294
if (from == 5 ) {
292
295
// 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 );
299
302
from ++;
300
303
onUpdate (db , from , to );
301
304
return ;
302
305
}
303
306
if (from > 5 ) {
304
307
// Added place field
305
- db .execSQL (ADD_WIKI_DATA_ENTITY_ID_FIELD );
306
- from ++;
308
+ from =to ;
307
309
onUpdate (db , from , to );
308
310
return ;
309
311
}
310
312
}
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
+
311
325
}
312
326
}
0 commit comments