12
I'm using a PhoneGap project on Xcode. I am trying to connect to a SQLite database by using JavaScript.
I have made a file, "myDatabase.sqlite", in an SQLite tool. How do I open that database in my code?
Right now I'm using the following code:
var db;
var shortName = 'myDatabase';
var version = '1.0';
var displayName = 'myDatabase';
var maxSize = 65535;
db = openDatabase(shortName, version, displayName, maxSize);
db.transaction(function(transaction) {
transaction.executeSql('SELECT * FROM User;', [],
function(transaction, result) {
if (result != null && result.rows != null) {
for (var i = 0; i < result.rows.length; i++) {
var row = result.rows.item(i);
alert(row.ID);
}
}
}, errorHandler);
}, errorHandler, nullHandler);
The problem is that the database is empty, because when I run it, it gives the error 'No such table'. I think it created a new database named "myDatabase" and that’s why it doesn't have any tables.
How can I open my file with all the tables in it?