Error regarding attaching the database

You must Login before you can answer or comment on any questions.

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.

— asked 9 months ago by Prasad M.R.C
2 Comments
  • Personally I download the encrypted database fully formed from the server, there's no need to merge one to the other.. Seems a strange use case this..

    — commented 9 months ago by Mark Henderson

  • Hi Mark,

    First I am trying to attach the existing database to the new database. If I am able to do that I will attach the existing database to a new database and at the same time I can encrypt the new database using dmarie.sql plugin. I tried to open the database which is already encrypted. But I am not able to open it. Thats why I am trying to attach the database to another database.

    — commented 9 months ago by Prasad M.R.C

Your Answer

Think you can help? Login to answer this question!