Hi I am developing an application in titanium. I am trying attach the existing database to the new database Here is my code:
var win1 = Titanium.UI.createWindow({
backgroundColor : '#fff'
});
var scrollView = Titanium.UI.createScrollView({});
var lblid = Titanium.UI.createLabel({ color : "black" });
var lblname = Titanium.UI.createLabel({ color : "black" });
var lbldesg = Titanium.UI.createLabel({ color : "black" });
var lblsalary = Titanium.UI.createLabel({ color : "black" });
scrollView.add(lblid);
scrollView.add(lblname);
scrollView.add(lbldesg);
scrollView.add(lblsalary);
win1.add(scrollView);
win1.open();
var undb = Ti.Database.open('UnencryptedDB.db');
var endb = Ti.Database.open('Encrypted.db');
var dbFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "UnencryptedDB.db");
alert('The path of the database is '+dbFile.getNativePath());
endb.execute("CREATE TABLE if not exists city (city_id integer PRIMARY KEY ,country_id integer NOT NULL ,city text,latitude real,longitude real)");
endb.execute("ATTACH DATABASE \'"+ dbFile.getNativePath() +"\' as DB1 ");
endb.execute("insert into city select * from DB1.city");
endb.close();
here UnencryptedDB.db is the existing database which is project/Resources folder and Encrypted.db is the new database.
While executing this code I am getting an error like Unable to open the database. Got the error at
"endb.execute("ATTACH DATABASE \'"+ dbFile.getNativePath() +"\' as DB1 ");"
this line. Can anyone tel me why I got this error. Where I went wrong in the code.
Your Answer
Think you can help? Login to answer this question!