コード例 #1
0
ファイル: SQLHelper.java プロジェクト: rankush/Headout
  public List<EventInfoBean> getAllEvents() {
    SQLiteDatabase db = this.getReadableDatabase();
    List<EventInfoBean> eventList = new ArrayList<EventInfoBean>();
    try {

      Cursor cursor = db.query(EVENT_TABLE_NAME, null, null, null, null, null, null);
      if (cursor != null && cursor.moveToFirst()) {
        do {
          EventInfoBean event =
              new EventInfoBean(
                  cursor.getInt(cursor.getColumnIndex(COL_EVENT_START_TIME)),
                  cursor.getInt(cursor.getColumnIndex(COL_EVENT_END_TIME)),
                  cursor.getString(cursor.getColumnIndex(COL_EVENT_CREATOR_ID)),
                  cursor.getString(cursor.getColumnIndex(COL_EVENT_NAME)),
                  cursor.getString(cursor.getColumnIndex(COL_EVENT_DESCRIPTION)));
          event.setEventStatus(cursor.getInt(cursor.getColumnIndex(COL_EVENT_STATUS)));

          eventList.add(event);
        } while (cursor.moveToNext());
      }
    } catch (SQLiteException se) {
      Log.v(TAG, Log.getStackTraceString(se));
    } catch (Exception e) {
      Log.v(TAG, Log.getStackTraceString(e));
    } finally {
      db.close();
    }

    return eventList;
  }
コード例 #2
0
ファイル: SQLHelper.java プロジェクト: rankush/Headout
  public List<EventInfoBean> getEventsAttendingByUser(String user) {
    SQLiteDatabase db = this.getReadableDatabase();
    List<EventInfoBean> eventList = new ArrayList<EventInfoBean>();
    try {

      String query =
          "SELECT * FROM "
              + EVENT_TABLE_NAME
              + " WHERE "
              + COL_EVENT_ID
              + " IN ( "
              + "SELECT DISTINCT "
              + COL_EVENT_ID
              + " FROM "
              + EVENT_ATTENDEES_TABLE_NAME
              + "WHERE "
              + COL_USER_ID
              + " = "
              + user
              + " )";

      Cursor cursor = db.rawQuery(query, null);
      if (cursor != null && cursor.moveToFirst()) {
        do {
          EventInfoBean event =
              new EventInfoBean(
                  cursor.getInt(cursor.getColumnIndex(COL_EVENT_START_TIME)),
                  cursor.getInt(cursor.getColumnIndex(COL_EVENT_END_TIME)),
                  cursor.getString(cursor.getColumnIndex(COL_EVENT_CREATOR_ID)),
                  cursor.getString(cursor.getColumnIndex(COL_EVENT_NAME)),
                  cursor.getString(cursor.getColumnIndex(COL_EVENT_DESCRIPTION)));
          event.setEventStatus(cursor.getInt(cursor.getColumnIndex(COL_EVENT_STATUS)));

          eventList.add(event);
        } while (cursor.moveToNext());
      }
    } catch (SQLiteException se) {
      Log.v(TAG, Log.getStackTraceString(se));
    } catch (Exception e) {
      Log.v(TAG, Log.getStackTraceString(e));
    } finally {
      db.close();
    }

    return eventList;
  }
コード例 #3
0
ファイル: SQLHelper.java プロジェクト: rankush/Headout
  public long insertEvent(EventInfoBean event) {
    SQLiteDatabase db = this.getWritableDatabase();
    try {
      ContentValues values = new ContentValues();
      values.put(COL_EVENT_START_TIME, event.getEventStartTime());
      values.put(COL_EVENT_END_TIME, event.getEventEndTime());
      values.put(COL_EVENT_CREATOR_ID, event.getEventCreatorId());
      values.put(COL_EVENT_NAME, event.getEventName());
      values.put(COL_EVENT_DESCRIPTION, event.getEventDesc());
      values.put(COL_EVENT_STATUS, event.getEventStatus());
      long rowID = db.insert(EVENT_TABLE_NAME, null, values);
      db.close();

      return rowID;
    } catch (SQLiteException se) {
      Log.e(TAG, Log.getStackTraceString(se));
      return -1;
    } catch (Exception e) {
      Log.v(TAG, Log.getStackTraceString(e));
      return -1;
    } finally {
      db.close();
    }
  }