public ReceiptImage getReceiptWithPhotoname(String photoname) throws ParseException { Log.d("MyQuittiDatasource", "getReceiptWithPhotoname: " + photoname); ReceiptImage receipt = null; this.open(); Log.d("MyQuittiDatasource", "photoname: " + photoname); Cursor cursor = database.rawQuery("SELECT * FROM receiptinfo WHERE photoname = '" + photoname + "'", null); // Cursor cursor = database.query(MySQLiteHelper.TABLE_RECEIPTINFO, // allColumns, MySQLiteHelper.COLUMN_PHOTONAME + " LIKE " + photoname, null, null, null, // null); cursor.moveToFirst(); // Comment newComment = cursorToComment(cursor); // cursor.close(); if (cursor.getCount() > 0) { receipt = cursorToReceiptImage(cursor); receipt.setCategory(getCategory(receipt.getReceiptId())); } System.out.println("*********************"); // cursor.moveToNext(); // make sure to close the cursor cursor.close(); // and database connection this.close(); Log.d("MyQuittiDatasource", "getReceiptWithPhotoname End"); return receipt; }
/** * Returns a list of all receipts in phones memory with specific category SELECT * receiptinfo.receiptId, receiptinfo.photoname,category.categorytext FROM receiptinfo,category * WHERE receiptinfo.receiptid=category.fk_category_receiptinfo and category.categorytext like * 'Business' @Sami Nurmi * * @return List * @throws ParseException */ public List<ReceiptImage> getAllReceipts(String category) throws ParseException { List<ReceiptImage> receipts = new ArrayList<ReceiptImage>(); Cursor cursor = database.query(MySQLiteHelper.TABLE_RECEIPTINFO, allColumns, null, null, null, null, null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { ReceiptImage receipt = cursorToReceiptImage(cursor); receipt.setCategory(getCategory(receipt.getReceiptId())); receipts.add(receipt); cursor.moveToNext(); } // make sure to close the cursor cursor.close(); return receipts; }