'INSERT ON CONFLICT DO UPDATE SET is not working

I'm trying to do the following using expo-sqlite in react-native:

tx.executeSql(`
                INSERT INTO composers (
                        lastName,
                        firstName,
                        birthDate,
                        deathDate
                ) VALUES (?, ?, ?, ?);
                ON CONFLICT(lastName, firstName, birthDate, deathDate) DO
                UPDATE SET
                    lastName = excluded.lastName,
                    firstName = excluded.firstName,
                    birthDate = excluded.birthDate,
                    deathDate = excluded.deathDate
                `,    
                [
                    composer.lastName, 
                    composer.firstName, 
                    composer.birthDate, 
                    composer.deathDate
                ], (_, resultSet) => {
                    //console.log(JSON.stringify(rows));
                    const insertId = resultSet.insertId ? resultSet.insertId : 0;
                    console.log("INSRTED COMPOSER")
                    console.log(insertId)         
                },
                (tx, error) => dbErrorCallback(tx, error)
            );

I have a UNIQUE(lastName, firstName, birthDate, deathDate) constraint on the composers table, and I'm getting an error that the unique constraint failed when I'm inserting a composer who already exists. I'm expecting it to move on to the ON CONFLICT DO UPDATE SET part, but it seems like it doesn't, I'm not even getting to the console.log("INSRTED COMPOSER") part.

I tried removing the semicolon after the VALUES (?, ?, ?, ?); part, but then I get a syntax error.

What I'm basically trying to do overall is to insert a composer and then use the row id to get the autoincremented primary key of the composer to do more inserts, OR if the composer already exists, get its primary key to do more inserts. But I can't even get this first part working.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source