コード例 #1
0
  /** getting all todos under single tag */
  public List<Todo> getAllToDosByTag(String tag_name) {
    List<Todo> todos = new ArrayList<Todo>();

    String selectQuery =
        "SELECT  * FROM "
            + TABLE_TODO
            + " td, "
            + TABLE_TAG
            + " tg, "
            + TABLE_TODO_TAG
            + " tt WHERE tg."
            + KEY_TAG_NAME
            + " = '"
            + tag_name
            + "'"
            + " AND tg."
            + KEY_ID
            + " = "
            + "tt."
            + KEY_TAG_ID
            + " AND td."
            + KEY_ID
            + " = "
            + "tt."
            + KEY_TODO_ID;

    Log.e(LOG, selectQuery);

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (c.moveToFirst()) {
      do {
        Todo td = new Todo();
        td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
        td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
        td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));

        // adding to todo list
        todos.add(td);
      } while (c.moveToNext());
    }

    return todos;
  }
コード例 #2
0
  /*
   * get single todo
   */
  public Todo getTodo(long todo_id) {
    SQLiteDatabase db = this.getReadableDatabase();

    String selectQuery = "SELECT  * FROM " + TABLE_TODO + " WHERE " + KEY_ID + " = " + todo_id;

    Log.e(LOG, selectQuery);

    Cursor c = db.rawQuery(selectQuery, null);

    if (c != null) c.moveToFirst();

    Todo td = new Todo();
    td.setId(c.getInt(c.getColumnIndex(KEY_ID)));
    td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
    td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));

    return td;
  }
コード例 #3
0
  /** getting all todos */
  public List<Todo> getAllToDos() {
    List<Todo> todos = new ArrayList<Todo>();
    String selectQuery = "SELECT  * FROM " + TABLE_TODO;

    Log.e(LOG, selectQuery);

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (c.moveToFirst()) {
      do {
        Todo td = new Todo();
        td.setId(c.getInt((c.getColumnIndex(KEY_ID))));
        td.setNote((c.getString(c.getColumnIndex(KEY_TODO))));
        td.setCreatedAt(c.getString(c.getColumnIndex(KEY_CREATED_AT)));

        // adding to todo list
        todos.add(td);
      } while (c.moveToNext());
    }

    return todos;
  }