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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations