Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ItemProduct getProductById(int idProduct, DataBaseHandler dh) {
- ItemProduct itemProduct = new ItemProduct();
- String selectQuery = "SELECT S." + DataBaseHandler.KEY_STORE_ID + ","
- + "S." + DataBaseHandler.KEY_STORE_LAT + ","
- + "S." + DataBaseHandler.KEY_STORE_LNG + ","
- + "S." + DataBaseHandler.KEY_STORE_NAME + ","
- + "S." + DataBaseHandler.KEY_STORE_PHONE + ","
- + "S." + DataBaseHandler.KEY_STORE_THUMBNAIL + ","
- + "C." + DataBaseHandler.KEY_CITY_ID + ","
- + "C." + DataBaseHandler.KEY_CITY_NAME + ","
- + "CA." + DataBaseHandler.KEY_CATEGORY_ID + ","
- + "CA." + DataBaseHandler.KEY_CATEGORY_NAME + ","
- + "P." + DataBaseHandler.KEY_PRODUCT_IMAGE + ","
- + "P." + DataBaseHandler.KEY_PRODUCT_ID + ","
- + "P." + DataBaseHandler.KEY_PRODUCT_DESCRIPTION + ","
- + "P." + DataBaseHandler.KEY_PRODUCT_TITLE + " FROM "
- + DataBaseHandler.TABLE_STORE + " S, "
- + DataBaseHandler.TABLE_CITY + " C, "
- + DataBaseHandler.TABLE_CATEGORY + " CA, "
- + DataBaseHandler.TABLE_PRODUCT + " P WHERE P."
- + DataBaseHandler.KEY_PRODUCT_ID + " = " + idProduct
- + " AND P." + DataBaseHandler.KEY_PRODUCT_STORE
- + " = S." + DataBaseHandler.KEY_STORE_ID
- + " AND P." + DataBaseHandler.KEY_PRODUCT_CATEGORY
- + " = CA." + DataBaseHandler.KEY_CATEGORY_ID
- + " AND S." + DataBaseHandler.KEY_STORE_CITY
- + " = C." + DataBaseHandler.KEY_CITY_ID;
- SQLiteDatabase db = dh.getReadableDatabase();
- Cursor cursor = db.rawQuery(selectQuery, null);
- if (cursor.moveToFirst()) {
- Store store = new Store();
- store.setId(cursor.getInt(0));
- store.setLatitude(cursor.getDouble(1));
- store.setLongitude(cursor.getDouble(2));
- store.setName(cursor.getString(3));
- store.setPhone(cursor.getString(4));
- store.setThumbnail(cursor.getInt(5));
- City city = new City();
- city.setIdCity(cursor.getInt(6));
- city.setName(cursor.getString(7));
- Category category = new Category();
- category.setIdCategory(cursor.getInt(8));
- category.setName(cursor.getString(9));
- itemProduct.setImage(cursor.getInt(10));
- itemProduct.setCode(cursor.getInt(11));
- itemProduct.setDescription(cursor.getString(12));
- itemProduct.setTitle(cursor.getString(13));
- itemProduct.setCategory(category);
- itemProduct.setStore(store);
- }
- try {
- cursor.close();
- db.close();
- } catch (Exception e) {
- }
- return itemProduct;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement