Пример #1
0
  public List<Category> getAllUserCategories() throws ParseException {
    System.out.println("**********getAllUserCategories************");
    List<Category> usercategories = new ArrayList<Category>();

    Cursor cursor =
        database.query(
            MySQLiteHelper.TABLE_USERS_CATEGORY,
            allUserCategoryColumns,
            null,
            null,
            null,
            null,
            null);

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
      Category category = cursorToUserCategory(cursor);

      System.out.println("CATEGORYID----->" + category.getCategoryId());
      usercategories.add(category);
      cursor.moveToNext();
    }
    // make sure to close the cursor
    cursor.close();
    return usercategories;
  }
Пример #2
0
  /**
   * create table category(categoryId INTEGER primary key autoincrement,categorytext TEXT,
   * fk_category_receiptinfo INTEGER,FOREIGN KEY(fk_category_receiptinfo) REFERENCES
   * receiptinfo(receiptId));
   */
  public Category addCategory(String categorytext, long receiptId) {
    Log.v("MyQuittiDataSource", "--addCategory--");

    ContentValues categoryValues = new ContentValues();
    categoryValues.put(MySQLiteHelper.COLUMN_CATEGORYTEXT, categorytext);
    categoryValues.put(MySQLiteHelper.COLUMN_CATEGORYRECEIPTID, receiptId);

    long insertId = database.insert(MySQLiteHelper.TABLE_CATEGORY, null, categoryValues);
    System.out.println("################addCategory#######################");

    Cursor cursor =
        database.query(
            MySQLiteHelper.TABLE_CATEGORY,
            allCategoryColumns,
            MySQLiteHelper.COLUMN_CATEGORYID + " = " + insertId,
            null,
            null,
            null,
            null);
    cursor.moveToFirst();
    Category category = cursorToCategory(cursor);
    cursor.close();
    Log.v("MyQuittiDataSource", "--addCategory--END---->ID: " + category.getCategoryId());
    return category;
  }
Пример #3
0
 private Category cursorToUserCategory(Cursor cursor) {
   System.out.println(
       "*******************cursorToUserCategory************************KOLUMNEJA"
           + cursor.getColumnCount());
   // Log.d("cursorToCategory", "cursor.getLong(0) ID..>" +cursor.getLong(0) +" CATEGORYTEXT: " +
   // cursor.getString(1) + " cursor.getLong(2) RECEIPTID---> " +cursor.getLong(2));
   Category newCategory = new Category();
   newCategory.setCategoryId(cursor.getLong(0));
   newCategory.setCategoryText(cursor.getString(1));
   System.out.println("CATEGORY: " + newCategory.getCategoryText());
   System.out.println("newCategory in cursorToCategory---->" + newCategory);
   return newCategory;
 }