sqlite update execution error if multiple records exist
Posted: Wed Jan 15, 2020 12:09 am
Hello
I'm just learning databases with Livecode. I'm sure there's a simple answer to this somewhere.
I've got a simple database just trying to update records with a simple statement. The query ends up reading like this
UPDATE photo SET favorite = "0" WHERE refnum = "123462"
This works just fine in DB Browser but give the following error when running from Livecode only if there are more than one records that equal the search in the WHERE statement.
execution error at line 333 (Database INSERT failed: 7)
Here's the code -
-------------------------------------------------------------
put "UPDATE photo " into tSql
put "SET favorite = " & quote & "0" & quote after tSql
put " WHERE refnum = " & quote & gCurrentRefNum & quote after tSql
revExecuteSQL gDatabaseConnection, tSql
if the result is not 1 then
throw "Database INSERT failed:" && the result
end if
--------------------------------------------------------------------------------
The statement runs and works if there is only one record in the database matching the WHERE variable in Livecode and DB Browser.
Doesn't work in Livecode if there are multiple records that match, but does run fine in DB Browser.
Do I need to run a repeat loop to update all the matching records in the database one at a time?
Is there a different way to form the query in Livecode that will update all matching records in the database at the same time?
Thanks!
Jon
I'm just learning databases with Livecode. I'm sure there's a simple answer to this somewhere.
I've got a simple database just trying to update records with a simple statement. The query ends up reading like this
UPDATE photo SET favorite = "0" WHERE refnum = "123462"
This works just fine in DB Browser but give the following error when running from Livecode only if there are more than one records that equal the search in the WHERE statement.
execution error at line 333 (Database INSERT failed: 7)
Here's the code -
-------------------------------------------------------------
put "UPDATE photo " into tSql
put "SET favorite = " & quote & "0" & quote after tSql
put " WHERE refnum = " & quote & gCurrentRefNum & quote after tSql
revExecuteSQL gDatabaseConnection, tSql
if the result is not 1 then
throw "Database INSERT failed:" && the result
end if
--------------------------------------------------------------------------------
The statement runs and works if there is only one record in the database matching the WHERE variable in Livecode and DB Browser.
Doesn't work in Livecode if there are multiple records that match, but does run fine in DB Browser.
Do I need to run a repeat loop to update all the matching records in the database one at a time?
Is there a different way to form the query in Livecode that will update all matching records in the database at the same time?
Thanks!
Jon