Now I am trying to work with databases. It's still iPad 4.2 and Ti SDK 1.6.0. I am using Database.install and my application just quits on start. At first I couldn't see any error messages but then I found where the log file was. So it sais database file can not be found. I looked up the path and noticed that install actually copied the database file but the path is wrong. The path goes only to the folder name where the database file is. The file name itself is missing in the path. Like so:
path: "/Users/mindvitaminsab/Library/Application Support/iPhone Simulator/4.2/Applications/C9905AF4-821C-4CEE-A657-B9B38B5DA0E4/Library/Application Support/database/abc.sqlite.sql"
file: "/Users/mindvitaminsab/Library/Application Support/iPhone Simulator/4.2/Applications/C9905AF4-821C-4CEE-A657-B9B38B5DA0E4/Library/Application Support/database/abc.sqlite.sql/abc.sqlite"
And here's the line of code:
var db = Ti.Database.install('db', 'abc.sqlite');So the question is: am I doing something wrong?
Thanks in advance
P.S. Another interesting detail is I change the copied file name to abc.sqlite.sql and remove the folder with the same name. Then I can use
var db = Ti.Database.open('abc.sqlite');Now I have access to my database.
I think you have the arguments reversed in your original line of code:
var db = Ti.Database.install('db', 'abc.sqlite');
This tells it to look to see if you have previously opened a database called abc.sqlite and if so, just open it again and ignore anything in the Resources folder. If you have not previously opened abc.sqlite, then it looks in the Resources folder for a file called 'db' (without extension) and copies it to the application's database folder and calls it 'abc.sqlite'
If 'abc.sqlite' is a file in your Resources folder, then you could do:
var db = Ti.Database.install('abc.sqlite', 'db');
Which would attempt to (re)open a database called "db" but when there is not yet, look in Resources for a file called 'abc.sqlite' for the initial copy. More typical usage would be:
var db = Ti.Database.install('abc.sqlite', 'abc');
But the name (db vs abc) doesn't really matter if you always use the same .install() values to open the database. However if you later close the database and want to reopen in your code you would either need to use the same .install() values or use .open() with the name in the second argument of the first .install() that was executed.
Think you can help? Login to answer this question!