I am trying to get a database created as per html5 web sql specs.


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() {	

STEP2: create/open Database

function connectToDB() {
	window.db = window.openDatabase('stats',
					 '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,
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],

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.


Don't you need to specify types when creating the table (example here). Are you sure you want to pursue this, because specification of websql by W3C is no longer maintained.