Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid + SQLite + Query
    text
    copied!<p>I've got two tables</p> <p>Workout Table <br> <p>Workout_ID --------- Workout Name <br> 1 --------------------------- Chest <br> 2 ---------------------------- Back</p> <p>Date of Workouts Table <br> </p> <p>Date_ID------- Date of Workout------ Workout_ID <br> 1-----------------------22/12/13---------------- 1 <br> 2---------------------- 23/12/13---------------- 2</p> <p>Within android, using MySqlite currently: <br> i have these exact tables.</p> <p><br> However when i come to OUTPUT my 'Date of Workouts Table' onto the screen, what MySQLite Code will i need to do so? General points would be really appreciated. </p> <p><br> Somehow i need to take the 'Workout_ID' and compare it to the 'Workout_ID' in the Workout Table and generate 'Chest' and then output that</p> <p><em>EDIT</em> Here i've got my code which Outputs whe Workout_ID which is present in the Date of Workouts Table</p> <pre><code>public String getWorkoutNameInfo() { // TODO Auto-generated method stub String[] columns = new String[] { KEY_DATE_OF_WORKOUT, KEY_WORKOUT_NAME, KEY_DATE }; Cursor c = ourDatabase.query(TABLE_DATE_WORKOUT, columns, null, null, null, null, null, null); String workoutName2 = ""; int iWorkoutID = c.getColumnIndex(KEY_WORKOUT_NAME); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { workoutName2 = workoutName2 + c.getString(iWorkoutID); } System.out.println(workoutName2); return workoutName2; } </code></pre> <p>HERE I'm trying to query my WorkoutTable WHERE my workout_id is equal to the workoutSlectedNameInfo <br> So i'm trying to go down the list of Workout_ID in my 'Date of Workouts Table' and compare the 1 and 2 to the Workout Table - This doesn't work - Will this Join statement allow me to do this?</p> <p>public String test(String workoutSelectedNameInfo) {</p> <pre><code> // TODO Auto-generated method stub String Weight = ""; open(); ourDatabase = ourhelper.getReadableDatabase(); Cursor c = ourDatabase .rawQuery( "SELECT workout_name FROM WorkoutTable WHERE workout_id = ?", new String[] { workoutSelectedNameInfo }); int iWeight = c.getColumnIndex(KEY_WORKOUT_NAME); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { Weight = Weight + c.getString(iWeight) + "\n"; } c.close(); ourDatabase.close(); return Weight; // TODO Auto-generated method stub } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload