Java Code Examples for com.activeandroid.Cache#openDatabase()
The following examples show how to use
com.activeandroid.Cache#openDatabase() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Sensor.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static boolean TableExists(String table) {//KS try { SQLiteDatabase db = Cache.openDatabase(); if (db != null) { db.rawQuery("SELECT * FROM " + table, null); Log.d("wearSENSOR", "TableExists table does NOT exist:" + table); return true; } else { Log.d("wearSENSOR", "TableExists Cache.openDatabase() failed."); return false; } } catch (Exception e) { Log.d("wearSENSOR", "TableExists CATCH error table:" + table); return false; } }
Example 2
Source File: DBSearchUtil.java From xDrip-Experimental with GNU General Public License v3.0 | 6 votes |
public static List<BgReadingStats> getReadings(boolean ordered) { Bounds bounds = new Bounds().invoke(); String orderBy = ordered ? "calculated_value desc" : null; SQLiteDatabase db = Cache.openDatabase(); Cursor cur = db.query("bgreadings", new String[]{"timestamp", "calculated_value"}, "timestamp >= ? AND timestamp <= ? AND calculated_value > ? AND snyced == 0", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); reading.timestamp = (Long.parseLong(cur.getString(0))); reading.calculated_value = (Double.parseDouble(cur.getString(1))); readings.add(reading); } while (cur.moveToNext()); } return readings; }
Example 3
Source File: DBSearchUtil.java From NightWatch with GNU General Public License v3.0 | 6 votes |
public static List<BgReadingStats> getReadings() { Bounds bounds = new Bounds().invoke(); SQLiteDatabase db = Cache.openDatabase(); //Cursor cur = db.query("bgreadings", new String[]{"datetime", "sgv"}, "datetime >= ? AND datetime <= ? AND calculated_value > ?", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); Cursor cur = db.query("Bg", new String[]{"datetime", "sgv"}, "datetime >= ? AND datetime <= ?", new String[]{"" + bounds.start, "" + bounds.stop}, null, null, null); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); //reading.timestamp = (long)(Double.parseDouble(cur.getString(0))); reading.timestamp = (long)cur.getDouble(0); reading.calculated_value = doubleFromSgv(cur.getString(1)); if(reading.calculated_value >= CUTOFF) { readings.add(reading); Log.d("Double timestamp", "" + reading.timestamp + " | " + cur.getString(0)); } } while (cur.moveToNext()); } return readings; }
Example 4
Source File: DatabaseAdmin.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private synchronized List<String> executeSQL(final String query) { final List<String> results = new ArrayList<>(); final SQLiteDatabase db = Cache.openDatabase(); final boolean transaction = !query.equals("vacuum"); if (transaction) db.beginTransaction(); try { final Cursor cursor = db.rawQuery(query, null); Log.d(TAG, "Got query results: " + query + " " + cursor.getCount()); while (cursor.moveToNext()) { for (int c = 0; c < cursor.getColumnCount(); c++) { if (D) Log.d(TAG, "Column: " + cursor.getColumnName(c)); results.add(cursor.getString(c)); } } cursor.close(); if (transaction) db.setTransactionSuccessful(); } finally { if (transaction) db.endTransaction(); } return results; }
Example 5
Source File: DBSearchUtil.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static List<BgReadingStats> getReadings(boolean ordered) { try { Bounds bounds = new Bounds().invoke(); String orderBy = ordered ? "calculated_value desc" : null; SQLiteDatabase db = Cache.openDatabase(); Cursor cur = db.query("bgreadings", new String[]{"timestamp", "calculated_value"}, "timestamp >= ? AND timestamp <= ? AND calculated_value > ? AND snyced == 0", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); reading.timestamp = (Long.parseLong(cur.getString(0))); reading.calculated_value = (Double.parseDouble(cur.getString(1))); readings.add(reading); } while (cur.moveToNext()); } return readings; } catch (Exception e) { JoH.static_toast_long(e.getMessage()); return null; } }
Example 6
Source File: Sensor.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static void InitDb(Context context) {//KS Configuration dbConfiguration = new Configuration.Builder(context).create(); try { SQLiteDatabase db = Cache.openDatabase(); if (db != null) { Log.d("wearSENSOR", "InitDb DB exists"); } else { ActiveAndroid.initialize(dbConfiguration); Log.d("wearSENSOR", "InitDb DB does NOT exist. Call ActiveAndroid.initialize()"); } } catch (Exception e) { ActiveAndroid.initialize(dbConfiguration); Log.d("wearSENSOR", "InitDb CATCH: DB does NOT exist. Call ActiveAndroid.initialize()"); } }
Example 7
Source File: DBSearchUtil.java From NightWatch with GNU General Public License v3.0 | 6 votes |
public static List<BgReadingStats> getReadings() { Bounds bounds = new Bounds().invoke(); SQLiteDatabase db = Cache.openDatabase(); //Cursor cur = db.query("bgreadings", new String[]{"datetime", "sgv"}, "datetime >= ? AND datetime <= ? AND calculated_value > ?", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); Cursor cur = db.query("Bg", new String[]{"datetime", "sgv"}, "datetime >= ? AND datetime <= ?", new String[]{"" + bounds.start, "" + bounds.stop}, null, null, null); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); //reading.timestamp = (long)(Double.parseDouble(cur.getString(0))); reading.timestamp = (long)cur.getDouble(0); reading.calculated_value = doubleFromSgv(cur.getString(1)); if(reading.calculated_value >= CUTOFF) { readings.add(reading); Log.d("Double timestamp", "" + reading.timestamp + " | " + cur.getString(0)); } } while (cur.moveToNext()); } return readings; }
Example 8
Source File: DatabaseAdmin.java From xDrip with GNU General Public License v3.0 | 6 votes |
private synchronized List<String> executeSQL(final String query) { final List<String> results = new ArrayList<>(); final SQLiteDatabase db = Cache.openDatabase(); final boolean transaction = !query.equals("vacuum"); if (transaction) db.beginTransaction(); try { final Cursor cursor = db.rawQuery(query, null); Log.d(TAG, "Got query results: " + query + " " + cursor.getCount()); while (cursor.moveToNext()) { for (int c = 0; c < cursor.getColumnCount(); c++) { if (D) Log.d(TAG, "Column: " + cursor.getColumnName(c)); results.add(cursor.getString(c)); } } cursor.close(); if (transaction) db.setTransactionSuccessful(); } finally { if (transaction) db.endTransaction(); } return results; }
Example 9
Source File: DBSearchUtil.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static List<BgReadingStats> getReadings(boolean ordered) { try { Bounds bounds = new Bounds().invoke(); String orderBy = ordered ? "calculated_value desc" : null; SQLiteDatabase db = Cache.openDatabase(); Cursor cur = db.query("bgreadings", new String[]{"timestamp", "calculated_value"}, "timestamp >= ? AND timestamp <= ? AND calculated_value > ? AND snyced == 0", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); reading.timestamp = (Long.parseLong(cur.getString(0))); reading.calculated_value = (Double.parseDouble(cur.getString(1))); readings.add(reading); } while (cur.moveToNext()); } return readings; } catch (Exception e) { JoH.static_toast_long(e.getMessage()); return null; } }
Example 10
Source File: Sensor.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static boolean TableExists(String table) {//KS try { SQLiteDatabase db = Cache.openDatabase(); if (db != null) { db.rawQuery("SELECT * FROM " + table, null); Log.d("wearSENSOR", "TableExists table does NOT exist:" + table); return true; } else { Log.d("wearSENSOR", "TableExists Cache.openDatabase() failed."); return false; } } catch (Exception e) { Log.d("wearSENSOR", "TableExists CATCH error table:" + table); return false; } }
Example 11
Source File: DBSearchUtil.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static List<BgReadingStats> getFilteredReadingsWithFallback(boolean ordered) { try { Bounds bounds = new Bounds().invoke(); String orderBy = ordered ? "calculated_value desc" : null; SQLiteDatabase db = Cache.openDatabase(); Cursor cur = db.query("bgreadings", new String[]{"timestamp", "calculated_value", "filtered_calculated_value"}, "timestamp >= ? AND timestamp <= ? AND calculated_value > ? AND snyced == 0", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); reading.timestamp = (Long.parseLong(cur.getString(0))); reading.calculated_value = (Double.parseDouble(cur.getString(2))); if(reading.calculated_value == 0) reading.calculated_value = (Double.parseDouble(cur.getString(1))); readings.add(reading); } while (cur.moveToNext()); } return readings; } catch (Exception e) { JoH.static_toast_long(e.getMessage()); return null; } }
Example 12
Source File: SqliteRejigger.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private static void executeBatchSQL(String batch) throws SQLException { final String[] statements = batch.split("\n"); final SQLiteDatabase db = Cache.openDatabase(); db.beginTransaction(); try { for (String query : statements) { db.execSQL(query); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
Example 13
Source File: SqliteRejigger.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private static void executeBatchSQL(String batch) throws SQLException { final String[] statements = batch.split("\n"); final SQLiteDatabase db = Cache.openDatabase(); db.beginTransaction(); try { for (String query : statements) { db.execSQL(query); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
Example 14
Source File: SqliteRejigger.java From xDrip with GNU General Public License v3.0 | 5 votes |
private static void executeBatchSQL(String batch) throws SQLException { final String[] statements = batch.split("\n"); final SQLiteDatabase db = Cache.openDatabase(); db.beginTransaction(); try { for (String query : statements) { db.execSQL(query); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
Example 15
Source File: DBSearchUtil.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static List<BgReadingStats> getFilteredReadingsWithFallback(boolean ordered) { try { Bounds bounds = new Bounds().invoke(); String orderBy = ordered ? "calculated_value desc" : null; SQLiteDatabase db = Cache.openDatabase(); Cursor cur = db.query("bgreadings", new String[]{"timestamp", "calculated_value", "filtered_calculated_value"}, "timestamp >= ? AND timestamp <= ? AND calculated_value > ? AND snyced == 0", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); reading.timestamp = (Long.parseLong(cur.getString(0))); reading.calculated_value = (Double.parseDouble(cur.getString(2))); if(reading.calculated_value == 0) reading.calculated_value = (Double.parseDouble(cur.getString(1))); readings.add(reading); } while (cur.moveToNext()); } return readings; } catch (Exception e) { JoH.static_toast_long(e.getMessage()); return null; } }
Example 16
Source File: SqliteRejigger.java From xDrip with GNU General Public License v3.0 | 5 votes |
private static void executeBatchSQL(String batch) throws SQLException { final String[] statements = batch.split("\n"); final SQLiteDatabase db = Cache.openDatabase(); db.beginTransaction(); try { for (String query : statements) { db.execSQL(query); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
Example 17
Source File: StatsResult.java From xDrip with GNU General Public License v3.0 | 4 votes |
public StatsResult(SharedPreferences settings, long from, long to){ this.from = from; this.to = to; mgdl = "mgdl".equals(settings.getString("units", "mgdl")); double high = Double.parseDouble(settings.getString("highValue", "170")); double low = Double.parseDouble(settings.getString("lowValue", "70")); if (!mgdl) { high *= Constants.MMOLL_TO_MGDL; low *= Constants.MMOLL_TO_MGDL; } SQLiteDatabase db = Cache.openDatabase(); Cursor cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value >= " + low + " AND calculated_value <= " + high + " AND snyced == 0", null); cursor.moveToFirst(); in = cursor.getInt(0); cursor.close(); cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + DBSearchUtil.CUTOFF + " AND calculated_value < " + low + " AND snyced == 0", null); cursor.moveToFirst(); below = cursor.getInt(0); cursor.close(); cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + high + " AND snyced == 0", null); cursor.moveToFirst(); above = cursor.getInt(0); cursor.close(); if (canShowRealtimeCapture()) { cursor = db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND source_info LIKE \"%Backfill\" AND snyced == 0", null); cursor.moveToFirst(); backfilledNativeG5 = cursor.getInt(0); cursor.close(); } if(getTotalReadings() > 0){ cursor= db.rawQuery("select avg(calculated_value) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + DBSearchUtil.CUTOFF + " AND snyced == 0", null); cursor.moveToFirst(); avg = cursor.getDouble(0); cursor.close(); } else { avg = 0; } possibleCaptures = (to - from) / (5*60*1000); //while already in the next 5 minutes, a package could already have arrived. if ((to - from) % (5*60*1000) != 0) possibleCaptures += 1; }
Example 18
Source File: StatsResult.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public StatsResult(SharedPreferences settings, long from, long to){ this.from = from; this.to = to; mgdl = "mgdl".equals(settings.getString("units", "mgdl")); double high = Double.parseDouble(settings.getString("highValue", "170")); double low = Double.parseDouble(settings.getString("lowValue", "70")); if (!mgdl) { high *= Constants.MMOLL_TO_MGDL; low *= Constants.MMOLL_TO_MGDL; } SQLiteDatabase db = Cache.openDatabase(); Cursor cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value >= " + low + " AND calculated_value <= " + high + " AND snyced == 0", null); cursor.moveToFirst(); in = cursor.getInt(0); cursor.close(); cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + CUTOFF + " AND calculated_value < " + low + " AND snyced == 0", null); cursor.moveToFirst(); below = cursor.getInt(0); cursor.close(); cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + high + " AND snyced == 0", null); cursor.moveToFirst(); above = cursor.getInt(0); cursor.close(); if(getTotalReadings() > 0){ cursor= db.rawQuery("select avg(calculated_value) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + CUTOFF + " AND snyced == 0", null); cursor.moveToFirst(); avg = cursor.getDouble(0); cursor.close(); } else { avg = 0; } possibleCaptures = (to - from) / (5*60*1000); //while already in the next 5 minutes, a package could already have arrived. if ((to - from) % (5*60*1000) != 0) possibleCaptures += 1; }
Example 19
Source File: StatsResult.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public StatsResult(SharedPreferences settings, long from, long to){ this.from = from; this.to = to; mgdl = "mgdl".equals(settings.getString("units", "mgdl")); double high = Double.parseDouble(settings.getString("highValue", "170")); double low = Double.parseDouble(settings.getString("lowValue", "70")); if (!mgdl) { high *= Constants.MMOLL_TO_MGDL; low *= Constants.MMOLL_TO_MGDL; } SQLiteDatabase db = Cache.openDatabase(); Cursor cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value >= " + low + " AND calculated_value <= " + high + " AND snyced == 0", null); cursor.moveToFirst(); in = cursor.getInt(0); cursor.close(); cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + DBSearchUtil.CUTOFF + " AND calculated_value < " + low + " AND snyced == 0", null); cursor.moveToFirst(); below = cursor.getInt(0); cursor.close(); cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + high + " AND snyced == 0", null); cursor.moveToFirst(); above = cursor.getInt(0); cursor.close(); if (canShowRealtimeCapture()) { cursor = db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND source_info LIKE \"%Backfill\" AND snyced == 0", null); cursor.moveToFirst(); backfilledNativeG5 = cursor.getInt(0); cursor.close(); } if(getTotalReadings() > 0){ cursor= db.rawQuery("select avg(calculated_value) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + DBSearchUtil.CUTOFF + " AND snyced == 0", null); cursor.moveToFirst(); avg = cursor.getDouble(0); cursor.close(); } else { avg = 0; } possibleCaptures = (to - from) / (5*60*1000); //while already in the next 5 minutes, a package could already have arrived. if ((to - from) % (5*60*1000) != 0) possibleCaptures += 1; }
Example 20
Source File: StatsResult.java From xDrip with GNU General Public License v3.0 | 4 votes |
public StatsResult(SharedPreferences settings, long from, long to){ this.from = from; this.to = to; mgdl = "mgdl".equals(settings.getString("units", "mgdl")); double high = Double.parseDouble(settings.getString("highValue", "170")); double low = Double.parseDouble(settings.getString("lowValue", "70")); if (!mgdl) { high *= Constants.MMOLL_TO_MGDL; low *= Constants.MMOLL_TO_MGDL; } SQLiteDatabase db = Cache.openDatabase(); Cursor cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value >= " + low + " AND calculated_value <= " + high + " AND snyced == 0", null); cursor.moveToFirst(); in = cursor.getInt(0); cursor.close(); cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + CUTOFF + " AND calculated_value < " + low + " AND snyced == 0", null); cursor.moveToFirst(); below = cursor.getInt(0); cursor.close(); cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + high + " AND snyced == 0", null); cursor.moveToFirst(); above = cursor.getInt(0); cursor.close(); if(getTotalReadings() > 0){ cursor= db.rawQuery("select avg(calculated_value) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + CUTOFF + " AND snyced == 0", null); cursor.moveToFirst(); avg = cursor.getDouble(0); cursor.close(); } else { avg = 0; } possibleCaptures = (to - from) / (5*60*1000); //while already in the next 5 minutes, a package could already have arrived. if ((to - from) % (5*60*1000) != 0) possibleCaptures += 1; }