private void openDB() {
    myHelper = new MyDataBaseHelper(context);
    try {
      myHelper.createDataBase();
    } catch (IOException ioe) {
      throw new Error("Unable to create database");
    }

    try {
      myHelper.openDataBase(false);
    } catch (SQLException sqle) {
      throw new Error("sqlite");
    }
  }
Beispiel #2
0
  public String addToDB(Context context) {
    ContentValues values = new ContentValues();
    openDB(context, true);
    if (this.getFkExercises().compareTo(-1) != 0)
      values.put(EXERCISE_COLUMN_FKEXERCISE, this.getFkExercises());
    if (this.getFkBody().compareTo(-1) != 0) values.put(EXERCISE_COLUMN_FKBODY, this.getFkBody());
    values.put(EXERCISE_COLUMN_VALUES, this.getValue());
    if (this.getSets().compareTo(-1) != 0) values.put(EXERCISE_COLUMN_SETS, this.getSets());
    if (this.getIterations().compareTo(-1) != 0)
      values.put(EXERCISE_COLUMN_ITERATION, this.getIterations());

    myHelper.writeData(values, "t_history");

    myHelper.close();
    return null;
  }
 /**
  * The constructor takes context and dataSelect to get the required data of the database
  *
  * @param context takes context
  * @param dataSelect takes String
  */
 public StatsExerciseMeasurementTable(Context context, String dataSelect) {
   this.context = context;
   openDB();
   cursor =
       myHelper.getData(
           "SELECT _ID,FK_Exercise,Value,Iterations,Sets,Date,round((julianday(Date) - julianday('now') ),0)as dateDayDiff FROM t_history where FK_Exercise=(SELECT _ID from t_exercises where name='"
               + dataSelect
               + "') group by date,FK_Exercise ORDER BY DATE(Date) ASC");
   if (cursor.moveToFirst()) {
     do {
       exerciseWeightList.add(cursor.getDouble(cursor.getColumnIndex("Value")));
       exerciseRepetitionesList.add(cursor.getDouble(cursor.getColumnIndex("Iterations")));
       exerciseSets.add(cursor.getDouble(cursor.getColumnIndex("Sets")));
       dateAsString.add(cursor.getString(cursor.getColumnIndex("Date")));
       dateDayDiff.add(cursor.getDouble(cursor.getColumnIndex("dateDayDiff")));
     } while (cursor.moveToNext());
   }
   cursor.close();
   myHelper.close();
 }
Beispiel #4
0
 public History(Exercise ex, Context context) {
   this.exercise = ex;
   this.fkExercises = ex.getId();
   openDB(context, false);
   try {
     Cursor c =
         myHelper.getData(
             "select * from 't_history' where _id=(select max(_id) from 't_history' where FK_Exercise='"
                 + String.valueOf(this.fkExercises)
                 + "')");
     c.moveToFirst();
     this.value = c.isNull(c.getColumnIndex("Value")) ? 0 : c.getFloat(c.getColumnIndex("Value"));
     this.sets = c.isNull(c.getColumnIndex("Sets")) ? 0 : c.getInt(c.getColumnIndex("Sets"));
     this.iterations =
         c.isNull(c.getColumnIndex("Iterations")) ? 0 : c.getInt(c.getColumnIndex("Iterations"));
     c.close();
   } catch (CursorIndexOutOfBoundsException n) {
     this.value = 0;
     this.sets = 0;
     this.iterations = 0;
   } finally {
     myHelper.close();
   }
 }