using UPDATE function in SQLite

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Ultravibe
Posts: 65
Joined: Sat Jan 17, 2015 12:06 pm

using UPDATE function in SQLite

Post by Ultravibe » Sun Jan 18, 2015 3:38 pm

Hi there!
This is my script, wich contained in Button controller and works when clicking the button:

on mouseUp
put "UPDATE Persons SET (Amplua='Rider',Name='Samuel',Lastname='Jackson',Origin='USA') WHERE Number='2'" into tSQL
revExecuteSQL DatabaseID, tSQL
--DatabaseID at this moment contains an actual database id, it's defined before!

revCloseDatabase DatabaseID
end mouseUp

I want to modify the cells in table of database. Table named "Persons". Field "Number" in every row contains number of person. Then i've got several fields like "Amplua" (person is rider, official or simple. it's like a status of person), "Name", "LastName" etc. Using WHERE clause, i set the destination (the row) where i want to update cells

but this structure doesn't work :(((( what am i supposed to do?

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: using UPDATE function in SQLite

Post by phaworth » Sun Jan 18, 2015 8:44 pm

The parentheses around the SET shouldn't be there, that's probably why i's not working. Also, you don't need the single quotes around the 2 although that doesn't cause an error. You only need single quotes around non-numeric values.

After revExecuteSQL, always check the result. It will contain an integer if things worked OK. In this case it would have the number of rows updated by your UPDATE command. If an error occurred it will contain a non integer value that is the text of the error that occurred.

Finally, and this is a matter of personal preference, I open the database when my application starts up and close it when it quits. Continuously opening and closing a database adds extra overhead that I don't think is necessary. You'll find others that don't agree with that but for SQLite databases, I think that's the way to go.

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: using UPDATE function in SQLite

Post by Klaus » Mon Jan 19, 2015 2:06 pm

With every new database app I create, Iususally go here to refresh my meager knowledge about SQL: http://www.w3schools.com/sql/default.asp
:D

zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Re: using UPDATE function in SQLite

Post by zaxos » Tue Jan 20, 2015 12:22 pm

Code: Select all

on mouseUp
put "UPDATE Persons SET Amplua='Rider',Name='Samuel',Lastname='Jackson',Origin='USA' WHERE Number='2'" into tSQL
revExecuteSQL DatabaseID, tSQL
if the result is not an integer then
answer the result
end if
--DatabaseID at this moment contains an actual database id, it's defined before!

revCloseDatabase DatabaseID
end mouseUp
You should get used to do some error checking, it helps :)
Knowledge is meant to be shared.

Post Reply