I have created a database, a table, and pre-populated it with initial values in one method:
function Setup(cb)
{
_db = openDatabase("MoneyMan", "1.0", "Money Manager", 8 * 1024 * 1024);
// Wallets
_db.transaction(function(tx) {
// Create wallet table
tx.executeSql('CREATE TABLE Wallets (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, balance FLOAT, target FLOAT, transactions INTEGER)', [],
function(tx, res) {
// Add initial wallets
tx.executeSql('INSERT INTO Wallets (name, balance, target, transactions) VALUES ("Main", 0, 0, NULL)');
tx.executeSql('INSERT INTO Wallets (name, balance, target, transactions) VALUES ("Bills", 0, 0, NULL)');
tx.executeSql('INSERT INTO Wallets (name, balance, target, transactions) VALUES ("Savings", 0, 0, NULL)');
tx.executeSql('INSERT INTO Wallets (name, balance, target, transactions) VALUES ("Business", 0, 0, NULL)');
});
cb();
});
}
This works perfectly fine.
I have a button to add a new wallet to the table, and it doesn't work. Even this code breaks:
_db.transaction(function(tx) {
tx.executeSql('INSERT INTO Wallets VALUES (NULL, "Testing", 0, 0, NULL)');
});
EDIT: I have also tried listing the fields as such:
_db.transaction(function(tx) {
tx.executeSql('INSERT INTO Wallets (name, balance, target, transactions) VALUES (?, 0, 0, NULL)', [name]);
});
On Chrome, the whole page breaks and I get "Aww, Snap". On Android nothing happens at all. However, when I refresh the page, it seems the wallet was successfully added.
I've searched all over the internet for a solution to this and it's driving me mad. Where am I going wrong?
Thanks
EDIT:
When I set a breakpoint on executeSQL(), it runs fine. It's only when it tries to leave the transaction callback that it breaks.
EDIT:
I should note that this is Javascript compiled from another language. The variable "_db" is accessible from the second method. There are no issues if I do a SELECT statement when I try to add a new wallet. Only INSERT INTO breaks.