List of usage examples for com.badlogic.gdx.sql SQLiteGdxDatabaseCursor moveToNext
public void moveToNext();
From source file:de.longri.cachebox3.sqlite.dao.CacheDAO.java
License:Open Source License
public static String GetShortDescription(Cache cache) { String description = ""; SQLiteGdxDatabaseCursor reader = Database.Data.rawQuery("select ShortDescription from Caches where Id=?", new String[] { Long.toString(cache.Id) }); if (reader == null) return ""; reader.moveToFirst();/*from w w w. ja v a 2 s. c o m*/ while (!reader.isAfterLast()) { if (reader.getString(0) != null) description = reader.getString(0); reader.moveToNext(); } reader.close(); return description; }
From source file:de.longri.cachebox3.sqlite.dao.CacheDAO.java
License:Open Source License
public static String GetDescription(Cache cache) { String description = ""; SQLiteGdxDatabaseCursor reader = Database.Data.rawQuery("select Description from Caches where Id=?", new String[] { Long.toString(cache.Id) }); if (reader == null) return ""; reader.moveToFirst();/* w w w . ja v a 2 s . c o m*/ while (!reader.isAfterLast()) { if (reader.getString(0) != null) description = reader.getString(0); reader.moveToNext(); } reader.close(); return description; }
From source file:de.longri.cachebox3.sqlite.dao.CacheDAO.java
License:Open Source License
public ArrayList<String> getGcCodesFromMustLoadImages() { ArrayList<String> GcCodes = new ArrayList<String>(); SQLiteGdxDatabaseCursor reader = Database.Data.rawQuery( "select GcCode from Caches where Type<>4 and (ImagesUpdated=0 or DescriptionImagesUpdated=0)", null);//from w ww .ja v a 2s .co m if (reader.getCount() > 0) { reader.moveToFirst(); while (!reader.isAfterLast()) { String GcCode = reader.getString(0); GcCodes.add(GcCode); reader.moveToNext(); } } reader.close(); return GcCodes; }
From source file:de.longri.cachebox3.sqlite.dao.CacheDAO.java
License:Open Source License
public Boolean loadBooleanValue(String gcCode, String key) { SQLiteGdxDatabaseCursor reader = Database.Data .rawQuery("select " + key + " from Caches where GcCode = \"" + gcCode + "\"", null); try {//www .j av a 2 s. c om reader.moveToFirst(); while (!reader.isAfterLast()) { if (reader.getInt(0) != 0) { // gefunden. Suche abbrechen return true; } reader.moveToNext(); } } catch (Exception ex) { return false; } finally { reader.close(); } return false; }
From source file:de.longri.cachebox3.sqlite.dao.CacheListDAO.java
License:Open Source License
public CacheList ReadCacheList(CacheList cacheList, String join, String where, boolean withDescription, boolean fullDetails, boolean loadAllWaypoints) { if (cacheList == null) return null; // Clear List before read cacheList.clear();//from ww w. ja v a 2 s . c o m boolean error = false; log.trace("ReadCacheList 1.Waypoints"); LongMap<CB_List<Waypoint>> waypoints = new LongMap<CB_List<Waypoint>>(); // zuerst alle Waypoints einlesen CB_List<Waypoint> wpList = new CB_List<Waypoint>(); long aktCacheID = -1; String sql = fullDetails ? WaypointDAO.SQL_WP_FULL : WaypointDAO.SQL_WP; if (!((fullDetails || loadAllWaypoints))) { // when CacheList should be loaded without full details and without all Waypoints // do not load all waypoints from db! sql += " WHERE IsStart=\"true\" or Type=" + CacheTypes.Final.ordinal(); // StartWaypoint or CacheTypes.Final } sql += " ORDER BY 'CacheId'"; SQLiteGdxDatabaseCursor reader = Database.Data.rawQuery(sql, null); if (reader == null) return cacheList; reader.moveToFirst(); while (!reader.isAfterLast()) { WaypointDAO waypointDAO = new WaypointDAO(); Waypoint wp = waypointDAO.getWaypoint(reader, fullDetails); if (!(fullDetails || loadAllWaypoints)) { // wenn keine FullDetails geladen werden sollen dann sollen nur die Finals und Start-Waypoints geladen werden if (!(wp.IsStart || wp.Type == CacheTypes.Final)) { reader.moveToNext(); continue; } } if (wp.CacheId != aktCacheID) { aktCacheID = wp.CacheId; wpList = new CB_List<Waypoint>(); waypoints.put(aktCacheID, wpList); } wpList.add(wp); reader.moveToNext(); } reader.close(); log.debug(wpList.size() + " Waypoints readed!"); log.debug("ReadCacheList 2.Caches"); try { if (fullDetails) { sql = SQL.SQL_GET_CACHE + ", " + SQL.SQL_DETAILS; if (withDescription) { // load Cache with Description, Solver, Notes for Transfering Data from Server to ACB sql += "," + SQL.SQL_GET_DETAIL_WITH_DESCRIPTION; } } else { sql = SQL.SQL_GET_CACHE; } sql += " FROM `Caches` AS `c` " + join + " " + ((where.length() > 0) ? "WHERE " + where : where); reader = Database.Data.rawQuery(sql, null); } catch (Exception e) { log.error("CacheList.LoadCaches() sql+ \n" + sql, e); error = true; } if (!error) { reader.moveToFirst(); CacheDAO cacheDAO = new CacheDAO(); while (!reader.isAfterLast()) { Cache cache = cacheDAO.ReadFromCursor(reader, fullDetails, withDescription); boolean doAdd = true; if (FilterInstances.hasCorrectedCoordinates != 0) { if (waypoints.containsKey(cache.Id)) { CB_List<Waypoint> tmpwaypoints = waypoints.get(cache.Id); for (int i = 0, n = tmpwaypoints.size(); i < n; i++) { cache.waypoints.add(tmpwaypoints.get(i)); } } boolean hasCorrectedCoordinates = cache.CorrectedCoordiantesOrMysterySolved(); if (FilterInstances.hasCorrectedCoordinates < 0) { // show only those without corrected ones if (hasCorrectedCoordinates) doAdd = false; } else if (FilterInstances.hasCorrectedCoordinates > 0) { // only those with corrected ones if (!hasCorrectedCoordinates) doAdd = false; } } if (doAdd) { cacheList.add(cache); cache.waypoints.clear(); if (waypoints.containsKey(cache.Id)) { CB_List<Waypoint> tmpwaypoints = waypoints.get(cache.Id); for (int i = 0, n = tmpwaypoints.size(); i < n; i++) { cache.waypoints.add(tmpwaypoints.get(i)); } waypoints.remove(cache.Id); } } // ++Global.CacheCount; reader.moveToNext(); } reader.close(); } else { log.error("Corrupt database try cache by cache"); // get all id's reader = Database.Data.rawQuery(SQL.SQL_ALL_CACHE_IDS, null); reader.moveToFirst(); ArrayList<Long> idList = new ArrayList<Long>(reader.getCount()); while (!reader.isAfterLast()) { idList.add(reader.getLong(0)); reader.moveToNext(); } CacheDAO cacheDAO = new CacheDAO(); for (Long id : idList) { Cache cache = null; try { cache = cacheDAO.getFromDbByCacheId(id); } catch (Exception e) { log.error("Can't read Cache (id:" + id + ") from database."); try { Database.Data.delete("Caches", "id=" + id, null); } catch (Exception e1) { log.error("Can't delete this Cache. Skip it!"); } continue; } boolean doAdd = true; if (FilterInstances.hasCorrectedCoordinates != 0) { if (waypoints.containsKey(cache.Id)) { CB_List<Waypoint> tmpwaypoints = waypoints.get(cache.Id); for (int i = 0, n = tmpwaypoints.size(); i < n; i++) { cache.waypoints.add(tmpwaypoints.get(i)); } } boolean hasCorrectedCoordinates = cache.CorrectedCoordiantesOrMysterySolved(); if (FilterInstances.hasCorrectedCoordinates < 0) { // show only those without corrected ones if (hasCorrectedCoordinates) doAdd = false; } else if (FilterInstances.hasCorrectedCoordinates > 0) { // only those with corrected ones if (!hasCorrectedCoordinates) doAdd = false; } } if (doAdd) { cacheList.add(cache); cache.waypoints.clear(); if (waypoints.containsKey(cache.Id)) { CB_List<Waypoint> tmpwaypoints = waypoints.get(cache.Id); for (int i = 0, n = tmpwaypoints.size(); i < n; i++) { cache.waypoints.add(tmpwaypoints.get(i)); } waypoints.remove(cache.Id); } } } } // clear other never used WP`s from Mem waypoints.clear(); waypoints = null; // do it manual (or automated after fix), got hanging app on startup // log.debug( "ReadCacheList 3.Sorting"); try { // Collections.sort(cacheList); } catch ( Exception e) { // log.error( "CacheListDAO.ReadCacheList()", "Sort ERROR", e); } // log.debug( "ReadCacheList 4. ready"); return cacheList; }
From source file:de.longri.cachebox3.sqlite.dao.CategoryDAO.java
License:Open Source License
public Category ReadFromCursor(SQLiteGdxDatabaseCursor reader) { Category result = new Category(); result.Id = reader.getLong(0);/*ww w. j a va 2 s. co m*/ result.GpxFilename = reader.getString(1); result.pinned = reader.getInt(2) != 0; // alle GpxFilenames einlesen SQLiteGdxDatabaseCursor reader2 = Database.Data.rawQuery( "select ID, GPXFilename, Imported, CacheCount from GpxFilenames where CategoryId=?", new String[] { String.valueOf(result.Id) }); reader2.moveToFirst(); while (reader2.isAfterLast() == false) { GpxFilenameDAO gpxFilenameDAO = new GpxFilenameDAO(); GpxFilename gpx = gpxFilenameDAO.ReadFromCursor(reader2); result.add(gpx); reader2.moveToNext(); } reader2.close(); return result; }
From source file:de.longri.cachebox3.sqlite.dao.ImageDAO.java
License:Open Source License
/** * @param GcCode//from w ww . ja va 2 s . c o m * @return */ public ArrayList<ImageEntry> getImagesForCache(String GcCode) { ArrayList<ImageEntry> images = new ArrayList<ImageEntry>(); SQLiteGdxDatabaseCursor reader = Database.Data.rawQuery( "select CacheId, GcCode, Name, Description, ImageUrl, IsCacheImage from Images where GcCode=?", new String[] { GcCode }); if (reader.getCount() > 0) { reader.moveToFirst(); while (!reader.isAfterLast()) { ImageEntry image = new ImageEntry(reader); images.add(image); reader.moveToNext(); } } reader.close(); return images; }
From source file:de.longri.cachebox3.sqlite.dao.ImageDAO.java
License:Open Source License
/** * @param GcCode//from ww w .j a v a 2 s. c om * @return */ public ArrayList<ImageEntry> getDescriptionImagesForCache(String GcCode) { ArrayList<ImageEntry> images = new ArrayList<ImageEntry>(); SQLiteGdxDatabaseCursor reader = Database.Data.rawQuery( "select CacheId, GcCode, Name, Description, ImageUrl, IsCacheImage from Images where GcCode=? and IsCacheImage=1", new String[] { GcCode }); if (reader == null) return images; reader.moveToFirst(); while (!reader.isAfterLast()) { ImageEntry image = new ImageEntry(reader); images.add(image); reader.moveToNext(); } reader.close(); return images; }
From source file:de.longri.cachebox3.sqlite.dao.ImageDAO.java
License:Open Source License
public ArrayList<String> getImageURLsForCache(String GcCode) { ArrayList<String> images = new ArrayList<String>(); SQLiteGdxDatabaseCursor reader = Database.Data.rawQuery("select ImageUrl from Images where GcCode=?", new String[] { GcCode }); if (reader == null) return images; reader.moveToFirst();/*from w ww . ja v a 2s . c o m*/ while (!reader.isAfterLast()) { images.add(reader.getString(0)); reader.moveToNext(); } reader.close(); return images; }
From source file:de.longri.cachebox3.sqlite.dao.WaypointDAO.java
License:Open Source License
/** * Returns a WaypointList from reading DB! * * @param CacheID ID of Cache/* w w w. j a va 2 s .c o m*/ * @param Full Waypoints as FullWaypoints (true) or Waypoint (false) * @return */ public CB_List<Waypoint> getWaypointsFromCacheID(Long CacheID, boolean Full) { CB_List<Waypoint> wpList = new CB_List<Waypoint>(); long aktCacheID = -1; StringBuilder sqlState = new StringBuilder(Full ? SQL_WP_FULL : SQL_WP); sqlState.append(" where CacheId = ?"); SQLiteGdxDatabaseCursor reader = Database.Data.rawQuery(sqlState.toString(), new String[] { String.valueOf(CacheID) }); reader.moveToFirst(); while (!reader.isAfterLast()) { Waypoint wp = getWaypoint(reader, Full); if (wp.CacheId != aktCacheID) { aktCacheID = wp.CacheId; wpList = new CB_List<Waypoint>(); } wpList.add(wp); reader.moveToNext(); } reader.close(); return wpList; }