I am trying to get a database created as per html5 web sql specs.
h**p://www.w3.org/TR/webdatabase/#sql
I am using jquery/javascript to accomplish this.
Here is a bit of simplified problem that i am facing.
1. User enters two fields on a html form
2. In background, i create a websql database .(DB gets created no issues here)
3. I try to create a table structure to start inserting the values grabbed from the HTML form. (the problem is here!)
I am using Chrome as my development debugging needs.
Since i am required to put all my sql commands inside a transaction (client requirement) i can't actually debug and notice where is it going wrong
Now here is my code.
Step 1: User has submitted the form and this function gets executed for the first time.
function submitForm() {
connectToDB();
create_table_runs();
}
STEP2: create/open Database
function connectToDB() {
window.db = window.openDatabase('stats',
'1.0',
'test app',
'2 * 1024 * 1024');
}
STEP3: create table 'runs'. On success, execute "add_table_runs()" (3rd argument in executesql() function )
function create_table_runs() {
window.db.transaction( function (tx) {
var sqlStatement = "CREATE TABLE runs (name, age)";
tx.executeSql ( sqlStatement,
[],
add_table_runs(),
null);
});
}
function add_table_runs() {
var player_name = $('#plrName').val();
var player_age = parseInt($('#plrAge').val());
db.transaction (function(tx)
{
var sqlStatement = "INSERT INTO runs (name,runs) VALUES (?,?)";
tx.executeSql( sqlStatement,
[player_name, player_age],
null,
null);
});
}
I have tried to re produce the problematic bit as best as possible. if you can comment on what might be wrong here including testing environment (i.e. chrome built in dev tools etc etc), that will be great.
Any help will be highly appreciated.
Thanks