1

I need to get the values of children column corresponding to key column as in the image. What would be the select statement for it in android sqlite.

Thanks

enter image description here

I am using following code for it:

 public Cursor fetchChildren(String KEY_){
            Cursor c = db.rawQuery("SELECT children FROM " + DATABASE_TABLE_NAVIGATION
                    + " WHERE key =" + KEY_+ "", null);
                       return c;

But it is giving me exception:

android.database.sqlite.SQLiteException: no such column: home: , while compiling: SELECT children FROM navigation WHERE key =home

           }
3
  • I don't know whether it is so simple or just something else then i understand your question as.Can not you use simple query method of SQLiteDatabase for fetching this column's value? Commented Nov 11, 2011 at 11:34
  • Yes i am already using that but givin g me following exception: android.database.sqlite.SQLiteException: no such column: home: , while compiling: SELECT children FROM navigation WHERE key =home Commented Nov 11, 2011 at 11:38
  • try to use key='home' or key like 'home' Commented Nov 11, 2011 at 11:53

2 Answers 2

6

As Andrey says, you need quotes around the key.

But it's better still to pass the key in separately as an argument to the query, rather than directly including it in the query. This allows SQLite to reuse the same cached query for every different key you might pass in, making it much more efficient.

public Cursor fetchChildren(String KEY_){
    Cursor c = db.rawQuery("SELECT children FROM " + DATABASE_TABLE_NAVIGATION
                           + " WHERE key = ?", new String[] {KEY_});
    return c;
}
Sign up to request clarification or add additional context in comments.

Comments

3

I suspect you just missed quotes

SELECT children FROM navigation WHERE key='home'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.