Exemple #1
0
  /* Insert new request into table 'request' */
  void insertRequest(int number) {

    // Log.i("PRIME", "Table : request : Inside insertRequest() : No -> "
    //		 										+ number);

    SQLiteDatabase db = this.getWritableDatabase();

    // ??
    String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

    // Log.i("PRIME", "DbHandler : insertRequest() "
    //		 				+ "howmany -> " + number);

    ContentValues values = new ContentValues();
    values.put("howmany", number);
    values.put("current_count", 0);
    values.put("is_complete", "N");
    values.put("created_time", timeStamp);
    values.put("tstamp", timeStamp);

    try {
      // Inserting Row
      db.insertOrThrow(TABLE_REQUEST, null, values);

    } catch (android.database.sqlite.SQLiteConstraintException e) {
      Log.e("PRIME", "insertRequest : SQLiteConstraintException:" + e.getMessage());
    } catch (android.database.sqlite.SQLiteException e) {
      Log.e("PRIME", "SQLiteException:" + e.getMessage());
    } catch (Exception e) {
      Log.e("PRIME", "Exception:" + e.getMessage());
    }

    db.close(); // Closing database connection
  }
Exemple #2
0
  public void insertPrimeNo(int nthNo, int primeNo) {

    // Log.v("PRIME", "Table : prime : Inside insertPrimeNo()");

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put("nthno", nthNo);
    values.put("primeno", primeNo);
    try {
      // Inserting Row
      db.insertOrThrow(TABLE_PRIME, null, values);

    } catch (android.database.sqlite.SQLiteConstraintException e) {
      Log.e("PRIME", "insertPrimeNo() : SQLiteConstraintException:" + e.getMessage());
    } catch (android.database.sqlite.SQLiteException e) {
      Log.e("PRIME", "insertPrimeNo() : SQLiteException:" + e.getMessage());
    } catch (Exception e) {
      Log.e("PRIME", "insertPrimeNo() : Exception:" + e.getMessage());
    }
    db.close(); // Closing database connection
  }
Exemple #3
0
  /**
   * Saves the given task to the database.getDatabase(). Task must already exist. Returns true on
   * success.
   *
   * @param task
   * @return true if save occurred, false otherwise (i.e. nothing changed)
   */
  public boolean save(Task task) {
    boolean saveSuccessful = false;
    if (task.getId() == Task.NO_ID) {
      try {
        saveSuccessful = createNew(task);
      } catch (SQLiteConstraintException e) {
        if (e.getMessage().contains(Task.REMOTE_ID_PROPERTY_NAME)) {
          // Tried to create task with remote id that already exists
          saveSuccessful = false;
          TodorooCursor<Task> cursor =
              query(Query.select(Task.ID).where(Task.REMOTE_ID.eq(task.getValue(Task.REMOTE_ID))));
          if (cursor.getCount() > 0) {
            cursor.moveToFirst();
            task.setId(cursor.get(Task.ID));
            saveSuccessful = saveExisting(task);
          }
        }
      }
    } else {
      saveSuccessful = saveExisting(task);
    }

    return saveSuccessful;
  }