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
36847105e3
commit
e90049bb31
2 changed files with 31 additions and 23 deletions
|
|
@ -4,19 +4,18 @@ import android.content.ContentProviderClient;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteException;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import fr.free.nrw.commons.settings.Prefs;
|
||||||
|
import fr.free.nrw.commons.utils.StringUtils;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
import timber.log.Timber;
|
||||||
import fr.free.nrw.commons.settings.Prefs;
|
|
||||||
import fr.free.nrw.commons.utils.StringUtils;
|
|
||||||
|
|
||||||
import static fr.free.nrw.commons.contributions.ContributionDao.Table.ALL_FIELDS;
|
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;
|
import static fr.free.nrw.commons.contributions.ContributionDao.Table.COLUMN_WIKI_DATA_ENTITY_ID;
|
||||||
|
|
@ -262,16 +261,20 @@ public class ContributionDao {
|
||||||
if (from == to) {
|
if (from == to) {
|
||||||
return;
|
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) {
|
if (from == 1) {
|
||||||
db.execSQL(ADD_DESCRIPTION_FIELD);
|
runQuery(db,ADD_DESCRIPTION_FIELD);
|
||||||
db.execSQL(ADD_CREATOR_FIELD);
|
runQuery(db,ADD_CREATOR_FIELD);
|
||||||
from++;
|
from++;
|
||||||
onUpdate(db, from, to);
|
onUpdate(db, from, to);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (from == 2) {
|
if (from == 2) {
|
||||||
db.execSQL(ADD_MULTIPLE_FIELD);
|
runQuery(db, ADD_MULTIPLE_FIELD);
|
||||||
db.execSQL(SET_DEFAULT_MULTIPLE);
|
runQuery(db, SET_DEFAULT_MULTIPLE);
|
||||||
from++;
|
from++;
|
||||||
onUpdate(db, from, to);
|
onUpdate(db, from, to);
|
||||||
return;
|
return;
|
||||||
|
|
@ -290,23 +293,34 @@ public class ContributionDao {
|
||||||
}
|
}
|
||||||
if (from == 5) {
|
if (from == 5) {
|
||||||
// Added width and height fields
|
// Added width and height fields
|
||||||
db.execSQL(ADD_WIDTH_FIELD);
|
runQuery(db, ADD_WIDTH_FIELD);
|
||||||
db.execSQL(SET_DEFAULT_WIDTH);
|
runQuery(db, SET_DEFAULT_WIDTH);
|
||||||
db.execSQL(ADD_HEIGHT_FIELD);
|
runQuery(db, ADD_HEIGHT_FIELD);
|
||||||
db.execSQL(SET_DEFAULT_HEIGHT);
|
runQuery(db, SET_DEFAULT_HEIGHT);
|
||||||
db.execSQL(ADD_LICENSE_FIELD);
|
runQuery(db, ADD_LICENSE_FIELD);
|
||||||
db.execSQL(SET_DEFAULT_LICENSE);
|
runQuery(db, SET_DEFAULT_LICENSE);
|
||||||
from++;
|
from++;
|
||||||
onUpdate(db, from, to);
|
onUpdate(db, from, to);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (from > 5) {
|
if (from > 5) {
|
||||||
// Added place field
|
// Added place field
|
||||||
db.execSQL(ADD_WIKI_DATA_ENTITY_ID_FIELD);
|
from=to;
|
||||||
from++;
|
|
||||||
onUpdate(db, from, to);
|
onUpdate(db, from, to);
|
||||||
return;
|
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
|
@Test
|
||||||
fun upgradeDatabase_v3_to_v4() {
|
fun upgradeDatabase_v3_to_v4() {
|
||||||
Table.onUpdate(database, 3, 4)
|
Table.onUpdate(database, 3, 4)
|
||||||
|
|
||||||
// No changes
|
|
||||||
verifyZeroInteractions(database)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun upgradeDatabase_v4_to_v5() {
|
fun upgradeDatabase_v4_to_v5() {
|
||||||
Table.onUpdate(database, 4, 5)
|
Table.onUpdate(database, 4, 5)
|
||||||
|
|
||||||
// No changes
|
|
||||||
verifyZeroInteractions(database)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue