List of usage examples for android.database.sqlite SQLiteDatabase close
public void close()
From source file:com.openatk.rockapp.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); dbHelper = new DatabaseHelper(this); FragmentManager fm = getSupportFragmentManager(); SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.map); if (savedInstanceState == null) { // First incarnation of this activity. f.setRetainInstance(true);// w w w .j av a 2s . co m } else { // Reincarnated activity. The obtained map is the same map instance // in the previous // activity life cycle. There is no need to reinitialize it. map = f.getExtendedMap(); } checkGPS(); mCurrentRockSelected = Rock.BLANK_ROCK_ID; slideMenu = (RockMenu) findViewById(R.id.rock_edit_layout); slideMenu.setDBHelper(dbHelper); slideMenu.setListener(this); mapBroadcastReciever = new MapBroadcastReciever(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mRockState = prefs.getInt("mRockState", STATE_ROCKS_NOT_PICKED_UP); // Restore state from savedInstanceState if (savedInstanceState != null) { mCurrentRockSelected = savedInstanceState.getInt("rock_edit.currentRock", Rock.BLANK_ROCK_ID); switch (savedInstanceState.getInt("state", STATE_DEFAULT)) { case STATE_ROCK_EDIT: // Get RockId and restore view states for setState() Log.d("MainActivity", "Editing rock:" + Integer.toString(mCurrentRockSelected)); SQLiteDatabase database = dbHelper.getReadableDatabase(); Rock theRock = Rock.getRockById(database, mCurrentRockSelected); database.close(); dbHelper.close(); theRock.setListener(this); slideMenu.editRock(theRock); break; } Log.d("MainActivity", "Startup State:" + Integer.toString(savedInstanceState.getInt("state", STATE_DEFAULT))); // Restore previous state setState(savedInstanceState.getInt("state", STATE_DEFAULT)); } else { // Otherwise set default initial state setState(STATE_DEFAULT); // TODO Zoom all markers (rocks) mRockState = STATE_ROCKS_NOT_PICKED_UP; } setUpMapIfNeeded(); }
From source file:com.yammy.meter.MainActivity.java
private void checkJarak() { double maxval; dbHelper = new MySQLHelper(getApplicationContext()); SQLiteDatabase jdb = dbHelper.getReadableDatabase(); Cursor cursor = jdb.rawQuery("SELECT maxlength FROM kendaraan WHERE _id=" + idkendaraan, null); if (cursor.moveToFirst()) { maxval = cursor.getDouble(0);// w ww . jav a 2 s . c o m double temp; temp = (totalJarakDitempuhKendaraan % maxval); //simple if, need 'mbengkel' data for details //cursor = jdb.rawQuery("SELECT jarak FROM latest_mbengkel WHERE id_kendaraan="+idkendaraan, null); if (temp >= maxval * 90 / 100) { showAlert(); } } jdb.close(); }
From source file:org.lastmilehealth.collect.android.tasks.BluetoothService.java
private void clearForms() { SQLiteDatabase db = SQLiteDatabase.openDatabase(Collect.FORMS_DB_PATH, null, SQLiteDatabase.OPEN_READWRITE); db.execSQL("delete from forms"); db.close(); deletePreferences();//from ww w . j a va2 s . co m try { org.apache.commons.io.FileUtils.cleanDirectory(new File(Collect.FORMS_PATH)); org.apache.commons.io.FileUtils.cleanDirectory(new File(Collect.ROLES_PATH)); } catch (Exception e) { } }
From source file:com.acrylicgoat.devchat.MainActivity.java
private String getYesterday(String owner) { //Log.d("MainActivity", "getYesterday() called: " + owner); StringBuilder sb = new StringBuilder(); String results = ""; sb.append("select notes_note, date(notes_date) as notes_date from notes where notes_owner='"); sb.append(currentOwner);// w ww. j av a 2 s .c om sb.append("' and date(notes_date)<=date('now','localtime','-1 day') order by date(notes_date) desc"); DatabaseHelper dbHelper = new DatabaseHelper(this.getApplicationContext()); SQLiteDatabase db = dbHelper.getReadableDatabase(); cursor = db.rawQuery(sb.toString(), null); if (cursor.getCount() > 0) { cursor.moveToNext(); int notesColumn = cursor.getColumnIndex(Notes.NOTE); int dateColumn = cursor.getColumnIndex(Notes.DATE); //Log.d("MainActivity.getYesterday()", "notesColumn: " + notesColumn); results = cursor.getString(dateColumn) + " - " + cursor.getString(notesColumn); } cursor.close(); db.close(); return results; }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public void deleteFavorite(FavoritesData fd, Context context) { SQLiteDatabase db = this.getWritableDatabase(); if (db == null) return;// w w w.j ava 2s . co m db.delete(TABLE_FAVORITES, KEY_ID + " = ?", new String[] { "" + fd.getId() }); db.close(); if (context != null) deleteFavoriteFromServer(fd, context); }
From source file:com.dpcsoftware.mn.EditCategories.java
private void renderCategories() { SQLiteDatabase db = DatabaseHelper.quickDb(this, 0); Cursor c = db/*w w w . j av a 2 s.co m*/ .rawQuery( "SELECT " + Db.Table2._ID + "," + Db.Table2.COLUMN_NCAT + "," + Db.Table2.COLUMN_CORCAT + " FROM " + Db.Table2.TABLE_NAME + " ORDER BY " + Db.Table2.COLUMN_NCAT + " ASC", null); if (adapter == null) { adapter = new CategoriesAdapter(this, c); lv.setAdapter(adapter); setContentView(lv); } else { adapter.swapCursor(c); adapter.notifyDataSetChanged(); } db.close(); }
From source file:com.quuzz.tbg.recyclerview.CustomAdapter.java
private TbModel[] initDataset() { // init DB// w ww .j ava 2 s . c o m // Gets the data repository in write mode // String[] mDataset = new String[DATASET_COUNT]; TbDbHelper tbDbHelper = new TbDbHelper(context); SQLiteDatabase db = tbDbHelper.getReadableDatabase(); Cursor cursor = db.query("tbdata", null, null, null, null, null, null); int count = cursor.getCount(); cursor.moveToFirst(); TbModel[] mDataset = new TbModel[count]; for (int i = 0; i < count; i++) { mDataset[i] = new TbModel(); mDataset[i].setName(cursor.getString(cursor.getColumnIndex("name"))); mDataset[i].setTbId(cursor.getString(cursor.getColumnIndex("tb_id"))); mDataset[i].setImageData(cursor.getBlob(cursor.getColumnIndex("image_data"))); mDataset[i].setDescription(cursor.getString(cursor.getColumnIndex("description"))); cursor.moveToNext(); } cursor.close(); db.close(); return mDataset; }
From source file:com.acrylicgoat.scrumnotes.DailyNotesActivity.java
private void saveNote() { ContentValues values = new ContentValues(); String noteStr = note.getText().toString(); //Log.d("NoteEditorActivity", "note: " + text); int nlength = noteStr.length(); if (nlength == 0) { Toast.makeText(this, getString(R.string.nothing_to_save), Toast.LENGTH_SHORT).show(); return;//from w w w. java 2 s.c o m } values.put(Goals.NOTE, noteStr); //check if a note already exists for today DatabaseHelper dbHelper = new DatabaseHelper(this.getApplicationContext()); SQLiteDatabase db = dbHelper.getReadableDatabase(); cursor = db.rawQuery("select goals_goal from goals", null); if (cursor.getCount() > 0) { //Log.d("MainActivity", "saveNote(): doing update "); StringBuilder sb = new StringBuilder(); sb.append("update goals set goals_note = '"); sb.append(ScrumNotesUtil.escape(noteStr)); sb.append("'"); dbHelper.getReadableDatabase().execSQL(sb.toString()); getContentResolver().update(Goals.CONTENT_URI, values, null, null); } else { getContentResolver().insert(Goals.CONTENT_URI, values); } cursor.close(); db.close(); }
From source file:org.akop.crosswords.Storage.java
public boolean emptyFolder(long folderId) { StorageHelper helper = getHelper();/*from w w w . ja va2 s.c om*/ SQLiteDatabase db = helper.getWritableDatabase(); int puzzlesDeleted; int statesDeleted; try { statesDeleted = db.delete(PuzzleState.TABLE, PuzzleState.PUZZLE_ID + " IN (" + "SELECT " + Puzzle._ID + " " + "FROM " + Puzzle.TABLE + " " + "WHERE " + Puzzle.FOLDER_ID + "=" + folderId + ")", null); puzzlesDeleted = db.delete(Puzzle.TABLE, Puzzle.FOLDER_ID + "=" + folderId, null); } finally { db.close(); } if (puzzlesDeleted > 0) { Intent outgoing = new Intent(ACTION_PUZZLE_CHANGE); sendLocalBroadcast(outgoing); } Crosswords.logv("Deleted %d puzzles and %d states", puzzlesDeleted, statesDeleted); return puzzlesDeleted > 0; }
From source file:com.shalzz.attendance.DatabaseHandler.java
public ListFooter getListFooter() { SQLiteDatabase db = this.getReadableDatabase(); ListFooter footer = null;/*from w w w . j a va 2 s.c o m*/ String selectQuery = "SELECT sum(" + Subject.ATTENDED + ") as " + KEY_TOTAL_ATTEND + ",sum(" + Subject.HELD + ") as " + KEY_TOTAL_HELD + " FROM " + Subject.TABLE_NAME + ";"; try (Cursor cursor = db.rawQuery(selectQuery, null)) { if (cursor.moveToFirst()) { footer = ListFooter.builder().setHeld(cursor.getFloat(cursor.getColumnIndexOrThrow(KEY_TOTAL_HELD))) .setAttended(cursor.getFloat(cursor.getColumnIndexOrThrow(KEY_TOTAL_ATTEND))).build(); } db.close(); cursor.close(); } return footer; }