0

As the title says I am having a little trouble with a query on an sqlite database.Basically, what I am trying to do is retrieve a bunch of quotes from the database, depending on the author chosen from user in a list.

But there is a problem with my SELECT statement(it seems..), and I can't seem to spot it, so if any of you good folk could lend a pair of eyes I would really appreciate it.

My query:

public Cursor getQuotes(int position){

    String who = authorName[position];

    return qmDB.query(QUOTES_TABLE, new String[]{
            KEY_QUOTE
            },
            KEY_AUTHNAME + "=" + who,
            null,
            null,
            null,
            null);
}

Error:

04-28 20:05:10.685: ERROR/AndroidRuntime(25017): Caused by: android.database.sqlite.SQLiteException: near "Anton": syntax error: , while compiling: SELECT quote FROM Quotes WHERE auth_name=Robert Anton Wilson

1 Answer 1

1

You need single quotes around your "who" string.

Sign up to request clarification or add additional context in comments.

1 Comment

However, a better way would be to use as third and fourth parameters: ... KEY_AUTHNAME + "=?", new String[] {who}, ...

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.