Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite get the old value after update

For my Android app i'd need to make uptades in some rows of a table and show the to the user the old and the new value. Is there any way of doing that with a single query to the db (with a method that returns the updated rows or similar? )? or I must use two query: fetch old values and then update with the new ones?

Thanks in advance

like image 536
Jaimit Avatar asked May 20 '26 10:05

Jaimit


2 Answers

You need to do that with two queries. You can begin a transaction prior to the read if you want to be assured that its value doesn't change before you write -- just be sure to commit the transaction to enable your change.

like image 106
mah Avatar answered May 22 '26 00:05

mah


As far as I know SQLite doesn't support the fetch-from-update clause like other DBs so you're best to run two queries.

like image 31
Andrew White Avatar answered May 21 '26 23:05

Andrew White



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!