Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db.sqlBatch( ) run success , but callback not run #989

Open
seotkd opened this issue Sep 10, 2021 · 1 comment
Open

db.sqlBatch( ) run success , but callback not run #989

seotkd opened this issue Sep 10, 2021 · 1 comment

Comments

@seotkd
Copy link

seotkd commented Sep 10, 2021

The steps are as follows:
1, executeSql() is wrappered in promise
2, run promise( ) , then run batch( )

There was a problem with the operation:
in the database, the data insert success, but no console or alert.
if don't use promise async, sqlBatch() callback is normal

let promise = new Promise(resolve=>{
	
	db.executeSql('SELECT count(*) AS mycount FROM DemoTable', [], function(rs) {
		console.log('Record count (expected to be 2): ' + rs.rows.item(0).mycount);
		resolve(true);
	  }, function(error) {
		console.log('SELECT SQL statement ERROR: ' + error.message);
	});
 
})

function batch(){	
	db.sqlBatch([
		'CREATE TABLE IF NOT EXISTS DemoTable (name, score)',
		[ 'INSERT INTO DemoTable VALUES (?,?)', ['Alice', 101] ],
		[ 'INSERT INTO DemoTable VALUES (?,?)', ['Betty', 202] ],
		], function() {
		console.log('Populated database OK');
                alert("success")
		}, function(error) {
		console.log('SQL batch ERROR: ' + error.message);
               alert("error")
	});  
}

promise().then(res=>{
	
  if(res === true) batch(); 
  // batch run success, but no console or alert.the callback is invalid.
	
})


/ *  If only batch() is executed , the callback is very good suach as  */
batch(); // batch run success ,console and alert is valid
@skrs13
Copy link

skrs13 commented Feb 10, 2022

Hi - I'm also facing a similar issue with executeSql() API. Were you able to fix this or work-around it?

[(https://github.com//issues/999#issue-1128856851)]

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

No branches or pull requests

2 participants