mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	Add destroyed column to BookmarkLocation table (##3729) (#3774)
* Add destroyed column to BookmarkLocation table (##3729) * switch with fall through for migrations
This commit is contained in:
		
							parent
							
								
									7a49ca12a4
								
							
						
					
					
						commit
						82d662c8ef
					
				
					 3 changed files with 38 additions and 38 deletions
				
			
		|  | @ -164,7 +164,7 @@ public class BookmarkLocationsDao { | |||
|                 cursor.getString(cursor.getColumnIndex(Table.COLUMN_CATEGORY)), | ||||
|                 builder.build(), | ||||
|                 cursor.getString(cursor.getColumnIndex(Table.COLUMN_PIC)), | ||||
|                 null | ||||
|                 cursor.getString(cursor.getColumnIndex(Table.COLUMN_DESTROYED)) | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|  | @ -181,6 +181,7 @@ public class BookmarkLocationsDao { | |||
|         cv.put(BookmarkLocationsDao.Table.COLUMN_LAT, bookmarkLocation.location.getLatitude()); | ||||
|         cv.put(BookmarkLocationsDao.Table.COLUMN_LONG, bookmarkLocation.location.getLongitude()); | ||||
|         cv.put(BookmarkLocationsDao.Table.COLUMN_PIC, bookmarkLocation.pic); | ||||
|         cv.put(BookmarkLocationsDao.Table.COLUMN_DESTROYED, bookmarkLocation.destroyed); | ||||
|         return cv; | ||||
|     } | ||||
| 
 | ||||
|  | @ -199,6 +200,7 @@ public class BookmarkLocationsDao { | |||
|         static final String COLUMN_WIKIDATA_LINK = "location_wikidata_link"; | ||||
|         static final String COLUMN_COMMONS_LINK = "location_commons_link"; | ||||
|         static final String COLUMN_PIC = "location_pic"; | ||||
|         static final String COLUMN_DESTROYED = "location_destroyed"; | ||||
| 
 | ||||
|         // NOTE! KEEP IN SAME ORDER AS THEY ARE DEFINED UP THERE. HELPS HARD CODE COLUMN INDICES. | ||||
|         public static final String[] ALL_FIELDS = { | ||||
|  | @ -213,7 +215,8 @@ public class BookmarkLocationsDao { | |||
|                 COLUMN_WIKIPEDIA_LINK, | ||||
|                 COLUMN_WIKIDATA_LINK, | ||||
|                 COLUMN_COMMONS_LINK, | ||||
|                 COLUMN_PIC | ||||
|                 COLUMN_PIC, | ||||
|                 COLUMN_DESTROYED | ||||
|         }; | ||||
| 
 | ||||
|         static final String DROP_TABLE_STATEMENT = "DROP TABLE IF EXISTS " + TABLE_NAME; | ||||
|  | @ -230,7 +233,8 @@ public class BookmarkLocationsDao { | |||
|                 + COLUMN_WIKIPEDIA_LINK + " STRING," | ||||
|                 + COLUMN_WIKIDATA_LINK + " STRING," | ||||
|                 + COLUMN_COMMONS_LINK + " STRING," | ||||
|                 + COLUMN_PIC + " STRING" | ||||
|                 + COLUMN_PIC + " STRING," | ||||
|                 + COLUMN_DESTROYED + " STRING" | ||||
|                 + ");"; | ||||
| 
 | ||||
|         public static void onCreate(SQLiteDatabase db) { | ||||
|  | @ -244,37 +248,24 @@ public class BookmarkLocationsDao { | |||
| 
 | ||||
|         public static void onUpdate(SQLiteDatabase db, int from, int to) { | ||||
|             Timber.d("bookmarksLocations db is updated from:"+from+", to:"+to); | ||||
|             if (from == to) { | ||||
|                 return; | ||||
|             } | ||||
|             if (from < 7) { | ||||
|                 // doesn't exist yet | ||||
|                 from++; | ||||
|                 onUpdate(db, from, to); | ||||
|                 return; | ||||
|             } | ||||
|             if (from == 7) { | ||||
|                 // table added in version 8 | ||||
|                 onCreate(db); | ||||
|                 from++; | ||||
|                 onUpdate(db, from, to); | ||||
|                 return; | ||||
|             } | ||||
|             if (from == 8) { | ||||
|                 from++; | ||||
|                 onUpdate(db, from, to); | ||||
|                 return; | ||||
|             } | ||||
|             if (from == 10 && to == 11) { | ||||
|                 from++; | ||||
|                 //This is safe, and can be called clean, as we/I do not remember the appropriate version for this | ||||
|                 //We are anyways switching to room, these things won't be nescessary then | ||||
|                 try { | ||||
|                     db.execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_pic STRING;"); | ||||
|                 }catch (SQLiteException exception){ | ||||
|                     Timber.e(exception);// | ||||
|                 } | ||||
|                 return; | ||||
|             switch (from) { | ||||
|                 case 7: onCreate(db); | ||||
|                 case 8: // No change | ||||
|                 case 9: // No change | ||||
|                 case 10: | ||||
|                     try { | ||||
|                         db.execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_pic STRING;"); | ||||
|                     } catch (SQLiteException exception){ | ||||
|                         Timber.e(exception); | ||||
|                     } | ||||
|                 case 11: // No change | ||||
|                 case 12: | ||||
|                     try { | ||||
|                         db.execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_destroyed STRING;"); | ||||
|                     }catch (SQLiteException exception){ | ||||
|                         Timber.e(exception); | ||||
|                     } | ||||
|                     break; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao; | |||
| public class DBOpenHelper  extends SQLiteOpenHelper { | ||||
| 
 | ||||
|     private static final String DATABASE_NAME = "commons.db"; | ||||
|     private static final int DATABASE_VERSION = 12; | ||||
|     private static final int DATABASE_VERSION = 13; | ||||
|     public static final String CONTRIBUTIONS_TABLE = "contributions"; | ||||
|     private final String DROP_TABLE_STATEMENT="DROP TABLE IF EXISTS %s"; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vaibhav
						Vaibhav