Android Open Source - bnote D B Manager






From Project

Back to project page bnote.

License

The source code is released under:

MIT License

If you think the Android project bnote listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.rd.bnote;
//from  w w w  .java 2 s.com
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class DBManager {

  private DBHelper mDbHelper;
  private SQLiteDatabase mdb;
  
  public DBManager(Context context) {
    mDbHelper = new DBHelper(context);
    mdb = mDbHelper.getWritableDatabase();
  }
  public void closeDBManager() {
    mdb.close();
  }
  public void add(Note note) {
    ContentValues values = new ContentValues();
    values.put(Note.FIELD_SNAP, note.snap);
    values.put(Note.FIELD_CONTENT, note.content);
    mdb.insert(DBHelper.DATABASE_TABLE, null, values);
  }
  public void update(Note note) {
    ContentValues values = new ContentValues();
    values.put(Note.FIELD_SNAP, note.snap);
    values.put(Note.FIELD_CONTENT, note.content);
    mdb.update(DBHelper.DATABASE_TABLE, values, Note.FIELD__ID + "=?", new String[]{(String.valueOf(note._id))});
  }
  public void delete(Note note) {
    mdb.delete(DBHelper.DATABASE_TABLE, Note.FIELD__ID + "=?", new String[]{(String.valueOf(note._id))});
  }
  public Cursor query() {
    String orderBy = Note.FIELD_PUB_DATE + " DESC";
    String[] columns = new String[]{Note.FIELD__ID, Note.FIELD_PUB_DATE, Note.FIELD_SNAP};
    Cursor cursor = mdb.query(DBHelper.DATABASE_TABLE, columns , null, null, null, null, orderBy);
    return cursor;
  }
  public Cursor query(Note note) {
    String[] columns = new String[]{Note.FIELD__ID, Note.FIELD_PUB_DATE, Note.FIELD_CONTENT};
    String selection = Note.FIELD__ID + "=?";
    String[] selectionArgs = new String[]{ String.valueOf(note._id) };
    Cursor cursor = mdb.query(DBHelper.DATABASE_TABLE, columns, selection, selectionArgs, null, null, null);
    return cursor;
  }
  public Cursor query(String s) {
    String orderBy = Note.FIELD_PUB_DATE + " DESC";
    String selection = Note.FIELD_CONTENT + " LIKE ?";
    String[] selectionArgs = new String[]{ "%" + s + "%" };
    String[] columns = new String[]{Note.FIELD__ID, Note.FIELD_PUB_DATE, Note.FIELD_SNAP};
    Cursor cursor = mdb.query(DBHelper.DATABASE_TABLE, columns , selection, selectionArgs, null, null, orderBy);
    return cursor;
  }
}




Java Source Code List

com.rd.bnote.DBHelper.java
com.rd.bnote.DBManager.java
com.rd.bnote.DateSimpleCursorAdapter.java
com.rd.bnote.EditActivity.java
com.rd.bnote.JSONParser.java
com.rd.bnote.ListActivity.java
com.rd.bnote.Note.java
com.rd.bnote.SearchableActivity.java