diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2012-12-18 06:41:55 +0100 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2012-12-18 06:47:45 +0100 |
commit | bd8a2860c404ba2cce50c9a3ebb081da9bc19fb9 (patch) | |
tree | c9240caa903813d852523a0de31345dfa88ddbb0 /main/src/cgeo/geocaching | |
parent | 5e3b688891cf3f34237604d861933bd91e5da650 (diff) | |
download | cgeo-bd8a2860c404ba2cce50c9a3ebb081da9bc19fb9.zip cgeo-bd8a2860c404ba2cce50c9a3ebb081da9bc19fb9.tar.gz cgeo-bd8a2860c404ba2cce50c9a3ebb081da9bc19fb9.tar.bz2 |
refactoring: reduce number of prepared statements
* for less memory usage
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 5d18b39..c1df97d 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -1473,7 +1473,6 @@ public class cgData { final Set<cgCache> caches = new HashSet<cgCache>(); int logIndex = -1; do { - //Extracted Method = LOADDBMINIMAL cgCache cache = cgData.createCacheFromDatabaseContent(cursor); if (loadFlags.contains(LoadFlag.LOAD_ATTRIBUTES)) { @@ -2080,25 +2079,42 @@ public class cgData { if (cacheType == null) { throw new IllegalArgumentException("cacheType must not be null"); } - if (list < 0) { - throw new IllegalArgumentException("list must be >= 0"); + if (list <= 0) { + throw new IllegalArgumentException("list must be > 0"); } init(); try { StringBuilder sql = new StringBuilder("select count(_id) from " + dbTableCaches + " where detailed = 1"); + String typeKey; + int reasonIndex; if (cacheType != CacheType.ALL) { - sql.append(" and type = ").append(DatabaseUtils.sqlEscapeString(cacheType.id)); + sql.append(" and type = ?"); + typeKey = cacheType.id; + reasonIndex = 2; } - if (list == 0) { + else { + typeKey = "all_types"; + reasonIndex = 1; + } + String listKey; + if (list == StoredList.ALL_LIST_ID) { sql.append(" and reason > 0"); - } else if (list >= 1) { - sql.append(" and reason = ").append(list); + listKey = "all_list"; + } else { + sql.append(" and reason = ?"); + listKey = "list"; } - String key = "CountCaches_" + cacheType.id + "_" + Integer.toString(list); + String key = "CountCaches_" + typeKey + "_" + listKey; SQLiteStatement compiledStmnt = PreparedStatements.getStatement(key, sql.toString()); + if (cacheType != CacheType.ALL) { + compiledStmnt.bindString(1, cacheType.id); + } + if (list != StoredList.ALL_LIST_ID) { + compiledStmnt.bindLong(reasonIndex, list); + } return (int) compiledStmnt.simpleQueryForLong(); } catch (Exception e) { Log.e("cgData.loadAllStoredCachesCount: " + e.toString()); |