UPDATE on SQLite Cause Crash please take a look.
Trying to update database from a textfield when you hit return and my app crashes because of it. here is the code.
textField.addEventListener('return',function(e)
{
dataBase.execute('UPDATE interests SET title= '+textField.value+'WHERE id='+id);
});
Thanks for your help!
3 Answers
-
Accepted Answer
You aren't properly quoting the text in the SQL statement. By way of example, if the text field had the value
my sample text
the SQL would end up:UPDATE interests SET title= my sample text WHERE id=...
As you can see, that would be invalid SQL syntax. So just try:
textField.addEventListener('return',function(e) { dataBase.execute('UPDATE interests SET title= "'+textField.value+'" WHERE id='+id); });
This ignores the potential for the user to mess up the SQL by actually keying a double quote in the field (for example: He is 6' 5" tall). Because of that, and to avoid the possibility of a SQL injection attempt, you should really use substitution variables in update statements:
textField.addEventListener('return',function(e) { dataBase.execute('UPDATE interests SET title= ? WHERE id='+id, textField.value); });
-
Thank you very much Dough. Unfortunately it did not work. The app still crashes in the simulator even with the changes you suggested.
I am a newbie at appcelerator but I see a message in the console saying:
[ERROR] Syntax Error = Parse error at interests.js (line 40) Terminating in response to SpringBoard's termination. ~
That might be the reason. Although I can't seem to find the issue at line 40 even if I comment the line out it still gives me the same error.
-
If you think something in the build is corrupted, just do a menu Project > Clean from Ti Studio. Then build it again. If the problem persists at runtime, place breakpoints shortly before the last activity you can see happening then start stepping through the code.