aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/geopoint/Viewport.java15
-rw-r--r--tests/src/cgeo/geocaching/geopoint/ViewportTest.java3
2 files changed, 11 insertions, 7 deletions
diff --git a/main/src/cgeo/geocaching/geopoint/Viewport.java b/main/src/cgeo/geocaching/geopoint/Viewport.java
index 32f542b..4c810d6 100644
--- a/main/src/cgeo/geocaching/geopoint/Viewport.java
+++ b/main/src/cgeo/geocaching/geopoint/Viewport.java
@@ -2,6 +2,7 @@ package cgeo.geocaching.geopoint;
import cgeo.geocaching.ICoordinates;
+import java.util.Locale;
import java.util.Set;
@@ -146,13 +147,15 @@ public class Viewport {
/**
* Return the "where" part of the string appropriate for a SQL query.
*
+ * @param dbTable
+ * the database table to use as prefix, or null if no prefix is required
* @return the string without the "where" keyword
*/
- public String sqlWhere() {
- return "latitude >= " + getLatitudeMin() + " and " +
- "latitude <= " + getLatitudeMax() + " and " +
- "longitude >= " + getLongitudeMin() + " and " +
- "longitude <= " + getLongitudeMax();
+ public String sqlWhere(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());
}
/**
@@ -168,7 +171,7 @@ public class Viewport {
/**
* Return a viewport that contains the current viewport as well as another point.
- *
+ *
* @param coords
* the point we want in the viewport
* @return either the same or an expanded viewport
diff --git a/tests/src/cgeo/geocaching/geopoint/ViewportTest.java b/tests/src/cgeo/geocaching/geopoint/ViewportTest.java
index ba7df51..bd35ae6 100644
--- a/tests/src/cgeo/geocaching/geopoint/ViewportTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/ViewportTest.java
@@ -54,7 +54,8 @@ public class ViewportTest extends AndroidTestCase {
}
public static void testSqlWhere() {
- assertEquals("latitude >= -1.0 and latitude <= 3.0 and longitude >= -2.0 and longitude <= 4.0", vpRef.sqlWhere());
+ assertEquals("latitude >= -1.0 and latitude <= 3.0 and longitude >= -2.0 and longitude <= 4.0", vpRef.sqlWhere(null));
+ assertEquals("t.latitude >= -1.0 and t.latitude <= 3.0 and t.longitude >= -2.0 and t.longitude <= 4.0", vpRef.sqlWhere("t"));
}
public static void testEquals() {