DataBases Adapter

2 votes · 0 comments

Using with DB Adapter

raw ·
copy
· download
public class DBAdapter { private static final String[] ALL_INFO = { MyDBHelper.S_ID + "," + MyDBHelper.S_NAME + "," + MyDBHelper.S_PRICE}; private static final String ORDER_BY_DATE = MyDBHelper.S_DATE + " DESC"; private Context context; private SQLiteDatabase database; private MyDBHelper dbHelper; public DBAdapter(Context context) { this.context = context; } public DBAdapter open() throws SQLException { dbHelper = new MyDBHelper(context); database = dbHelper.getWritableDatabase(); return this; } public void close() { dbHelper.close(); } // Dumps old DB and create a new one with new values public void insertInDB(List<Message> messages) { dbHelper.onUpgrade(database,1,2); ContentValues values = new ContentValues(); values.clear(); values.put(MyDBHelper.S_ID,"1"); values.put(MyDBHelper.S_NAME, "Name_Example"); values.put(MyDBHelper.S_PRICE, "Price_Example"); } // Return a Cursor over the list of all rows in the database order by date // (desc) public Cursor getAllRows() { return database.query(MyDBHelper.TABLE_NAME, ALL_INFO, null, null, null, null, ORDER_BY_DATE); } }

Be the first to comment

Sign in with OpenID