List of usage examples for android.database.sqlite SQLiteDatabase close
public void close()
From source file:com.modestmaps.providers.connection.TileBaseHelper.java
private boolean checkDatabase() { System.out.println("1. checkDatabase().."); SQLiteDatabase checkableDatabase = null; boolean localDatabaseExists = false; //String checkableDatabase = null; //dummy null String.. System.out.println("1. null checkableDatabase created..!!"); try {// www . java2 s. c o m checkableDatabase = SQLiteDatabase.openDatabase(DBPATH + DBNAME, null, SQLiteDatabase.OPEN_READONLY); } catch (Exception e) { System.out.println("1. database doesnt exist/is corrupt..so copy from server.."); //our database doesn't exist, so we'll return false below. System.out.println("Copying from: " + serverADD); localDatabaseExists = false; //checkableDatabase.close(); checkableDatabase = null; } if (checkableDatabase != null) { localDatabaseExists = true; System.out.println("1. huh?? database exists?? " + localDatabaseExists); checkableDatabase.close(); } System.out.println("2. returning checkableDatabase().." + localDatabaseExists); return localDatabaseExists; }
From source file:com.maxwen.wallpaper.board.databases.Database.java
public void addWallpapers(@NonNull List<Wallpaper> wallpapers) { SQLiteDatabase db = this.getWritableDatabase(); long insertTime = System.currentTimeMillis(); for (int i = 0; i < wallpapers.size(); i++) { ContentValues values = new ContentValues(); values.put(KEY_NAME, wallpapers.get(i).getName()); values.put(KEY_AUTHOR, wallpapers.get(i).getAuthor()); values.put(KEY_URL, wallpapers.get(i).getUrl()); values.put(KEY_THUMB_URL, wallpapers.get(i).getThumbUrl()); values.put(KEY_CATEGORY, wallpapers.get(i).getCategory()); values.put(KEY_ADDED_ON, insertTime); db.insert(TABLE_WALLPAPERS, null, values); }//from ww w.j a v a 2 s. c o m db.close(); }
From source file:com.maxwen.wallpaper.board.databases.Database.java
@Nullable public List<Wallpaper> getWallpapersOfCatgegory(String category) { List<Wallpaper> wallpapers = new ArrayList<>(); List<String> selection = new ArrayList<>(); StringBuilder CONDITION = new StringBuilder(); CONDITION.append("LOWER(").append(KEY_CATEGORY).append(")").append(" LIKE ?"); selection.add("%" + category.toLowerCase(Locale.getDefault()) + "%"); SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_WALLPAPERS, null, CONDITION.toString(), selection.toArray(new String[selection.size()]), null, null, null, null); if (cursor.moveToFirst()) { do {//from w ww . j a v a2s .c o m 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); } while (cursor.moveToNext()); } cursor.close(); db.close(); return wallpapers; }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public void updateFavorite(FavoritesData fd, Context context, APIListener listener) { SQLiteDatabase db = this.getWritableDatabase(); if (db == null) return;// w w w. ja v a2s .c o m ContentValues values = new ContentValues(); values.put(KEY_NAME, fd.getName()); values.put(KEY_ADDRESS, fd.getAdress()); values.put(KEY_SOURCE, fd.getSource()); values.put(KEY_SUBSOURCE, fd.getSubSource()); values.put(KEY_LAT, Double.valueOf(fd.getLatitude())); values.put(KEY_LONG, Double.valueOf(fd.getLongitude())); db.update(TABLE_FAVORITES, values, KEY_ID + " = ?", new String[] { "" + fd.getId() }); db.close(); if (context != null) updateFavoriteToServer(fd, context, listener); }
From source file:com.maxwen.wallpaper.board.databases.Database.java
public List<Wallpaper> getFilteredWallpapers() { List<Wallpaper> wallpapers = new ArrayList<>(); List<String> selected = getSelectedCategories(); List<String> selection = new ArrayList<>(); if (selected.size() == 0) return wallpapers; 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.j ava 2 s .c o 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()) { do { 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); } while (cursor.moveToNext()); } cursor.close(); db.close(); return wallpapers; }
From source file:com.maxwen.wallpaper.board.databases.Database.java
public List<Wallpaper> getFavoriteWallpapers() { List<Wallpaper> wallpapers = new ArrayList<>(); List<String> selected = getSelectedCategories(); List<String> selection = new ArrayList<>(); if (selected.size() == 0) return wallpapers; 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. ja v a2 s .c o m*/ 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()) { do { 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); } while (cursor.moveToNext()); } cursor.close(); db.close(); return wallpapers; }
From source file:com.denimgroup.android.training.pandemobium.stocktrader.ManageTipsActivity.java
private void doSendTipData(String symbol) { StockDatabase dbHelper = new StockDatabase(this.getApplicationContext()); SQLiteDatabase db = dbHelper.openDatabase(); StringBuilder sb = new StringBuilder(); String sql = "SELECT * FROM tip WHERE symbol = '" + symbol + "'"; Log.d("ManageTipsActivity", "SQL to execute is: " + sql); Cursor tips = db.rawQuery(sql, null); // Take all the data returned and package it up for sending int numTips = tips.getCount(); Log.d("ManageTipsActivity", "Got " + numTips + " tips to send"); tips.moveToFirst();//from w w w .j a v a 2 s . co m for (int i = 0; i < numTips; i++) { sb.append("TIP"); sb.append(i); sb.append(":"); int columnCount = tips.getColumnCount(); Log.d("ManageTipsActivity", "Tip " + i + " has " + columnCount + " columns"); for (int j = 0; j < columnCount; j++) { if (j > 0) { sb.append("&"); } sb.append(tips.getColumnName(j)); sb.append("="); sb.append(tips.getString(j)); } tips.moveToNext(); sb.append("\n"); } tips.close(); db.close(); Log.d("ManageTipsActivity", "Tip data to post is: " + sb.toString()); String accountId = AccountUtils.retrieveAccountId(getApplicationContext()); String tradeServiceUrl = getResources().getString(R.string.tip_service); String fullUrl = tradeServiceUrl + "?method=submitTips&id=" + accountId; Log.d("ManageTipsActivity", "Full URL for tip sending is: " + fullUrl); HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(fullUrl); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("tipData", sb.toString())); try { post.setEntity(new UrlEncodedFormEntity(pairs)); HttpResponse response = client.execute(post); tvTipStatus.setText("Tip data for " + etSymbol.getText().toString() + " sent!"); } catch (Exception e) { Log.e("ManageTipsActivity", "Error when encoding or sending tip data: " + e.toString()); e.printStackTrace(); } }
From source file:com.snt.bt.recon.database.DBHandler.java
public void addBcEntry(BluetoothClassicEntry bc_entry) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_SESSION_ID, bc_entry.getSessionId().toString()); values.put(KEY_LOCATION_ID, bc_entry.getLocationId().toString()); values.put(KEY_TIMESTAMP, bc_entry.getTimestamp()); values.put(KEY_MAC, bc_entry.getMac()); values.put(KEY_TYPE, bc_entry.getType()); values.put(KEY_RSSI, bc_entry.getRssi()); values.put(KEY_DEVICE_NAME, bc_entry.getDeviceName()); values.put(KEY_BC_CLASS, bc_entry.getBcClass()); values.put(KEY_UPLOAD_STATUS, bc_entry.getUploadStatus()); // Inserting Row db.insertOrThrow(TABLE_BC, null, values); //Log.d("DatabaseTest1", ""+test); db.close(); // Closing database connection }
From source file:com.maxwen.wallpaper.board.databases.Database.java
public List<Object> getFilteredCategoriesUnified() { List<Object> categories = new ArrayList<>(); List<String> selected = getSelectedCategories(); List<String> selection = new ArrayList<>(); if (selected.size() == 0) return categories; StringBuilder CONDITION = new StringBuilder(); for (String item : selected) { if (CONDITION.length() > 0) { CONDITION.append(" OR ").append("LOWER(").append(KEY_NAME).append(")").append(" LIKE ?"); } else {/*from w w w . j ava2 s . c o m*/ CONDITION.append("LOWER(").append(KEY_NAME).append(")").append(" LIKE ?"); } selection.add("%" + item.toLowerCase(Locale.getDefault()) + "%"); } SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_CATEGORIES, null, CONDITION.toString(), selection.toArray(new String[selection.size()]), null, null, KEY_NAME); if (cursor.moveToFirst()) { do { Category category = new Category(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getInt(3) == 1); int count = getWallpapersCountOfCatgegory(cursor.getString(1)); category.setNumWallpapers(count); categories.add(category); } while (cursor.moveToNext()); } cursor.close(); db.close(); return categories; }
From source file:net.smart_json_database.JSONDatabase.java
/** * Insert or update a property to db//from ww w .ja v a 2 s .c o m * * @param key * @param value * @return */ public long setProperty(String key, String value) { SQLiteDatabase db = dbHelper.getWritableDatabase(); String checkKey = Util.DateToString(new Date()); ContentValues values = new ContentValues(); values.put("value", value); long i = -1; if (checkKey.equals(getPropterty(db, key, checkKey))) { values.put("key", key); i = db.insert(TABLE_Meta, null, values); } else { i = db.update(TABLE_Meta, values, "key = ?", new String[] { key }); } db.close(); return i; }