diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2012-06-01 18:13:57 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2012-06-01 18:16:21 +0200 |
| commit | 0faaf37a1fc823e961c5dce39e3fbb28074e5a42 (patch) | |
| tree | 4c6ad7517f237eda658bff0193f67fb44a417220 | |
| parent | b1aa1836678ad7111fd8ac67242baaf901e75921 (diff) | |
| download | cgeo-0faaf37a1fc823e961c5dce39e3fbb28074e5a42.zip cgeo-0faaf37a1fc823e961c5dce39e3fbb28074e5a42.tar.gz cgeo-0faaf37a1fc823e961c5dce39e3fbb28074e5a42.tar.bz2 | |
An id of 0 is not invalid when storing into the database
Also, simplify the code, and do not protect against exceptions that
cannot happen.
Found while discussing about #1701, but this is not the cause of the
problem.
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 37f8b7d..ec9c406 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -2475,41 +2475,30 @@ public class cgData { public boolean saveLogOffline(String geocode, Date date, LogType type, String log) { if (StringUtils.isBlank(geocode)) { + Log.e("cgData.saveLogOffline: cannot log a blank geocode"); return false; } if (LogType.UNKNOWN == type && StringUtils.isBlank(log)) { + Log.e("cgData.saveLogOffline: cannot log an unknown log type and no message"); return false; } init(); - boolean status = false; - ContentValues values = new ContentValues(); + final ContentValues values = new ContentValues(); values.put("geocode", geocode); values.put("updated", System.currentTimeMillis()); values.put("type", type.id); values.put("log", log); values.put("date", date.getTime()); - try { - if (hasLogOffline(geocode)) { - final int rows = database.update(dbTableLogsOffline, values, "geocode = ?", new String[] { geocode }); - - if (rows > 0) { - status = true; - } - } else { - final long id = database.insert(dbTableLogsOffline, null, values); - - if (id > 0) { - status = true; - } - } - } catch (Exception e) { - Log.e("cgData.saveLogOffline: " + e.toString()); + if (hasLogOffline(geocode)) { + final int rows = database.update(dbTableLogsOffline, values, "geocode = ?", new String[] { geocode }); + return rows > 0; + } else { + final long id = database.insert(dbTableLogsOffline, null, values); + return id != -1; } - - return status; } public LogEntry loadLogOffline(String geocode) { |
