I’m trying to run a statement on sqlite database from android…I wish to return some records from a table which lastChagedDate bigger than the date I give.
Let’s say I have this:
private String ending_date = "2012-01-01 08:24:59";
roadmapSyncStmt = "SELECT * FROM roadmap WHERE lastChangedDate > '"+ ending_date +"'";
The roadmapSyncStmt is the one I will execute on sqlite table full of dates.
The statement will look something like:
SELECT * FROM roadmap WHERE lastChangedDate >"2012-01-01 08:24:59"
And when I run I get this error:
sqlite returned: error code = 1, msg = near “2012”: syntax error
and no data in cursor even though my database contains plenty of data which respects this condition. Does someone know what I do wrong?
You should enclose your date value in single quotes, not double quotes. Like this:
Whilst you are learning, I recommend that you install a PC base SQLite editor, for example “SQLite Database Browser” which you can find on SourceForge. It’s much quicker and easier than testing in your app. I would go so far as to say that all of the DB development, testing, query creation etc should be done on your PC then it’s pretty much a copy/paste exercise to get it into your app.
Good luck.