diff options
Diffstat (limited to 'src/cgeo/geocaching/cgData.java')
| -rw-r--r-- | src/cgeo/geocaching/cgData.java | 122 |
1 files changed, 69 insertions, 53 deletions
diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java index 0c15718..80516a5 100644 --- a/src/cgeo/geocaching/cgData.java +++ b/src/cgeo/geocaching/cgData.java @@ -23,6 +23,7 @@ import android.content.ContentValues; import android.content.Context; import android.content.res.Resources; import android.database.Cursor; +import android.database.DatabaseUtils.InsertHelper; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteStatement; @@ -38,7 +39,7 @@ public class cgData { private cgDbHelper dbHelper = null; private SQLiteDatabase databaseRO = null; private SQLiteDatabase databaseRW = null; - private static final int dbVersion = 55; + private static final int dbVersion = 56; private static final String dbName = "data"; private static final String dbTableCaches = "cg_caches"; private static final String dbTableLists = "cg_lists"; @@ -150,6 +151,14 @@ public class cgData { + "date long, " + "found integer not null default 0 " + "); "; + private final static int LOGS_GEOCODE = 2; + private final static int LOGS_UPDATED = 3; + private final static int LOGS_TYPE = 4; + private final static int LOGS_AUTHOR = 5; + private final static int LOGS_LOG = 6; + private final static int LOGS_DATE = 7; + private final static int LOGS_FOUND = 8; + private static final String dbCreateLogCount = "" + "create table " + dbTableLogCount + " (" + "_id integer primary key autoincrement, " @@ -781,6 +790,18 @@ public class cgData { } } + + // make all internal attribute names lowercase + // @see issue #299 + if (oldVersion < 56) { // update to 56 + try { + db.execSQL("update " + dbTableAttributes + " set attribute = " + + "lower(attribute) where attribute like \"%_yes\" " + + "or attribute like \"%_no\""); + } catch (Exception e) { + Log.e(cgSettings.tag, "Failed to upgrade to ver. 56: " + e.toString()); + } + } } db.setTransactionSuccessful(); @@ -1195,54 +1216,47 @@ public class cgData { values.put("inventoryunknown", cache.inventoryItems); values.put("onWatchlist", cache.onWatchlist ? 1 : 0); - boolean status = false; boolean statusOk = true; if (cache.attributes != null) { - status = saveAttributes(cache.geocode, cache.attributes); - if (status == false) { + if (!saveAttributes(cache.geocode, cache.attributes)) { statusOk = false; } } if (cache.waypoints != null) { - status = saveWaypoints(cache.geocode, cache.waypoints, true); - if (status == false) { + if (!saveWaypoints(cache.geocode, cache.waypoints, true)) { statusOk = false; } } if (cache.spoilers != null) { - status = saveSpoilers(cache.geocode, cache.spoilers); - if (status == false) { + if (!saveSpoilers(cache.geocode, cache.spoilers)) { statusOk = false; } } if (cache.logs != null) { - status = saveLogs(cache.geocode, cache.logs); - if (status == false) { + if (!saveLogs(cache.geocode, cache.logs)) { statusOk = false; } } if (cache.logCounts != null && cache.logCounts.isEmpty() == false) { - status = saveLogCount(cache.geocode, cache.logCounts); - if (status == false) { + if (!saveLogCount(cache.geocode, cache.logCounts)) { statusOk = false; } } if (cache.inventory != null) { - status = saveInventory(cache.geocode, cache.inventory); - if (status == false) { + if (!saveInventory(cache.geocode, cache.inventory)) { statusOk = false; } } if (statusOk == false) { cache.detailed = false; - cache.detailedUpdate = 0l; + cache.detailedUpdate = 0L; } init(); @@ -1498,21 +1512,23 @@ public class cgData { } if (!logs.isEmpty()) { - ContentValues values = new ContentValues(); - for (cgLog oneLog : logs) { - values.clear(); - values.put("geocode", geocode); - values.put("updated", System.currentTimeMillis()); - values.put("type", oneLog.type); - values.put("author", oneLog.author); - values.put("log", oneLog.log); - values.put("date", oneLog.date); - values.put("found", oneLog.found); - - long log_id = databaseRW.insert(dbTableLogs, null, values); - - if (CollectionUtils.isNotEmpty(oneLog.logImages)) { - for (cgImage img : oneLog.logImages) { + InsertHelper helper = new InsertHelper(databaseRW, dbTableLogs); + for (cgLog log : logs) { + helper.prepareForInsert(); + + helper.bind(LOGS_GEOCODE, geocode); + helper.bind(LOGS_UPDATED, System.currentTimeMillis()); + helper.bind(LOGS_TYPE, log.type); + helper.bind(LOGS_AUTHOR, log.author); + helper.bind(LOGS_LOG, log.log); + helper.bind(LOGS_DATE, log.date); + helper.bind(LOGS_FOUND, log.found); + + long log_id = helper.execute(); + + if (CollectionUtils.isNotEmpty(log.logImages)) { + ContentValues values = new ContentValues(); + for (cgImage img : log.logImages) { values.clear(); values.put("log_id", log_id); values.put("title", img.title); @@ -1521,6 +1537,7 @@ public class cgData { } } } + helper.close(); } databaseRW.setTransactionSuccessful(); } finally { @@ -1595,7 +1612,7 @@ public class cgData { if (oneTrackable.released != null) { values.put("released", oneTrackable.released.getTime()); } else { - values.put("released", 0l); + values.put("released", 0L); } values.put("goal", oneTrackable.goal); values.put("description", oneTrackable.details); @@ -1629,9 +1646,9 @@ public class cgData { if (all.length() > 0) { all.append(", "); } - all.append("\""); + all.append('"'); all.append((String) one); - all.append("\""); + all.append('"'); } if (where.length() > 0) { @@ -1639,7 +1656,7 @@ public class cgData { } where.append("geocode in ("); where.append(all); - where.append(")"); + where.append(')'); } cursor = databaseRO.query( @@ -1730,9 +1747,9 @@ public class cgData { if (all.length() > 0) { all.append(", "); } - all.append("\""); + all.append('"'); all.append((String) one); - all.append("\""); + all.append('"'); } if (where.length() > 0) { @@ -1740,16 +1757,16 @@ public class cgData { } where.append("geocode in ("); where.append(all); - where.append(")"); + where.append(')'); } else if (guids != null && guids.length > 0) { StringBuilder all = new StringBuilder(); for (Object one : guids) { if (all.length() > 0) { all.append(", "); } - all.append("\""); + all.append('"'); all.append((String) one); - all.append("\""); + all.append('"'); } if (where.length() > 0) { @@ -1757,7 +1774,7 @@ public class cgData { } where.append("guid in ("); where.append(all); - where.append(")"); + where.append(')'); } else { return caches; } @@ -1784,8 +1801,7 @@ public class cgData { if (where.length() > 0) { where.append(" and "); } - where.append("("); - where.append("latitude >= "); + where.append("(latitude >= "); where.append(String.format((Locale) null, "%.6f", latMin)); where.append(" and latitude <= "); where.append(String.format((Locale) null, "%.6f", latMax)); @@ -1793,7 +1809,7 @@ public class cgData { where.append(String.format((Locale) null, "%.6f", lonMin)); where.append(" and longitude <= "); where.append(String.format((Locale) null, "%.6f", lonMax)); - where.append(")"); + where.append(')'); } cursor = databaseRO.query( @@ -1879,13 +1895,13 @@ public class cgData { cache.rating = (Float) cursor.getFloat(cursor.getColumnIndex("rating")); cache.votes = (Integer) cursor.getInt(cursor.getColumnIndex("votes")); cache.myVote = (Float) cursor.getFloat(cursor.getColumnIndex("myvote")); - cache.disabled = cursor.getLong(cursor.getColumnIndex("disabled")) == 1l; - cache.archived = cursor.getLong(cursor.getColumnIndex("archived")) == 1l; - cache.members = cursor.getLong(cursor.getColumnIndex("members")) == 1l; - cache.found = cursor.getLong(cursor.getColumnIndex("found")) == 1l; - cache.favourite = cursor.getLong(cursor.getColumnIndex("favourite")) == 1l; + cache.disabled = cursor.getLong(cursor.getColumnIndex("disabled")) == 1L; + cache.archived = cursor.getLong(cursor.getColumnIndex("archived")) == 1L; + cache.members = cursor.getLong(cursor.getColumnIndex("members")) == 1L; + cache.found = cursor.getLong(cursor.getColumnIndex("found")) == 1L; + cache.favourite = cursor.getLong(cursor.getColumnIndex("favourite")) == 1L; cache.inventoryItems = (Integer) cursor.getInt(cursor.getColumnIndex("inventoryunknown")); - cache.onWatchlist = cursor.getLong(cursor.getColumnIndex("onWatchlist")) == 1l; + cache.onWatchlist = cursor.getLong(cursor.getColumnIndex("onWatchlist")) == 1L; if (loadA) { ArrayList<String> attributes = loadAttributes(cache.geocode); @@ -2471,7 +2487,7 @@ public class cgData { if (cachetype != null) { specifySql.append(" and type = \""); specifySql.append(cachetype); - specifySql.append("\""); + specifySql.append('"'); } try { @@ -2521,7 +2537,7 @@ public class cgData { if (cachetype != null) { specifySql.append(" and type = \""); specifySql.append(cachetype); - specifySql.append("\""); + specifySql.append('"'); } try { @@ -2605,7 +2621,7 @@ public class cgData { if (cachetype != null) { where.append(" and type = \""); where.append(cachetype); - where.append("\""); + where.append('"'); } // offline caches only @@ -2655,7 +2671,7 @@ public class cgData { // cachetype limitation if (cachetype != null) { where.append(cachetype); - where.append("\""); + where.append('"'); } // offline caches only |
