Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.92 KB | None | 0 0
  1. public ItemProduct getProductById(int idProduct, DataBaseHandler dh) {
  2.         ItemProduct itemProduct = new ItemProduct();
  3.         String selectQuery = "SELECT S." + DataBaseHandler.KEY_STORE_ID + ","
  4.                 + "S." + DataBaseHandler.KEY_STORE_LAT + ","
  5.                 + "S." + DataBaseHandler.KEY_STORE_LNG + ","
  6.                 + "S." + DataBaseHandler.KEY_STORE_NAME + ","
  7.                 + "S." + DataBaseHandler.KEY_STORE_PHONE + ","
  8.                 + "S." + DataBaseHandler.KEY_STORE_THUMBNAIL + ","
  9.                 + "C." + DataBaseHandler.KEY_CITY_ID + ","
  10.                 + "C." + DataBaseHandler.KEY_CITY_NAME + ","
  11.                 + "CA." + DataBaseHandler.KEY_CATEGORY_ID + ","
  12.                 + "CA." + DataBaseHandler.KEY_CATEGORY_NAME + ","
  13.                 + "P." + DataBaseHandler.KEY_PRODUCT_IMAGE + ","
  14.                 + "P." + DataBaseHandler.KEY_PRODUCT_ID + ","
  15.                 + "P." + DataBaseHandler.KEY_PRODUCT_DESCRIPTION + ","
  16.                 + "P." + DataBaseHandler.KEY_PRODUCT_TITLE + " FROM "
  17.                 + DataBaseHandler.TABLE_STORE + " S, "
  18.                 + DataBaseHandler.TABLE_CITY + " C, "
  19.                 + DataBaseHandler.TABLE_CATEGORY + " CA, "
  20.                 + DataBaseHandler.TABLE_PRODUCT + " P WHERE P."
  21.                 + DataBaseHandler.KEY_PRODUCT_ID + " = " + idProduct
  22.                 + " AND P." + DataBaseHandler.KEY_PRODUCT_STORE
  23.                 + " = S." + DataBaseHandler.KEY_STORE_ID
  24.                 + " AND P." + DataBaseHandler.KEY_PRODUCT_CATEGORY
  25.                 + " = CA." + DataBaseHandler.KEY_CATEGORY_ID
  26.                 + " AND S." + DataBaseHandler.KEY_STORE_CITY
  27.                 + " = C." + DataBaseHandler.KEY_CITY_ID;
  28.  
  29.  
  30.         SQLiteDatabase db = dh.getReadableDatabase();
  31.         Cursor cursor = db.rawQuery(selectQuery, null);
  32.         if (cursor.moveToFirst()) {
  33.             Store store = new Store();
  34.             store.setId(cursor.getInt(0));
  35.             store.setLatitude(cursor.getDouble(1));
  36.             store.setLongitude(cursor.getDouble(2));
  37.             store.setName(cursor.getString(3));
  38.             store.setPhone(cursor.getString(4));
  39.             store.setThumbnail(cursor.getInt(5));
  40.  
  41.             City city = new City();
  42.             city.setIdCity(cursor.getInt(6));
  43.             city.setName(cursor.getString(7));
  44.  
  45.             Category category = new Category();
  46.             category.setIdCategory(cursor.getInt(8));
  47.             category.setName(cursor.getString(9));
  48.  
  49.             itemProduct.setImage(cursor.getInt(10));
  50.             itemProduct.setCode(cursor.getInt(11));
  51.             itemProduct.setDescription(cursor.getString(12));
  52.             itemProduct.setTitle(cursor.getString(13));
  53.             itemProduct.setCategory(category);
  54.             itemProduct.setStore(store);
  55.         }
  56.         try {
  57.             cursor.close();
  58.             db.close();
  59.         } catch (Exception e) {
  60.         }
  61.  
  62.         return itemProduct;
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement