Wrap all cursor for null pointer check
This commit is contained in:
parent
ff5b795694
commit
159796f3e2
7 changed files with 114 additions and 73 deletions
|
@ -732,7 +732,7 @@ public class FavouritesDbHelper {
|
|||
"SELECT " + FAVOURITE_COL_NAME + ", " + FAVOURITE_COL_CATEGORY + ", " + FAVOURITE_COL_LAT + "," + FAVOURITE_COL_LON + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
FAVOURITE_TABLE_NAME, null);
|
||||
cachedFavoritePoints.clear();
|
||||
if (query.moveToFirst()) {
|
||||
if (query != null && query.moveToFirst()) {
|
||||
do {
|
||||
String name = query.getString(0);
|
||||
String cat = query.getString(1);
|
||||
|
@ -748,7 +748,9 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
if (query != null) {
|
||||
query.close();
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
|
|
@ -523,12 +523,14 @@ public class GPXDatabase {
|
|||
if (db != null) {
|
||||
try {
|
||||
SQLiteCursor query = db.rawQuery(GPX_TABLE_SELECT, null);
|
||||
if (query.moveToFirst()) {
|
||||
if (query != null && query.moveToFirst()) {
|
||||
do {
|
||||
items.add(readItem(query));
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
if (query != null) {
|
||||
query.close();
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
@ -546,10 +548,12 @@ public class GPXDatabase {
|
|||
String fileDir = getFileDir(file);
|
||||
SQLiteCursor query = db.rawQuery(GPX_TABLE_SELECT + " WHERE " + GPX_COL_NAME + " = ? AND " +
|
||||
GPX_COL_DIR + " = ?", new String[] { fileName, fileDir });
|
||||
if (query.moveToFirst()) {
|
||||
if ( query != null && query.moveToFirst()) {
|
||||
result = readItem(query);
|
||||
}
|
||||
if (query != null) {
|
||||
query.close();
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
|
|
@ -374,7 +374,7 @@ public class SearchHistoryHelper {
|
|||
// LEGACY QUERY !!
|
||||
SQLiteCursor query = db.rawQuery(
|
||||
"SELECT name, latitude, longitude, time FROM history ORDER BY time DESC", null); //$NON-NLS-1$//$NON-NLS-2$
|
||||
if (query.moveToFirst()) {
|
||||
if (query != null && query.moveToFirst()) {
|
||||
do {
|
||||
String name = query.getString(0);
|
||||
String type = PointDescription.POINT_TYPE_MARKER;
|
||||
|
@ -401,8 +401,10 @@ public class SearchHistoryHelper {
|
|||
entries.add(e);
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
if(query != null) {
|
||||
query.close();
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
@ -416,7 +418,7 @@ public class SearchHistoryHelper {
|
|||
HISTORY_COL_TIME + ", " + HISTORY_COL_FREQ_INTERVALS + ", " + HISTORY_COL_FREQ_VALUES +
|
||||
" FROM " + HISTORY_TABLE_NAME , null); //$NON-NLS-1$//$NON-NLS-2$
|
||||
Map<PointDescription, HistoryEntry> st = new HashMap<PointDescription, HistoryEntry>();
|
||||
if (query.moveToFirst()) {
|
||||
if (query != null && query.moveToFirst()) {
|
||||
boolean reinsert = false;
|
||||
do {
|
||||
String name = query.getString(0);
|
||||
|
@ -443,7 +445,9 @@ public class SearchHistoryHelper {
|
|||
|
||||
}
|
||||
}
|
||||
if(query != null) {
|
||||
query.close();
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
|
|
@ -213,13 +213,15 @@ public class MapMarkersDbHelper {
|
|||
if (db != null) {
|
||||
try {
|
||||
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT, null);
|
||||
if (query.moveToFirst()) {
|
||||
if (query != null && query.moveToFirst()) {
|
||||
do {
|
||||
MapMarkersGroup group = readGroup(query);
|
||||
res.put(group.getId(), group);
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
if(query != null) {
|
||||
query.close();
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
@ -392,10 +394,12 @@ public class MapMarkersDbHelper {
|
|||
if (db != null) {
|
||||
try {
|
||||
SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ID + " = ?", new String[]{id});
|
||||
if (query.moveToFirst()) {
|
||||
if (query != null && query.moveToFirst()) {
|
||||
res = readItem(query);
|
||||
}
|
||||
if(query != null) {
|
||||
query.close();
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
@ -411,14 +415,16 @@ public class MapMarkersDbHelper {
|
|||
try {
|
||||
SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?",
|
||||
new String[]{String.valueOf(1)});
|
||||
if (query.moveToFirst()) {
|
||||
if (query != null && query.moveToFirst()) {
|
||||
do {
|
||||
MapMarker marker = readItem(query);
|
||||
markers.put(marker.id, marker);
|
||||
nextKeys.add(marker.nextKey);
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
if(query != null) {
|
||||
query.close();
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
@ -570,12 +576,14 @@ public class MapMarkersDbHelper {
|
|||
try {
|
||||
SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?",
|
||||
new String[]{String.valueOf(0)});
|
||||
if (query.moveToFirst()) {
|
||||
if (query != null && query.moveToFirst()) {
|
||||
do {
|
||||
markers.add(readItem(query));
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
if(query != null) {
|
||||
query.close();
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
|
|
@ -473,7 +473,7 @@ public class PoiFiltersHelper {
|
|||
SQLiteCursor query = conn.rawQuery("SELECT " + CATEGORIES_FILTER_ID + ", " + CATEGORIES_COL_CATEGORY + "," + CATEGORIES_COL_SUBCATEGORY + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
CATEGORIES_NAME, null);
|
||||
Map<String, Map<PoiCategory, LinkedHashSet<String>>> map = new LinkedHashMap<String, Map<PoiCategory, LinkedHashSet<String>>>();
|
||||
if (query.moveToFirst()) {
|
||||
if (query != null && query.moveToFirst()) {
|
||||
do {
|
||||
String filterId = query.getString(0);
|
||||
if (!map.containsKey(filterId)) {
|
||||
|
@ -492,11 +492,13 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
if(query != null) {
|
||||
query.close();
|
||||
}
|
||||
|
||||
query = conn.rawQuery("SELECT " + FILTER_COL_ID + ", " + FILTER_COL_NAME + "," + FILTER_COL_FILTERBYNAME + " FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
FILTER_NAME, null);
|
||||
if (query.moveToFirst()) {
|
||||
if (query != null && query.moveToFirst()) {
|
||||
do {
|
||||
String filterId = query.getString(0);
|
||||
if (map.containsKey(filterId)) {
|
||||
|
@ -507,8 +509,10 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
if(query != null) {
|
||||
query.close();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
@ -216,6 +216,7 @@ public class TravelDbHelper {
|
|||
query += ") ";
|
||||
if (params.size() > 0) {
|
||||
SQLiteCursor cursor = conn.rawQuery(query, params.toArray(new String[params.size()]));
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
WikivoyageSearchResult rs = new WikivoyageSearchResult();
|
||||
|
@ -230,6 +231,7 @@ public class TravelDbHelper {
|
|||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<WikivoyageSearchResult> list = new ArrayList<>(groupSearchResultsByCityId(res));
|
||||
sortSearchResults(searchQuery, list);
|
||||
|
@ -252,6 +254,9 @@ public class TravelDbHelper {
|
|||
}
|
||||
String LANG_WHERE = " WHERE " + ARTICLES_COL_LANG + " = '" + language + "'";
|
||||
SQLiteCursor cursor = conn.rawQuery(POP_ARTICLES_TABLE_SELECT + LANG_WHERE, null);
|
||||
if(cursor == null) {
|
||||
return popularArticles;
|
||||
}
|
||||
// read popular articles
|
||||
List<PopularArticle> popReadArticlesOrder = new ArrayList<>();
|
||||
List<PopularArticle> popReadArticlesLocation = new ArrayList<>();
|
||||
|
@ -327,6 +332,7 @@ public class TravelDbHelper {
|
|||
bld.append(")");
|
||||
cursor = conn.rawQuery(bld.toString(), null);
|
||||
Map<Long, TravelArticle> ts = new HashMap<Long, TravelArticle>();
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
TravelArticle travelArticle = readArticle(cursor);
|
||||
|
@ -334,6 +340,7 @@ public class TravelDbHelper {
|
|||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
@ -461,7 +468,7 @@ public class TravelDbHelper {
|
|||
}
|
||||
}
|
||||
SQLiteCursor cursor = conn.rawQuery(query.toString(), params.toArray(new String[params.size()]));
|
||||
if (cursor.moveToFirst()) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
WikivoyageSearchResult rs = new WikivoyageSearchResult();
|
||||
rs.tripId = cursor.getLong(0);
|
||||
|
@ -480,8 +487,10 @@ public class TravelDbHelper {
|
|||
}
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
LinkedHashMap<WikivoyageSearchResult, List<WikivoyageSearchResult>> res = new LinkedHashMap<>();
|
||||
for (String header : headers) {
|
||||
WikivoyageSearchResult searchResult = headerObjs.get(header);
|
||||
|
@ -510,11 +519,13 @@ public class TravelDbHelper {
|
|||
if (conn != null) {
|
||||
SQLiteCursor cursor = conn.rawQuery(ARTICLES_TABLE_SELECT + " WHERE " + ARTICLES_COL_TRIP_ID + " = ? AND "
|
||||
+ ARTICLES_COL_LANG + " = ?", new String[] { String.valueOf(cityId), lang });
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
res = readArticle(cursor);
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -525,11 +536,13 @@ public class TravelDbHelper {
|
|||
SQLiteCursor cursor = conn.rawQuery("SELECT " + ARTICLES_COL_TRIP_ID + " FROM "
|
||||
+ ARTICLES_TABLE_NAME + " WHERE " + ARTICLES_COL_TITLE + " = ? AND "
|
||||
+ ARTICLES_COL_LANG + " = ?", new String[]{title, lang});
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
res = cursor.getLong(0);
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -540,6 +553,7 @@ public class TravelDbHelper {
|
|||
if (conn != null) {
|
||||
SQLiteCursor cursor = conn.rawQuery("SELECT " + ARTICLES_COL_LANG + " FROM " + ARTICLES_TABLE_NAME
|
||||
+ " WHERE " + ARTICLES_COL_TRIP_ID + " = ?", new String[]{String.valueOf(cityId)});
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
String baseLang = application.getLanguage();
|
||||
do {
|
||||
|
@ -559,6 +573,7 @@ public class TravelDbHelper {
|
|||
}
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -278,12 +278,14 @@ public class TravelLocalDataHelper {
|
|||
try {
|
||||
String query = HISTORY_TABLE_SELECT + " WHERE " + HISTORY_COL_TRAVEL_BOOK + " = ?";
|
||||
SQLiteCursor cursor = conn.rawQuery(query, new String[]{travelBook});
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
WikivoyageSearchHistoryItem item = readHistoryItem(cursor);
|
||||
res.put(item.getKey(), item);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
} finally {
|
||||
conn.close();
|
||||
|
@ -380,12 +382,14 @@ public class TravelLocalDataHelper {
|
|||
try {
|
||||
String query = BOOKMARKS_TABLE_SELECT + " WHERE " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?";
|
||||
SQLiteCursor cursor = conn.rawQuery(query, new String[]{travelBook});
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
res.add(readSavedArticle(cursor));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} finally {
|
||||
conn.close();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue