diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2012-04-20 11:38:00 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2012-04-20 12:59:07 +0200 |
| commit | 28d3cf2659c787f6f5d4fa8dec6e6d378c577aee (patch) | |
| tree | 221a0000b4557e79063183ebb97b7eff5b8c64bb | |
| parent | f49842de614383ecbebe91085a7d00691d5fa2e1 (diff) | |
| download | cgeo-28d3cf2659c787f6f5d4fa8dec6e6d378c577aee.zip cgeo-28d3cf2659c787f6f5d4fa8dec6e6d378c577aee.tar.gz cgeo-28d3cf2659c787f6f5d4fa8dec6e6d378c577aee.tar.bz2 | |
Add optional table parameter to Viewport#sqlWhere()
| -rw-r--r-- | main/src/cgeo/geocaching/geopoint/Viewport.java | 15 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/geopoint/ViewportTest.java | 3 |
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() { |
