Search in sources :

Example 11 with SQLiteCursor

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

the class MapMarkersDbHelper method getActiveMarkers.

public List<MapMarker> getActiveMarkers() {
    Map<String, MapMarker> markers = new LinkedHashMap<>();
    Set<String> nextKeys = new HashSet<>();
    SQLiteConnection db = openConnection(true);
    if (db != null) {
        try {
            SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?", new String[] { String.valueOf(1) });
            if (query.moveToFirst()) {
                do {
                    MapMarker marker = readItem(query);
                    markers.put(marker.id, marker);
                    nextKeys.add(marker.nextKey);
                } while (query.moveToNext());
            }
            query.close();
        } finally {
            db.close();
        }
    }
    return buildLinkedList(markers, nextKeys);
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 12 with SQLiteCursor

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

the class SQLiteTileSource method getBytes.

public byte[] getBytes(int x, int y, int zoom, String dirWithTiles, long[] timeHolder) throws IOException {
    SQLiteConnection db = getDatabase();
    if (db == null) {
        return null;
    }
    long ts = System.currentTimeMillis();
    try {
        if (zoom <= maxZoom) {
            // return the normal tile if exists
            String[] params = new String[] { x + "", y + "", getFileZoom(zoom) + "" };
            boolean queryTime = timeHolder != null && timeHolder.length > 0 && timeSupported;
            SQLiteCursor cursor = db.rawQuery("SELECT image " + (queryTime ? ", time" : "") + "  FROM tiles WHERE x = ? AND y = ? AND z = ?", // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
            params);
            byte[] blob = null;
            if (cursor.moveToFirst()) {
                blob = cursor.getBlob(0);
                if (queryTime) {
                    timeHolder[0] = cursor.getLong(1);
                }
            }
            cursor.close();
            return blob;
        }
        return null;
    } finally {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Load tile " + x + "/" + y + "/" + zoom + " for " + (System.currentTimeMillis() - ts) + " ms ");
        }
    }
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor)

Example 13 with SQLiteCursor

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

the class GPXDatabase method onUpgrade.

private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) {
    if (oldVersion < 2) {
        db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_COLOR + " TEXT");
    }
    if (oldVersion < 3) {
        db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_FILE_LAST_MODIFIED_TIME + " long");
    }
    if (oldVersion < 4) {
        db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_TYPE + " int");
        db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_INTERVAL + " double");
    }
    if (oldVersion < 5) {
        boolean colorColumnExists = false;
        boolean fileLastModifiedTimeColumnExists = false;
        boolean splitTypeColumnExists = false;
        boolean splitIntervalColumnExists = false;
        SQLiteCursor cursor = db.rawQuery("PRAGMA table_info(" + GPX_TABLE_NAME + ")", null);
        if (cursor.moveToFirst()) {
            do {
                String columnName = cursor.getString(1);
                if (!colorColumnExists && columnName.equals(GPX_COL_COLOR)) {
                    colorColumnExists = true;
                } else if (!fileLastModifiedTimeColumnExists && columnName.equals(GPX_COL_FILE_LAST_MODIFIED_TIME)) {
                    fileLastModifiedTimeColumnExists = true;
                } else if (!splitTypeColumnExists && columnName.equals(GPX_COL_SPLIT_TYPE)) {
                    splitTypeColumnExists = true;
                } else if (!splitIntervalColumnExists && columnName.equals(GPX_COL_SPLIT_INTERVAL)) {
                    splitIntervalColumnExists = true;
                }
            } while (cursor.moveToNext());
        }
        cursor.close();
        if (!colorColumnExists) {
            db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_COLOR + " TEXT");
        }
        if (!fileLastModifiedTimeColumnExists) {
            db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_FILE_LAST_MODIFIED_TIME + " long");
            List<GpxDataItem> items = getItems();
            for (GpxDataItem item : items) {
                updateLastModifiedTime(item);
            }
        }
        if (!splitTypeColumnExists) {
            db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_TYPE + " int");
        }
        if (!splitIntervalColumnExists) {
            db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_INTERVAL + " double");
        }
    }
    if (oldVersion < 6) {
        db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_API_IMPORTED + " int");
        db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_API_IMPORTED + " = ? " + "WHERE " + GPX_COL_API_IMPORTED + " IS NULL", new Object[] { 0 });
    }
    if (oldVersion < 7) {
        db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_WPT_CATEGORY_NAMES + " TEXT");
    }
}
Also used : SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor)

Example 14 with SQLiteCursor

use of net.osmand.plus.api.SQLiteAPI.SQLiteCursor 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 15 with SQLiteCursor

use of net.osmand.plus.api.SQLiteAPI.SQLiteCursor 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

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