Database crash - can't close

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

I have a list that I am populating from a database. I am following the example found in the persistence app. This is the code:

var db = Titanium.Database.open('MyTable');
db.execute('CREATE TABLE IF NOT EXISTS labels (id INTEGER PRIMARY KEY, label TEXT)');
 
 
//Code that populates database if it doesn't exist
 
var dbData = db.execute('SELECT * FROM labels');
 
for(i=0;i<dbData.rowCount;i++){
    labels.push(dbData.fieldByName('label'));
    Ti.API.info(dbData.fieldByName('label'));
    dbData.next();
}
dbData.close();
Everything works fine until I quit the application when I get the following stack trace saying that the db cannot be closed because implementations have leaked prepared statements.

If I add db.close(); to the code the same error is thrown.

I tried looking at different questions but I can't figure this out.

Any help is appreciated.

1 Answer

I would close the db after populating the data, and define db again to open the database before select, then close it again.

— answered 3 years ago by Daniel Lim
answer permalink
7 Comments
  • If I do that, I get the same error 'leaked prepared statements'. I don't understand

    — commented 3 years ago by Abraham Vivas

  • BTW I am using Titanium Mobile SDK 1.3.3

    — commented 3 years ago by Abraham Vivas

  • I don't know what you got in populating data parts, something like this still gives you problem?

    var db = Titanium.Database.open('MyTable');
    db.execute('CREATE TABLE IF NOT EXISTS labels (id INTEGER PRIMARY KEY, label TEXT)'); 
    //Code that populates database if it doesn't exist
    db.close();
     
    var db = Titanium.Database.open('MyTable');
    var dbData = db.execute('SELECT * FROM labels');
     
    for(i=0;i<dbData.rowCount;i++){
        labels.push(dbData.fieldByName('label'));
        Ti.API.info(dbData.fieldByName('label'));
        dbData.next();
    }
    dbData.close();
    db.close();

    — commented 3 years ago by Daniel Lim

  • Show 4 more comments

Your Answer

Think you can help? Login to answer this question!