@Override public int getSize() { SQLiteDatabase db = this.getReadableDatabase(); int size = ((Long) ExtraUtils.longForQuery(db, "SELECT COUNT(*) FROM " + this.table_identifier, null)) .intValue(); db.close(); return size; }
@Override public void insert(STPoint point) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("minX", point.getX()); values.put("maxX", point.getX()); values.put("minY", point.getY()); values.put("maxY", point.getY()); values.put("minT", point.getT()); values.put("maxT", point.getT()); db.insert( this.table_identifier, // table null, // nullColumnHack values); // key/value -> keys = column names/ values = column values db.close(); }
private float getRowValueHelper(SQLiteDatabase db, String query, int index) { Cursor cur = db.rawQuery(query, null); cur.moveToFirst(); float val = cur.getFloat(index); cur.close(); return val; }
@Override public List<STPoint> range(STRegion range) { SQLiteDatabase db = this.getReadableDatabase(); String query = "SELECT id,minX,maxX,minY,maxY,minT,maxT from " + this.table_identifier + " "; STPoint mins = range.getMins(); STPoint maxs = range.getMaxs(); String prefix = " WHERE "; if (mins.hasX() && maxs.hasX()) { query += prefix + " minX >= " + String.valueOf(mins.getX()) + " AND maxX <= " + String.valueOf(maxs.getX()); prefix = " AND "; } if (mins.hasY() && maxs.hasY()) { query += prefix + " minY >= " + String.valueOf(mins.getY()) + " AND maxY <= " + String.valueOf(maxs.getY()); prefix = " AND "; } if (mins.hasT() && maxs.hasT()) { query += prefix + " minT >= " + String.valueOf(mins.getT()) + " AND maxT <= " + String.valueOf(maxs.getT()); prefix = " AND "; } Cursor cur = db.rawQuery(query, null); List<STPoint> points = cursorToList(cur); db.close(); return points; }
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w( SQLiteRTree.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS " + this.table_identifier); onCreate(db); }
@Override public void onCreate(SQLiteDatabase database) { String create_rtree = "CREATE VIRTUAL TABLE " + this.table_identifier + " USING rtree(\n" + " id, -- Integer primary key\n" + " minX, maxX, -- Minimum and maximum X coordinate\n" + " minY, maxY, -- Minimum and maximum Y coordinate\n" + " minT, maxT -- Minimum and maximum T coordinate\n" + ");"; Log.d("LST", "Created table: " + this.table_identifier); database.execSQL(create_rtree); }
public void clear() { SQLiteDatabase db = this.getWritableDatabase(); db.delete(this.table_identifier, null, null); }