Search in sources :

Example 11 with SQLiteConnection

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

the class GPXDatabase method getItems.

public List<GpxDataItem> getItems() {
    List<GpxDataItem> items = new ArrayList<>();
    SQLiteConnection db = openConnection(true);
    if (db != null) {
        try {
            SQLiteCursor query = db.rawQuery(GPX_TABLE_SELECT, null);
            if (query.moveToFirst()) {
                do {
                    items.add(readItem(query));
                } while (query.moveToNext());
            }
            query.close();
        } finally {
            db.close();
        }
    }
    return items;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) ArrayList(java.util.ArrayList) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor)

Example 12 with SQLiteConnection

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

the class GPXDatabase method openConnection.

private SQLiteConnection openConnection(boolean readonly) {
    SQLiteConnection conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly);
    int version = conn.getVersion();
    if (version == 0 || DB_VERSION != version) {
        if (readonly) {
            conn.close();
            conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, false);
        }
        version = conn.getVersion();
        conn.setVersion(DB_VERSION);
        if (version == 0) {
            onCreate(conn);
        } else {
            onUpgrade(conn, version, DB_VERSION);
        }
    }
    return conn;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

Example 13 with SQLiteConnection

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

the class GPXDatabase method getItem.

@Nullable
public GpxDataItem getItem(File file) {
    GpxDataItem result = null;
    SQLiteConnection db = openConnection(true);
    if (db != null) {
        try {
            String fileName = getFileName(file);
            String fileDir = getFileDir(file);
            SQLiteCursor query = db.rawQuery(GPX_TABLE_SELECT + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", new String[] { fileName, fileDir });
            if (query.moveToFirst()) {
                result = readItem(query);
            }
            query.close();
        } finally {
            db.close();
        }
    }
    return result;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection) SQLiteCursor(net.osmand.plus.api.SQLiteAPI.SQLiteCursor) Nullable(android.support.annotation.Nullable)

Example 14 with SQLiteConnection

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

the class GPXDatabase method rename.

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

Example 15 with SQLiteConnection

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

the class GPXDatabase method updateColor.

public boolean updateColor(GpxDataItem item, int color) {
    SQLiteConnection db = openConnection(false);
    if (db != null) {
        try {
            String fileName = getFileName(item.file);
            String fileDir = getFileDir(item.file);
            db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_COLOR + " = ? " + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", new Object[] { (color == 0 ? "" : Algorithms.colorToString(color)), fileName, fileDir });
            item.color = color;
        } finally {
            db.close();
        }
        return true;
    }
    return false;
}
Also used : SQLiteConnection(net.osmand.plus.api.SQLiteAPI.SQLiteConnection)

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