Hello,
I have an application that reads data from a file and stores them into a database. But I need to store the data only once, so if I close the app and open it again, the same values should not be inserted again.
Is there a way to create a flag or mark the database and check if there are already tables inside?
Best Regards, Martin
2 Answers
Accepted Answer
Check out this: http://docs.appcelerator.com/titanium/2.1/index.html#!/api/Titanium.App.Properties
You can use those properties because they are permanent storage. Store flag there and when you app lunches, check for that flag.
Hello Martin,
first you have to set primary key of any common field....
after set primary key write code like this....
var btn = Ti.UI.createButton({ title : 'Add', height : 35, width : 140, }); win.add(btn); btn.addEventListener('click', function(e) { try { var myDB = Ti.Database.open("films"); var sql = 'INSERT INTO table (title,filmYear) VALUES ("' + 'DDL' + '","' + '1995' + '")'; Ti.API.info('SQL => ' + sql); myDB.execute(sql); myDB.close(); alert('Your film was added to your table.') } catch(e) { alert('This Film is already in table'); } });
Your Answer
Think you can help? Login to answer this question!