Forum > Database
Smart way to get changes on Db table.
BSaidus:
Hello.
Let say that I have an sqlite3 table
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---t1 (id integer, name varchar(20), address varchar(50) ) Is there any smart way to know changed records after posting data ?
I mean :
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- // let record 1 has a values id = 1, name = 'toto', address = '33 av. lebhayer' I changed the name value to
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- // let record 1 has a values id = 1, name = 'tata', address = '33 av. lebhayer' after commuting changes, Is there any way to know that only the name field changed.
For now, I proceed like this.
when creating form, I get the initial value before any changes to variable,
then after omitting changes I compare current values with the first ones I get in the FormCreate.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- // get_Initial_values // POST changes // get_Current_value >> Diff >> get_Initial_values
Thank you
cdbc:
Hi
I think SQLite has something called 'rows_affected' tucked away somewhere deeper then the dataset, maybe in TSQLite3Connection?!?
Happy hunting
Regards Benny
Hartmut:
What cdbc means, is function TSQLQuery.RowsAffected, if that is, what you was looking for.
TRon:
SQLite seem to support a so called snapshot (when support for it was compiled in) which can be used to differentiate between two points in time. I do not have any experience with SQLite and snapshots though so can't provide practical example.
Thaddy:
--- Quote from: TRon on February 13, 2024, 03:56:50 am ---SQLite seem to support a so called snapshot (when support for it was compiled in) which can be used to differentiate between two points in time. I do not have any experience with SQLite and snapshots though so can't provide practical example.
--- End quote ---
That is an interesting feature that I did not know about in SQLite.
I found a good example on the web.
Suppose we have two tables, student and new_student. Then we can create a snapshot like so:
--- Code: SQL [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---CREATE SNAPSHOT snapshot1 ASSELECT student.rollno, student.name FROM studentUNION ALLSELECT new_student.rollno, new_student.name FROM new_student;
Now suppose we have created two snapshots over time, we can query the difference like so:
--- Code: SQL [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SELECT * FROM snapshot1 EXCEPT SELECT * FROM snapshot2;That was really easy. I will use it more often. Tnx for the tip!
Navigation
[0] Message Index
[#] Next page