samedi 11 avril 2015

Database inner join QUERY cursor problems SQLite

Table User: userid, username, password, age, email, gender, height, weight, bmi, bmr


Table Calorie Intake: userid, (DATE)intakedate, intakeday, calories;


Im trying to Select Calories from table user INNER JOIN table Cal In ON user. uid == Cal.userid, where userid =? and current date =?


Here is the Query:



public CalorieIntake getuserIntake(int id, Date currentdate) {
CalorieIntake calorieIntake = null;
SQLiteDatabase db = getReadableDatabase();
final String UserintQuery = "SELECT " + KEY_CALORIES + " FROM "
+ TABLE_CALORIE_INTAKE + " c " + " INNER JOIN " + TABLE_USERS + " u " +
"ON" + " c." + KEY_USER_ID + " = u." + KEY_U_ID + " WHERE u." + KEY_U_ID + " =? AND " + KEY_INTAKE_DATE + " =?";
Cursor cursor;
cursor = db.rawQuery(UserintQuery, new String[]{String.valueOf(id), currentdate});

if (cursor.getCount() < 0) {
cursor.moveToFirst();
assert cursor != null;
calorieIntake = new CalorieIntake(cursor.getInt(0),cursor.getDate??,
cursor.getString(2),
cursor.getDouble(3));


}
cursor.close();
return calorieIntake;
}


i put two ?? beside cursor.getDate to highlight it as I cant find a way to retrieve the Type Date.


Aucun commentaire:

Enregistrer un commentaire