List of usage examples for android.database.sqlite SQLiteDatabase close
public void close()
From source file:edu.mit.media.funf.pipeline.BasicPipeline.java
protected void writeData(String name, IJsonObject data) { SQLiteDatabase db = databaseHelper.getWritableDatabase(); final double timestamp = data.get(ProbeKeys.BaseProbeKeys.TIMESTAMP).getAsDouble(); final String value = data.toString(); if (timestamp == 0L || name == null || value == null) { Log.e(LogUtil.TAG, "Unable to save data. Not all required values specified. " + timestamp + " " + name + " - " + value); throw new SQLException("Not all required fields specified."); }/*w w w . j a v a 2 s.c o m*/ String[] subStrings = name.split("\\."); String probeName = subStrings[subStrings.length - 1]; ContentValues cv = new ContentValues(); cv.put(DatabaseHelper.TABLE_STANDARD_PROBE, name); cv.put(DatabaseHelper.TABLE_STANDARD_VALUE, data.toString()); cv.put(DatabaseHelper.TABLE_STANDARD_TIMESTAMP, TimeUtil.alignedTimestamp); for (String entry : data.getAllKeys()) if (DatabaseHelper.getAllowedList().contains(entry.toLowerCase(Locale.ENGLISH))) { String toSave = data.toString(); try { toSave = data.get(entry).getAsString(); } catch (Exception e) { e.printStackTrace(); } cv.put(entry, toSave); } db.insertOrThrow(probeName, "", cv); Log.e("Database", name + " " + TimeUtil.alignedTimestamp); Intent intent = new Intent("pipeline"); intent.putExtra("Name", name); intent.putExtra("IJsonObject", data.toString()); // intent.setAction("edu.mit.media.funf.pipeline.broadcastreceiver"); LocalBroadcastManager.getInstance(getFunfManager()).sendBroadcast(intent); db.close(); }
From source file:com.odoo.orm.OModel.java
/** * Update.//from w w w . j av a 2s .c om * * @param updateValues * the update values * @param where * the where * @param whereArgs * the where args * @return the int */ public int update(OValues updateValues, String where, Object[] whereArgs) { int affectedRows = 0; ContentValues values = createValues(updateValues); SQLiteDatabase db = getWritableDatabase(); if (!updateValues.contains("is_dirty")) values.put("is_dirty", "true"); affectedRows = db.update(getTableName(), values, getWhereClause(where), getWhereArgs(where, whereArgs)); db.close(); updateRelationColumns(updateValues); notifyDataChange(null); return affectedRows; }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public SearchListItem getFavoriteByName(String name) { SearchListItem ret = null;/*from w w w .j a v a2s . c om*/ SQLiteDatabase db = getReadableDatabase(); if (db == null) return null; String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG, KEY_API_ID }; Cursor cursor = db.query(TABLE_FAVORITES, columns, KEY_NAME + " = ? ", new String[] { name.trim() }, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); int colApiId = cursor.getColumnIndex(KEY_API_ID); ret = new FavoritesData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong), cursor.getInt(colApiId)); break; } } if (cursor != null) cursor.close(); db.close(); return ret; }
From source file:com.uproot.trackme.LocationActivity.java
public void showData() throws IOException { SQLiteDatabase db = null; Cursor cursor = null;/*from w ww. j a v a 2s . c om*/ db = openOrCreateDatabase(DATABASE_NAME, SQLiteDatabase.OPEN_READWRITE, null); cursor = db.rawQuery("SELECT * " + " FROM " + POINTS_TABLE_NAME + " ORDER BY GMTTIMESTAMP ASC", null); StringBuffer str = new StringBuffer( "<session id=\"chetan123\" userid=\"" + userid + "\" passkey=\"" + passkey + "\">"); int latitudeColumnIndex = cursor.getColumnIndexOrThrow("LATITUDE"); int longitudeColumnIndex = cursor.getColumnIndexOrThrow("LONGITUDE"); int TSColumnIndex = cursor.getColumnIndexOrThrow("GMTTIMESTAMP"); int ACCColumnIndex = cursor.getColumnIndexOrThrow("ACCURACY"); if (cursor.moveToFirst()) { do { double latitude = cursor.getDouble(latitudeColumnIndex); double longitude = cursor.getDouble(longitudeColumnIndex); long timestamp = (long) cursor.getDouble(TSColumnIndex); long accuracy = (long) cursor.getDouble(ACCColumnIndex); str.append("<location latitude=\""); str.append(latitude); str.append("\" longitude=\""); str.append(longitude); str.append("\" accuracy=\""); str.append(accuracy); str.append("\" timestamp=\""); str.append(timestamp); str.append("\" />"); } while (cursor.moveToNext()); str.append("</session>"); fileContents = str.toString(); } db.close(); }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public ArrayList<FavoritesData> getFavorites(ArrayList<FavoritesData> ret) { if (ret == null) { ret = new ArrayList<FavoritesData>(); } else {// ww w . j a v a2 s .co m ret.clear(); } SQLiteDatabase db = getReadableDatabase(); if (db == null) { return null; } String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG, KEY_API_ID }; Cursor cursor = db.query(TABLE_FAVORITES, columns, null, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); int colApiId = cursor.getColumnIndex(KEY_API_ID); FavoritesData fd = new FavoritesData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong), cursor.getInt(colApiId)); ret.add(fd); cursor.moveToNext(); } } if (cursor != null) { cursor.close(); } db.close(); LOG.d("favourites count from DB = " + ret.size()); return ret; }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public ArrayList<SearchListItem> getFavorites2() { ArrayList<SearchListItem> ret = new ArrayList<SearchListItem>(); SQLiteDatabase db = getReadableDatabase(); if (db == null) return null; String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG, KEY_API_ID };//from ww w .j av a 2s . co m Cursor cursor = db.query(TABLE_FAVORITES, columns, null, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); int colApiId = cursor.getColumnIndex(KEY_API_ID); FavoritesData fd = new FavoritesData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong), cursor.getInt(colApiId)); ret.add((SearchListItem) fd); cursor.moveToNext(); } } if (cursor != null) cursor.close(); db.close(); return ret; }
From source file:com.openatk.field_work.MainActivity.java
public void loadOperations() { SQLiteDatabase database = dbHelper.getReadableDatabase(); Cursor cursor = database.query(TableOperations.TABLE_NAME, TableOperations.COLUMNS, null, null, null, null, null);//from w w w. j av a 2 s .c o m while (cursor.moveToNext()) { Operation operation = TableOperations.cursorToOperation(cursor); if (operation != null) operationsList.add(operation); } cursor.close(); database.close(); dbHelper.close(); List<Operation> operations = dbHelper.readOperations(); operationsList.clear(); operationsList.addAll(operations); if (operations.isEmpty() == false) { //Add the "New Operation" button Operation operation = new Operation(); operation.setName("New Operation"); operationsList.add(operation); } else { //Dont display any operations //Hide? } if (spinnerMenuAdapter != null) spinnerMenuAdapter.notifyDataSetChanged(); selectCurrentOperationInSpinner(); }
From source file:com.maxwen.wallpaper.board.databases.Database.java
public List<Object> getFilteredWallpapersUnified() { List<Object> wallpapers = new ArrayList<>(); List<String> selected = getSelectedCategories(); List<String> selection = new ArrayList<>(); if (selected.size() == 0) return wallpapers; Map<String, Category> categoryMap = getCategoryMap(); StringBuilder CONDITION = new StringBuilder(); for (String item : selected) { if (CONDITION.length() > 0) { CONDITION.append(" OR ").append("LOWER(").append(KEY_CATEGORY).append(")").append(" LIKE ?"); } else {//from w w w. jav a2s. co m CONDITION.append("LOWER(").append(KEY_CATEGORY).append(")").append(" LIKE ?"); } selection.add("%" + item.toLowerCase(Locale.getDefault()) + "%"); } SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_WALLPAPERS, null, CONDITION.toString(), selection.toArray(new String[selection.size()]), null, null, KEY_CATEGORY); if (cursor.moveToFirst()) { String categoryName = cursor.getString(5); Category category = new Category(0, categoryName, categoryMap.get(categoryName).getThumbUrl(), false); wallpapers.add(category); int numWallpapers = 0; do { String newCategoryName = cursor.getString(5); if (!newCategoryName.equals(categoryName)) { category.setNumWallpapers(numWallpapers); numWallpapers = 0; categoryName = newCategoryName; category = new Category(0, newCategoryName, categoryMap.get(newCategoryName).getThumbUrl(), false); wallpapers.add(category); } Wallpaper wallpaper = new Wallpaper(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getInt(6) == 1, cursor.getLong(7)); wallpapers.add(wallpaper); numWallpapers++; } while (cursor.moveToNext()); category.setNumWallpapers(numWallpapers); } cursor.close(); db.close(); return wallpapers; }
From source file:com.maxwen.wallpaper.board.databases.Database.java
public List<Object> getFavoriteWallpapersUnified() { List<Object> wallpapers = new ArrayList<>(); List<String> selected = getSelectedCategories(); List<String> selection = new ArrayList<>(); if (selected.size() == 0) return wallpapers; Map<String, Category> categoryMap = getCategoryMap(); StringBuilder CONDITION = new StringBuilder(); for (String item : selected) { if (CONDITION.length() > 0) { CONDITION.append(" OR ").append("LOWER(").append(KEY_CATEGORY).append(")").append(" LIKE ?"); } else {/* w w w .j a va 2 s . c om*/ CONDITION.append("LOWER(").append(KEY_CATEGORY).append(")").append(" LIKE ?"); } selection.add("%" + item.toLowerCase(Locale.getDefault()) + "%"); } CONDITION.append(" AND " + KEY_FAVORITE + " = ?"); selection.add("1"); SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_WALLPAPERS, null, CONDITION.toString(), selection.toArray(new String[selection.size()]), null, null, KEY_CATEGORY); if (cursor.moveToFirst()) { String categoryName = cursor.getString(5); Category category = new Category(0, categoryName, categoryMap.get(categoryName).getThumbUrl(), false); wallpapers.add(category); int numWallpapers = 0; do { String newCategoryName = cursor.getString(5); if (!newCategoryName.equals(categoryName)) { category.setNumWallpapers(numWallpapers); numWallpapers = 0; categoryName = newCategoryName; category = new Category(0, newCategoryName, categoryMap.get(newCategoryName).getThumbUrl(), false); wallpapers.add(category); } Wallpaper wallpaper = new Wallpaper(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getInt(6) == 1, cursor.getLong(7)); wallpapers.add(wallpaper); numWallpapers++; } while (cursor.moveToNext()); category.setNumWallpapers(numWallpapers); } cursor.close(); db.close(); return wallpapers; }
From source file:com.openerp.orm.ORM.java
/** * Execute query./* w ww. jav a 2 s . c o m*/ * * @param dbHelper * the db helper * @param where * the where * @param whereVals * the where vals * @param group_by * the group_by * @param having * the having * @param orderby * the orderby * @return the list */ private List<HashMap<String, Object>> executeQuery(BaseDBHelper dbHelper, String[] fetch_columns, String[] where, String[] whereVals, String group_by, String having, String orderby) { SQLiteDatabase db = getWritableDatabase(); List<String> cols = new ArrayList<String>(); String columns[] = null; if (fetch_columns != null) { cols = new ArrayList<String>(); cols = Arrays.asList(fetch_columns); } else { for (Fields col : dbHelper.getColumns()) { if (!(col.getType() instanceof Many2Many)) { cols.add(col.getName()); } } } columns = cols.toArray(new String[cols.size()]); Cursor cursor = db.query(modelToTable(dbHelper.getModelName()), columns, whereStatement(where, dbHelper), whereVals, group_by, having, orderby); List<HashMap<String, Object>> data = getResult(dbHelper, columns, cursor); db.close(); return data; }