Search in sources :

Example 31 with SQLiteConnection

use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.

the class GPXDatabase method remove.

public boolean remove(File file) {
    SQLiteConnection db = openConnection(false);
    if (db != null) {
        try {
            String fileName = getFileName(file);
            String fileDir = getFileDir(file);
            db.execSQL("DELETE FROM " + GPX_TABLE_NAME + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", new Object[] { fileName, fileDir });
        } finally {
            db.close();
        }
        return true;
    }
    return false;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Example 32 with SQLiteConnection

use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.

the class FavouritesDbHelper method loadAndCheckDatabasePoints.

private void loadAndCheckDatabasePoints() {
    if (favoriteGroups == null) {
        SQLiteConnection db = openConnection(true);
        if (db != null) {
            try {
                SQLiteCursor query = db.rawQuery(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                "SELECT " + FAVOURITE_COL_NAME + ", " + FAVOURITE_COL_CATEGORY + ", " + FAVOURITE_COL_LAT + "," + FAVOURITE_COL_LON + " FROM " + FAVOURITE_TABLE_NAME, null);
                cachedFavoritePoints.clear();
                if (query.moveToFirst()) {
                    do {
                        String name = query.getString(0);
                        String cat = query.getString(1);
                        FavouritePoint p = new FavouritePoint();
                        p.setName(name);
                        p.setCategory(cat);
                        FavoriteGroup group = getOrCreateGroup(p, 0);
                        if (!name.equals("")) {
                            p.setLatitude(query.getDouble(2));
                            p.setLongitude(query.getDouble(3));
                            group.points.add(p);
                        }
                    } while (query.moveToNext());
                }
                query.close();
            } finally {
                db.close();
            }
            sortAll();
        }
        recalculateCachedFavPoints();
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor)

Example 33 with SQLiteConnection

use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.

the class FavouritesDbHelper method deleteFavouriteDB.

public boolean deleteFavouriteDB(FavouritePoint p) {
    SQLiteConnection db = openConnection(false);
    if (db != null) {
        try {
            db.execSQL("DELETE FROM " + FAVOURITE_TABLE_NAME + " WHERE category = ? AND " + whereNameLatLon(), // $NON-NLS-1$ //$NON-NLS-2$
            new Object[] { p.getCategory(), p.getName(), p.getLatitude(), p.getLongitude() });
            FavouritePoint fp = findFavoriteByAllProperties(p.getCategory(), p.getName(), p.getLatitude(), p.getLongitude());
            if (fp != null) {
                FavoriteGroup group = flatGroups.get(p.getCategory());
                if (group != null) {
                    group.points.remove(fp);
                }
                cachedFavoritePoints.remove(fp);
            }
            saveCurrentPointsIntoFile();
        } finally {
            db.close();
        }
        return true;
    }
    return false;
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Example 34 with SQLiteConnection

use of net.osmand.plus.api.SQLiteAPI.SQLiteConnection in project Osmand by osmandapp.

the class WikivoyageDbHelper method getArticle.

@Nullable
public WikivoyageArticle getArticle(long cityId, String lang) {
    WikivoyageArticle res = null;
    SQLiteConnection conn = openConnection();
    if (conn != null) {
        try {
            SQLiteCursor cursor = conn.rawQuery(ARTICLES_TABLE_SELECT + " WHERE " + ARTICLES_COL_CITY_ID + " = ? AND " + ARTICLES_COL_LANG + " = ?", new String[] { String.valueOf(cityId), lang });
            if (cursor.moveToFirst()) {
                res = readArticle(cursor);
            }
            cursor.close();
        } finally {
            conn.close();
        }
    }
    return res;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor) Nullable(android.support.annotation.Nullable)

Aggregations

SQLiteConnection (net.osmand.plus.api.SQLiteAPI.SQLiteConnection)34 SQLiteCursor (net.osmand.plus.api.SQLiteAPI.SQLiteCursor)12 Nullable (android.support.annotation.Nullable)3 ArrayList (java.util.ArrayList)3 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)3 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)2 LinkedHashMap (java.util.LinkedHashMap)2 FavouritePoint (net.osmand.data.FavouritePoint)2 Bitmap (android.graphics.Bitmap)1 NonNull (android.support.annotation.NonNull)1 Interpreter (bsh.Interpreter)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 QuadRect (net.osmand.data.QuadRect)1 MapMarkersGroup (net.osmand.plus.MapMarkersHelper.MapMarkersGroup)1