Transaction callback fires several times

Today I got a very strange behavior of my application: I have this function for creating tables, and then, when it succeeds, continue in the code.

db.transaction(function (tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS newsDetail(id unique, title, text, created, createdTS, imageSmall, imageBig, facebook, gameNumber)'); tx.executeSql('CREATE TABLE IF NOT EXISTS lastModified(id unique, ts)'); tx.executeSql('CREATE TABLE IF NOT EXISTS teams(pos unique, name, games, gd, points, s, snv, gl, glo, goals)'); tx.executeSql('CREATE TABLE IF NOT EXISTS players(number unique, name, nickname, birthdate, height, married, children, profession, clubs, position, image)'); tx.executeSql('CREATE TABLE IF NOT EXISTS games(id unique, home, away, score, date, shortDate)'); tx.executeSql('CREATE TABLE IF NOT EXISTS galleryCategories(id unique, name, date, thumb, ordering)'); tx.executeSql('CREATE TABLE IF NOT EXISTS galleryImages(id unique, url, description, catid, ordering)'); tx.executeSql('CREATE TABLE IF NOT EXISTS videos(id unique, url, title, image)'); }, errorCB, function () { loadData('newslist', createNewslist, true); loadData('refresh', loadNewOnes, true); }); 

Now the problem is that the Succes callback function is called 8 times. Why is this? I have been using this code for several months and have never encountered this problem before. Has anyone ever come across anything like this? Any help is appreciated.

+4
source share
1 answer

You have probably added code that calls this function several times. What can happen, since this function is asynchronous, if you loop it or run code that constantly calls this function, this code will not block and wait for the completion of your function. Instead, it is called several times, not knowing why this is happening.

Have you ever written tests to surround the problem so that you know what was broken?

0
source

All Articles