Database Error: java.lang.IllegalStateException: database not open
Hey, I'm trying to have a common class to make some database operations, so, I'm using prototype inheritance model, here's the code:
var Barrel = {} || Barrel;
Barrel.DB = function () {
this.conn = null;
};
Barrel.DB.prototype.setConn = function ( conn ) {
this.conn = conn;
return this;
}
Barrel.DB.prototype.insert = function ( table, data ) {
// this is just a example code.
var query = "INSERT INTO " + table + " VALUES (?, ?)";
// I get values from data argument.
var values = ["val1", "val2"];
Ti.API.debug( "c: " + this.conn ); // prints: [DEBUG] [3,1732639] c: ti.modules.titanium.database.TiDatabaseProxy@43f45fb8
this.conn.execute( query, values ); // ERROR!
return this.conn.lastInsertRowId;
}
function Product() {
this.setConn( Titanium.Database.open( "my.db" ) );
}
Product.prototype = new Barrel.DB();
Product.prototype.constructor = Product;
var product = new Product();
product.insert( "notices", { col1: "woot", col2: "woot2", col3: null, col4: "null" } );
So, as you see, this.conn actually have an instance of Titanium.Database.DB (ti.modules.titanium.database.TiDatabaseProxy@43f45fb8) but when I try to execute the query I get this error:
[TRACE] I/ALERT ( 725): (kroll$2) [166,1732805] java.lang.IllegalStateException: database not open
The question is: why I can't execute some query even if I have an instance of the database?