Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Table created and first record inserted but then disappears #52

Open
arsusbravo opened this issue Oct 19, 2017 · 0 comments
Open

Table created and first record inserted but then disappears #52

arsusbravo opened this issue Oct 19, 2017 · 0 comments

Comments

@arsusbravo
Copy link

I'm very happy with this plugin, that I can finally see something works with my websql database in windows phone. However, I got this problem.

Here is my open database codes:

`var db = openDatabase("MyTable", "1.0", "mytable", 2000000);
db.transaction(newVehicles, function(tx, err){ console.log("Error processing vehicle: "+ JSON.stringify(err)); });
function newVehicles(tx){
   tx.executeSql("SELECT COUNT(*) FROM VEHICLES", [], function(tx){
	console.log('table found');
   }, function(tx, err){
	console.log('No table found. Going to create table. '+ JSON.stringify(err));
	tx.executeSql('DROP TABLE IF EXISTS VEHICLES', [], function(tx, res){ console.log('table dropped'+ JSON.stringify(res)) }, function(tx, err){ console.log('no vehicles table found: '+ JSON.stringify(err)) });
	tx.executeSql('CREATE TABLE IF NOT EXISTS VEHICLES (id INTEGER PRIMARY KEY, polnum, license)', [], function(tx, resultSet){
		console.log('new app, new VEHICLES table has been made. '+JSON.stringify(resultSet));
	}, function(tx, err){
		console.log('Cannot create table '+ JSON.stringify(err)); 
	});
	
	tx.executeSql("SELECT COUNT(*) FROM VEHICLES", [], function(tx, resultSet){ console.log('vehicle table now existed. '+JSON.stringify(resultSet)); }, function(tx, err){ console.log('vehicle table still not existed. '+JSON.stringify(err)); });
	
	tx.executeSql('INSERT INTO VEHICLES (polnum, license) VALUES (?, ?)', ['123XX', 'XX123'], function(tx, results){ console.log('table created and new record inserted. '+JSON.stringify(results)); }, function(tx, err){ console.log('none inserted: '+ err.message); });
   });
}`

From the console I got this results:

  • No table found. Going to create table. {"code":1,"message":"no such table: VEHICLES"}
  • table dropped{"insertId":0,"rows":[],"rowsAffected":0}
  • new app, new VEHICLES table has been made. {"insertId":0,"rows":[],"rowsAffected":0}
  • vehicle table now existed. {"insertId":0,"rows":[{"COUNT(*)":0}],"rowsAffected":0}
  • table created and new record inserted. {"insertId":1,"rows":[],"rowsAffected":1}
  • Error processing vehicle: {"code":1,"message":"no such table: VEHICLES"}

For the first time, no table found. Then vehicles table created. And I checked one more time, and it says the table is existed. Furthermore, I can insert a record.

However, the db.transaction says, no table found. And if I reopen the app, it says again that no table is found. How come did the table just disappear?

Could someone tell me where my mistake here? Have I made a temp table here?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant