Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DbAdapter extends AbstractDbAdapter {
- private static final String DATABASE_TABLE_1 = "Lists";
- public static final String KEY_ROWID1 = "_id";
- public static final String KEY_TITLE = "Title";
- public static final String KEY_SHOP = "Shop";
- public static final String KEY_DATA = "Data";
- public static final String KEY_B_ALLOC = "Budget_allocated";
- public static final String KEY_B_SPENT = "Budget_spent";
- private static final String DATABASE_TABLE_2 = "Products";
- public static final String KEY_ROWID2 = "_id";
- public static final String KEY_LISTID = "ListId";
- public static final String KEY_ITEM = "Item";
- public static final String KEY_QUANTITY = "Quantity";
- public static final String KEY_UNITS = "Units";
- private static final String DATABASE_TABLE_3 = "Shops";
- public static final String KEY_ROWID3 = "_id";
- public static final String NAME = "Name";
- public static final String ADRESS = "Adress";
- public static final String TYPE = "Type";
- public static final String LATITUDINE = "Latitudine";
- public static final String LONGITUDINE = "Longitudine";
- private static final String DATABASE_TABLE_4 = "Budget";
- public static final String KEY_ROWID4 = "_id";
- public static final String KEY_BUDGET = "Budget";
- public static final String KEY_BUDGET_DATA = "Data_budget";
- DbAdapter db;
- public DbAdapter(Context ctx) {
- super(ctx);
- }
- /* create */
- public long createlist(String title, String shop, String data,
- String b_alloc, String b_spent) {
- ContentValues args = new ContentValues();
- args.put(KEY_TITLE, title);
- args.put(KEY_SHOP, shop);
- args.put(KEY_DATA, data);
- args.put(KEY_B_ALLOC, b_alloc);
- args.put(KEY_B_SPENT, b_spent);
- return mDb.insert(DATABASE_TABLE_1, null, args);
- }
- public long createproduct(Integer listid, String item, String quantity,
- String units) {
- ContentValues args = new ContentValues();
- args.put(KEY_LISTID, listid);
- args.put(KEY_ITEM, item);
- args.put(KEY_QUANTITY, quantity);
- args.put(KEY_UNITS, units);
- return mDb.insert(DATABASE_TABLE_2, null, args);
- }
- public long createshop(String shop, String adress, String types,
- Double latitudine, Double longitudine) {
- ContentValues args = new ContentValues();
- args.put(NAME, shop);
- args.put(ADRESS, adress);
- args.put(TYPE, types);
- args.put(LATITUDINE, latitudine);
- args.put(LONGITUDINE, longitudine);
- return mDb.insert(DATABASE_TABLE_3, null, args);
- }
- public long createbudget(String budget, String data) {
- ContentValues args = new ContentValues();
- args.put(KEY_BUDGET, budget);
- args.put(KEY_BUDGET_DATA, data);
- return mDb.insert(DATABASE_TABLE_4, null, args);
- }
- /* Update */
- public boolean updatelist(long rowId, String title, String shop,
- String data, String b_alloc, String b_spent) {
- ContentValues args = new ContentValues();
- args.put(KEY_TITLE, title);
- args.put(KEY_SHOP, shop);
- args.put(KEY_DATA, data);
- args.put(KEY_B_ALLOC, b_alloc);
- args.put(KEY_B_SPENT, b_spent);
- return mDb.update(DATABASE_TABLE_1, args, KEY_ROWID1 + "=" + rowId,
- null) > 0;
- }
- public boolean updateproduct(long rowId, Integer listid, String item,
- String quantity, String units) {
- ContentValues values = new ContentValues();
- values.put(KEY_LISTID, listid);
- values.put(KEY_ITEM, item);
- values.put(KEY_QUANTITY, quantity);
- values.put(KEY_UNITS, units);
- return mDb.update(DATABASE_TABLE_2, values, KEY_ROWID2 + "=" + rowId,
- null) > 0;
- }
- public boolean updateshop(long rowId, String shop, String adress,
- String types, Double latitudine, Double longitudine) {
- ContentValues args = new ContentValues();
- args.put(NAME, shop);
- args.put(ADRESS, adress);
- args.put(TYPE, types);
- args.put(LATITUDINE, latitudine);
- args.put(LONGITUDINE, longitudine);
- return mDb.update(DATABASE_TABLE_3, args, KEY_ROWID3 + "=" + rowId,
- null) > 0;
- }
- public boolean updatebudget(long rowId, String budget, String data) {
- ContentValues args = new ContentValues();
- args.put(KEY_BUDGET, budget);
- args.put(KEY_BUDGET_DATA, data);
- return mDb.update(DATABASE_TABLE_4, args, KEY_ROWID4 + "=" + rowId,
- null) > 0;
- }
- /* Delete */
- public boolean deletelist(long rowId) {
- return mDb.delete(DATABASE_TABLE_1, KEY_ROWID1 + "=" + rowId, null) > 0;
- }
- public boolean deleteproduct(long rowId) {
- return mDb.delete(DATABASE_TABLE_2, KEY_ROWID2 + "=" + rowId, null) > 0;
- }
- public boolean deleteshop(long rowId) {
- return mDb.delete(DATABASE_TABLE_3, KEY_ROWID3 + "=" + rowId, null) > 0;
- }
- public boolean deletebudget(long rowId) {
- return mDb.delete(DATABASE_TABLE_4, KEY_ROWID4 + "=" + rowId, null) > 0;
- }
- /* Getall */
- public Cursor getAllLists() {
- return mDb.query(DATABASE_TABLE_1, new String[] { KEY_ROWID1,
- KEY_TITLE, KEY_SHOP, KEY_DATA, KEY_B_ALLOC, KEY_B_SPENT },
- null, null, null, null, null);
- }
- public Cursor getAllProducts() {
- return mDb.query(DATABASE_TABLE_2, new String[] { KEY_ROWID2,
- KEY_LISTID, KEY_ITEM, KEY_QUANTITY, KEY_UNITS }, null, null,
- null, null, null);
- }
- public Cursor getAllShops() {
- return mDb.query(DATABASE_TABLE_3, new String[] { KEY_ROWID3, NAME,
- ADRESS, TYPE, LATITUDINE, LONGITUDINE }, null, null, null,
- null, null);
- }
- public Cursor getAllBudget() {
- return mDb.query(DATABASE_TABLE_4, new String[] { KEY_ROWID4,
- KEY_BUDGET, KEY_BUDGET_DATA }, null, null, null, null, null);
- }
- /* Getone */
- public Cursor getList(long rowId) throws SQLException {
- Cursor mCursor = mDb.query(true, DATABASE_TABLE_1, new String[] {
- KEY_ROWID1, KEY_TITLE, KEY_SHOP, KEY_DATA, KEY_B_ALLOC,
- KEY_B_SPENT }, KEY_ROWID1 + "=" + rowId, null, null, null,
- null, null);
- if (mCursor != null) {
- mCursor.moveToFirst();
- }
- return mCursor;
- }
- public Cursor getProduct(long rowId) throws SQLException {
- Cursor mCursor = mDb.query(true, DATABASE_TABLE_2, new String[] {
- KEY_ROWID2, KEY_LISTID, KEY_ITEM, KEY_QUANTITY, KEY_UNITS },
- KEY_ROWID2 + "=" + rowId, null, null, null, null, null);
- if (mCursor != null) {
- mCursor.moveToFirst();
- }
- return mCursor;
- }
- public Cursor getShop(long rowId) throws SQLException {
- Cursor mCursor = mDb.query(true, DATABASE_TABLE_3, new String[] {
- KEY_ROWID3, NAME, ADRESS, TYPE, LATITUDINE, LONGITUDINE },
- KEY_ROWID3 + "=" + rowId, null, null, null, null, null);
- if (mCursor != null) {
- mCursor.moveToFirst();
- }
- return mCursor;
- }
- public Cursor getBudget(long rowId) throws SQLException {
- Cursor mCursor = mDb.query(true, DATABASE_TABLE_4, new String[] {
- KEY_ROWID4, KEY_BUDGET, KEY_BUDGET_DATA }, KEY_ROWID4 + "="
- + rowId, null, null, null, null, null);
- if (mCursor != null) {
- mCursor.moveToFirst();
- }
- return mCursor;
- }
- public Cursor fetchListId(String listId) throws SQLException {
- Cursor mCursor = mDb.query(true, DATABASE_TABLE_2, new String[] {
- KEY_ROWID2, KEY_LISTID, KEY_ITEM, KEY_QUANTITY, KEY_UNITS },
- KEY_LISTID + "=" + listId, null, null, null, null, null);
- if (mCursor != null) {
- mCursor.moveToFirst();
- }
- return mCursor;
- }
- /* Altele */
- /* For shops */
- public long getId(Cursor c) {
- return (c.getLong(0));
- }
- public String getName(Cursor c) {
- return (c.getString(1));
- }
- public String getAddress(Cursor c) {
- return (c.getString(2));
- }
- public String getType(Cursor c) {
- return (c.getString(3));
- }
- public Double getLatitudine(Cursor c) {
- return (c.getDouble(4));
- }
- public Double getLongitudine(Cursor c) {
- return (c.getDouble(5));
- }
- /* For Lists */
- public String getTitle(Cursor c) {
- return (c.getString(1));
- }
- public String getShop(Cursor c) {
- return (c.getString(2));
- }
- public String getData(Cursor c) {
- return (c.getString(3));
- }
- /* For Budget */
- public String getBudget(Cursor c) {
- return (c.getString(1));
- }
- public String getDataBudget(Cursor c) {
- return (c.getString(2));
- }
- /* incercari */
- public Cursor getAllSearch(String where, String orderBy) {
- StringBuilder buf=new StringBuilder("SELECT _id, Title, Shop , Data , Budget_allocated ," +
- " Budget_spent FROM Lists");
- if (where!=null) {
- buf.append(" WHERE ");
- buf.append(where);
- }
- if (orderBy!=null) {
- buf.append(" ORDER BY ");
- buf.append(orderBy);
- }
- return(mDb.rawQuery(buf.toString(), null));
- }
- public Cursor getAll(){
- return (mDb.rawQuery("SELECT _id, Title, Shop , Data , Budget_allocated ," +
- " Budget_spent FROM Lists ORDER BY Title",null));
- }
- /*public Cursor getListsOrder(String[] columns, String selection,
- String[] selectionArgs, String groupBy, String having,
- String sortBy, String sortOption) {
- return mDb.query(DATABASE_TABLE_1, columns, selection, selectionArgs,
- groupBy, having, sortBy + " " + sortOption);
- }*/
- /*public Cursor getListsOrder() {
- Cursor mCursor = db.query(DATABASE_TABLE_1, new String[] { KEY_ROWID1,
- KEY_TITLE, KEY_SHOP, KEY_DATA, KEY_B_ALLOC, KEY_B_SPENT },
- null, null, null, null,KEY_TITLE + " ASC");
- return mCursor;
- // db.query(table, columns, selection, selectionArgs, groupBy, having,
- // orderBy)
- }*/
- /*public ArrayList<String> getData(String[] keys, String selection,
- String[] selectionArgs, String groupBy, String having,
- String sortBy, String sortOption) {
- ArrayList<String> list = new ArrayList<String>();
- Cursor results = db.getListsOrder(keys, selection, selectionArgs,
- groupBy, having, sortBy, sortOption);
- while (results.moveToNext())
- list.add(results.getString(results.getColumnIndex(sortBy)));
- return list;
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement