views:

74

answers:

1

I would like to limit the results to those whose KEY_HOMEID is equal to journalId. I've been on this for a couple days any help would be appreciated.

public Cursor fetchAllNotes(String journalId) { return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_HEIGHT, KEY_BODY, KEY_HOMEID},"FROM DATABASE_TABLE WHERE KEY_HOMEID = journalId",null, null, null, null,null); }

+3  A: 

Have a look at http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#query

Your query should look a little like this:

mDb.query(DATABASE_TABLE, // Table name
          columnNames, // String[] containing your column names
          KEY_HOMEID+" = "+jounalId, // your where statement, you do not include the WHERE or the FROM DATABASE_TABLE parts of the query,
          null,
          null,
          null,
          null
         );

If you feel more comfortable writing sql queries you can also use:

mDb.rawQuery("SQL STATEMENT", null);
disretrospect
Thanks. Works. I didnt realize that SQL statment could only be used in rawQUery.
Brian
See also my answer on your earlier (pretty much identical) question :)http://stackoverflow.com/questions/3269863/sqlite-and-android-how-do-i-use-string-having-in-my-query/3271769#3271769
Christopher