Merge pull request #768 from tised/#733_#732_fix

fix for #733,732 issue
This commit is contained in:
Josephine Lim 2017-07-11 16:30:10 +10:00 committed by GitHub
commit 691acbf983
2 changed files with 11 additions and 16 deletions

View file

@ -10,7 +10,6 @@ import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import fr.free.nrw.commons.CommonsApplication; import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.data.DBOpenHelper;
import timber.log.Timber; import timber.log.Timber;
public class ContributionsContentProvider extends ContentProvider{ public class ContributionsContentProvider extends ContentProvider{
@ -33,10 +32,8 @@ public class ContributionsContentProvider extends ContentProvider{
return Uri.parse(BASE_URI.toString() + "/" + id); return Uri.parse(BASE_URI.toString() + "/" + id);
} }
private DBOpenHelper dbOpenHelper;
@Override @Override
public boolean onCreate() { public boolean onCreate() {
dbOpenHelper = CommonsApplication.getInstance().getDBOpenHelper();
return false; return false;
} }
@ -47,7 +44,7 @@ public class ContributionsContentProvider extends ContentProvider{
int uriType = uriMatcher.match(uri); int uriType = uriMatcher.match(uri);
SQLiteDatabase db = dbOpenHelper.getReadableDatabase(); SQLiteDatabase db = CommonsApplication.getInstance().getDBOpenHelper().getReadableDatabase();
Cursor cursor; Cursor cursor;
switch(uriType) { switch(uriType) {
@ -81,7 +78,7 @@ public class ContributionsContentProvider extends ContentProvider{
@Override @Override
public Uri insert(Uri uri, ContentValues contentValues) { public Uri insert(Uri uri, ContentValues contentValues) {
int uriType = uriMatcher.match(uri); int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
long id = 0; long id = 0;
switch (uriType) { switch (uriType) {
case CONTRIBUTIONS: case CONTRIBUTIONS:
@ -99,7 +96,7 @@ public class ContributionsContentProvider extends ContentProvider{
int rows = 0; int rows = 0;
int uriType = uriMatcher.match(uri); int uriType = uriMatcher.match(uri);
SQLiteDatabase db = dbOpenHelper.getReadableDatabase(); SQLiteDatabase db = CommonsApplication.getInstance().getDBOpenHelper().getReadableDatabase();
switch(uriType) { switch(uriType) {
case CONTRIBUTIONS_ID: case CONTRIBUTIONS_ID:
@ -120,7 +117,7 @@ public class ContributionsContentProvider extends ContentProvider{
public int bulkInsert(Uri uri, ContentValues[] values) { public int bulkInsert(Uri uri, ContentValues[] values) {
Timber.d("Hello, bulk insert! (ContributionsContentProvider)"); Timber.d("Hello, bulk insert! (ContributionsContentProvider)");
int uriType = uriMatcher.match(uri); int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
sqlDB.beginTransaction(); sqlDB.beginTransaction();
switch (uriType) { switch (uriType) {
case CONTRIBUTIONS: case CONTRIBUTIONS:
@ -148,7 +145,7 @@ public class ContributionsContentProvider extends ContentProvider{
In here, the only concat created argument is for id. It is cast to an int, and will error out otherwise. In here, the only concat created argument is for id. It is cast to an int, and will error out otherwise.
*/ */
int uriType = uriMatcher.match(uri); int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
int rowsUpdated = 0; int rowsUpdated = 0;
switch (uriType) { switch (uriType) {
case CONTRIBUTIONS: case CONTRIBUTIONS:

View file

@ -10,7 +10,6 @@ import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import fr.free.nrw.commons.CommonsApplication; import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.data.DBOpenHelper;
import timber.log.Timber; import timber.log.Timber;
public class ModificationsContentProvider extends ContentProvider{ public class ModificationsContentProvider extends ContentProvider{
@ -33,10 +32,9 @@ public class ModificationsContentProvider extends ContentProvider{
return Uri.parse(BASE_URI.toString() + "/" + id); return Uri.parse(BASE_URI.toString() + "/" + id);
} }
private DBOpenHelper dbOpenHelper;
@Override @Override
public boolean onCreate() { public boolean onCreate() {
dbOpenHelper = CommonsApplication.getInstance().getDBOpenHelper();
return false; return false;
} }
@ -54,7 +52,7 @@ public class ModificationsContentProvider extends ContentProvider{
throw new IllegalArgumentException("Unknown URI" + uri); throw new IllegalArgumentException("Unknown URI" + uri);
} }
SQLiteDatabase db = dbOpenHelper.getReadableDatabase(); SQLiteDatabase db = CommonsApplication.getInstance().getDBOpenHelper().getReadableDatabase();
Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
cursor.setNotificationUri(getContext().getContentResolver(), uri); cursor.setNotificationUri(getContext().getContentResolver(), uri);
@ -70,7 +68,7 @@ public class ModificationsContentProvider extends ContentProvider{
@Override @Override
public Uri insert(Uri uri, ContentValues contentValues) { public Uri insert(Uri uri, ContentValues contentValues) {
int uriType = uriMatcher.match(uri); int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
long id = 0; long id = 0;
switch (uriType) { switch (uriType) {
case MODIFICATIONS: case MODIFICATIONS:
@ -86,7 +84,7 @@ public class ModificationsContentProvider extends ContentProvider{
@Override @Override
public int delete(Uri uri, String s, String[] strings) { public int delete(Uri uri, String s, String[] strings) {
int uriType = uriMatcher.match(uri); int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
switch (uriType) { switch (uriType) {
case MODIFICATIONS_ID: case MODIFICATIONS_ID:
String id = uri.getLastPathSegment(); String id = uri.getLastPathSegment();
@ -104,7 +102,7 @@ public class ModificationsContentProvider extends ContentProvider{
public int bulkInsert(Uri uri, ContentValues[] values) { public int bulkInsert(Uri uri, ContentValues[] values) {
Timber.d("Hello, bulk insert! (ModificationsContentProvider)"); Timber.d("Hello, bulk insert! (ModificationsContentProvider)");
int uriType = uriMatcher.match(uri); int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
sqlDB.beginTransaction(); sqlDB.beginTransaction();
switch (uriType) { switch (uriType) {
case MODIFICATIONS: case MODIFICATIONS:
@ -132,7 +130,7 @@ public class ModificationsContentProvider extends ContentProvider{
In here, the only concat created argument is for id. It is cast to an int, and will error out otherwise. In here, the only concat created argument is for id. It is cast to an int, and will error out otherwise.
*/ */
int uriType = uriMatcher.match(uri); int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
int rowsUpdated = 0; int rowsUpdated = 0;
switch (uriType) { switch (uriType) {
case MODIFICATIONS: case MODIFICATIONS: