From 20232a47f33653f0950663c4e96467f4de60e303 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 8 Jan 2014 13:26:24 +0100 Subject: fix #3527: bad query string Let's hope that the bad formatting occurring for, at least, very small negative values in `String.format()` with a `null` Locale will not happen with `StringBuilder.append(double)`. --- main/src/cgeo/geocaching/DataStore.java | 6 +++--- main/src/cgeo/geocaching/geopoint/Viewport.java | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'main/src') diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java index bb8b427..0345e30 100644 --- a/main/src/cgeo/geocaching/DataStore.java +++ b/main/src/cgeo/geocaching/DataStore.java @@ -1675,7 +1675,7 @@ public class DataStore { * @return */ - private static String buildCoordinateWhere(final String dbTable, final Viewport viewport) { + private static StringBuilder buildCoordinateWhere(final String dbTable, final Viewport viewport) { return viewport.resize(1.5).sqlWhere(dbTable); } @@ -2265,7 +2265,7 @@ public class DataStore { } // viewport limitation - final StringBuilder selection = new StringBuilder(buildCoordinateWhere(dbTableCaches, viewport)); + final StringBuilder selection = buildCoordinateWhere(dbTableCaches, viewport); // cacheType limitation String[] selectionArgs = null; @@ -2870,7 +2870,7 @@ public class DataStore { */ public static Set loadWaypoints(final Viewport viewport, boolean excludeMine, boolean excludeDisabled, CacheType type) { - final StringBuilder where = new StringBuilder(buildCoordinateWhere(dbTableWaypoints, viewport)); + final StringBuilder where = buildCoordinateWhere(dbTableWaypoints, viewport); if (excludeMine) { where.append(" and ").append(dbTableCaches).append(".found == 0"); } diff --git a/main/src/cgeo/geocaching/geopoint/Viewport.java b/main/src/cgeo/geocaching/geopoint/Viewport.java index 21dc7fa..9d55f69 100644 --- a/main/src/cgeo/geocaching/geopoint/Viewport.java +++ b/main/src/cgeo/geocaching/geopoint/Viewport.java @@ -3,12 +3,11 @@ package cgeo.geocaching.geopoint; import cgeo.geocaching.ICoordinates; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; -import java.util.Locale; import java.util.Set; - public class Viewport { public final @NonNull Geopoint center; @@ -104,11 +103,12 @@ public class Viewport { * the database table to use as prefix, or null if no prefix is required * @return the string without the "where" keyword */ - public String sqlWhere(final String dbTable) { + public StringBuilder sqlWhere(@Nullable final String dbTable) { final String prefix = dbTable == null ? "" : (dbTable + "."); - return String.format((Locale) null, - "%slatitude >= %s and %slatitude <= %s and %slongitude >= %s and %slongitude <= %s", - prefix, getLatitudeMin(), prefix, getLatitudeMax(), prefix, getLongitudeMin(), prefix, getLongitudeMax()); + return new StringBuilder(prefix).append("latitude >= ").append(getLatitudeMin()).append(" and ") + .append(prefix).append("latitude <= ").append(getLatitudeMax()).append(" and ") + .append(prefix).append("longitude >= ").append(getLongitudeMin()).append(" and ") + .append(prefix).append("longitude <= ").append(getLongitudeMax()); } /** -- cgit v1.1