1

I don't understand why my query does not work in Java (android). I would like access to a sqlite databse but I think the problem is about the "WHERE" clause.

Cursor cQuery = db.query("PLUGBATTERY", new String[] {
                        "strftime('%s',date)", "code", "state","startup" }, "strftime('%Y-%m-%d',date)=="+DATE_FORMAT_DATE.format(currentC.getTime()), null, null,null, "strftime('%s',date)");

in the debug view I have DATE_FORMAT_DATE.format(currentC.getTime()) = 2013-08-22

Maybe I can test my query out of my application code but I don't know how to do that...

Thanks for your help.

1 Answer 1

3

In SQL, strings must be written 'with quotes'.

You can avoid formatting problems like this (and SQL injection attacks) by using parameters:

cursor = db.query("PLUGBATTERY",
                  new String[] { "strftime('%s',date)", "code", "state","startup" },
                  "date(date) = ?",
                  new String[] { DATE_FORMAT_DATE.format(currentC.getTime()) },
                  null, null, "date");
Sign up to request clarification or add additional context in comments.

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.