ON DUPLICATE KEY UPDATE with website and variables
I am trying to do this, but it doesn't work:
tx.executeSql('INSERT INTO MOVIE (id, rate) VALUES(?,?) ON DUPLICATE KEY UPDATE rate=VALUES(rate)',[result.id,score]);
My ID is INT NOT NULL UNIQUE and evaluates to INT. I think my syntax is wrong ... Do you have a solution?
thanks :) Anthony.
+3
source to share
1 answer
As stated in Web SQL Database :
User agents must implement the SQL dialect supported by Sqlite 3.6.19.
So, I am assuming that you run into the same problems as with Sqlite. It looks like SQLite UPSERT - ON DUPLICATE KEY UPDATE is not supported by Sqlite, so I suggest just trying one of the solutions provided in the answers. Perhaps something like this will work:
db.transaction(function (tx) {
tx.executeSql('INSERT OR IGNORE INTO MOVIE VALUES (?, ?)', [result.id,score]);
tx.executeSql('UPDATE MOVIE SET rate = ? WHERE id = ?', [score,result.id]);
});
See demo
By the way, Web SQL Database is outdated .
+1
source to share