mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
* Added wikidataEntityID in all db versions, handled db.execSql via method runQuery
This commit is contained in:
parent
6365815e0d
commit
64eae8be82
2 changed files with 31 additions and 23 deletions
|
|
@ -4,19 +4,18 @@ import android.content.ContentProviderClient;
|
|||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.net.Uri;
|
||||
import android.os.RemoteException;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import fr.free.nrw.commons.utils.StringUtils;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import fr.free.nrw.commons.utils.StringUtils;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static fr.free.nrw.commons.contributions.ContributionDao.Table.ALL_FIELDS;
|
||||
import static fr.free.nrw.commons.contributions.ContributionDao.Table.COLUMN_WIKI_DATA_ENTITY_ID;
|
||||
|
|
@ -262,16 +261,20 @@ public class ContributionDao {
|
|||
if (from == to) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Considering the crashes we have been facing recently, lets blindly add this column to any table which has ever existed
|
||||
runQuery(db,ADD_WIKI_DATA_ENTITY_ID_FIELD);
|
||||
|
||||
if (from == 1) {
|
||||
db.execSQL(ADD_DESCRIPTION_FIELD);
|
||||
db.execSQL(ADD_CREATOR_FIELD);
|
||||
runQuery(db,ADD_DESCRIPTION_FIELD);
|
||||
runQuery(db,ADD_CREATOR_FIELD);
|
||||
from++;
|
||||
onUpdate(db, from, to);
|
||||
return;
|
||||
}
|
||||
if (from == 2) {
|
||||
db.execSQL(ADD_MULTIPLE_FIELD);
|
||||
db.execSQL(SET_DEFAULT_MULTIPLE);
|
||||
runQuery(db, ADD_MULTIPLE_FIELD);
|
||||
runQuery(db, SET_DEFAULT_MULTIPLE);
|
||||
from++;
|
||||
onUpdate(db, from, to);
|
||||
return;
|
||||
|
|
@ -290,23 +293,34 @@ public class ContributionDao {
|
|||
}
|
||||
if (from == 5) {
|
||||
// Added width and height fields
|
||||
db.execSQL(ADD_WIDTH_FIELD);
|
||||
db.execSQL(SET_DEFAULT_WIDTH);
|
||||
db.execSQL(ADD_HEIGHT_FIELD);
|
||||
db.execSQL(SET_DEFAULT_HEIGHT);
|
||||
db.execSQL(ADD_LICENSE_FIELD);
|
||||
db.execSQL(SET_DEFAULT_LICENSE);
|
||||
runQuery(db, ADD_WIDTH_FIELD);
|
||||
runQuery(db, SET_DEFAULT_WIDTH);
|
||||
runQuery(db, ADD_HEIGHT_FIELD);
|
||||
runQuery(db, SET_DEFAULT_HEIGHT);
|
||||
runQuery(db, ADD_LICENSE_FIELD);
|
||||
runQuery(db, SET_DEFAULT_LICENSE);
|
||||
from++;
|
||||
onUpdate(db, from, to);
|
||||
return;
|
||||
}
|
||||
if (from > 5) {
|
||||
// Added place field
|
||||
db.execSQL(ADD_WIKI_DATA_ENTITY_ID_FIELD);
|
||||
from++;
|
||||
from=to;
|
||||
onUpdate(db, from, to);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* perform the db.execSQl with handled exceptions
|
||||
*/
|
||||
private static void runQuery(SQLiteDatabase db, String query) {
|
||||
try {
|
||||
db.execSQL(query);
|
||||
} catch (SQLiteException e) {
|
||||
Timber.e("Exception performing query: " + query + " message: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,17 +78,11 @@ class ContributionDaoTest {
|
|||
@Test
|
||||
fun upgradeDatabase_v3_to_v4() {
|
||||
Table.onUpdate(database, 3, 4)
|
||||
|
||||
// No changes
|
||||
verifyZeroInteractions(database)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun upgradeDatabase_v4_to_v5() {
|
||||
Table.onUpdate(database, 4, 5)
|
||||
|
||||
// No changes
|
||||
verifyZeroInteractions(database)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue