Hi all,
I have an app that is trying to pull data from a local database. I've connected to the database and can pull data when the SQL query is based on the primary key but I've been trying to run the same query on a different integer column and it incorrectly returns 0 rows. I've tested the SQL statement elsewhere and it returns the data fine, just not inside the app. Also I've tried querying the database on another column that is based on a string and that works too.
Example of code that doesn't work:
var rows = db.execute('SELECT * FROM Event WHERE track_id="1"');But this code does work:
var rows = db.execute('SELECT * FROM Event WHERE event_id="1"');I've checked the spellings of the column names and everything but it still doesn't work. Anyone else encountered the same problem?
Thanks
3 Answers
Accepted Answer
Andy, Here's a few crazy things to remember when using SQLite in Titanium. You might already know them but can't hurt to mention them anyway.
Firstly, when working on the device or in the simulator, you have to reset it to see any changes in the database. In the simulator goto File > Reset Contents and Settings and reload your app. It may help.
Secondly, simplify your tests, use this code just to see if you get a result
var rows = db.execute('SELECT * FROM Event');I like to test for everything just to se if there is a result. Then you know you are at least returning something from the database.
These two handy hints always help me when I'm getting frustrated. Hope they help you. Wayne
Andy
It doesn't work because you are not using execute() correctly. You should be using string substitution. See Storing data for examples.
Cheers
I have never had trouble with any selects. You mentioned the the column which is failing is an integer column, so try this instead:
var rows = db.execute('SELECT * FROM Event WHERE event_id=1');
Your Answer
Think you can help? Login to answer this question!