Forum > Databases

TCSVDataset duplicates modified records on Post

<< < (2/2)

Martin Lowry:
Hi wp,

I was able to reproduce the 'bug' by adding the following method to the form:


--- 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";}};} ---procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin  CSVDataset1.Close;  CloseAction:=caFree;end; 
I ran the test, modified 2 fields in record 2, and closed the form without doing anything further. The original file was rewritten and now has an extra record duplicating the one I modified.

--- Code: Text  [+][-]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";}};} ---FirstName,LastName,City,Address,BirthdateWalter,Mellon,Oklahoma City,"1261, Main Street",01/01/1980Mario,Speedwagon,Hollywood,"1500, Hollywood Blvd",17/12/1982Mario2,Speedwagon2,Hollywood,"1500, Hollywood Blvd",17/12/1982Anna,Mull,Los Angeles,"2202, Capitol Square",17/12/1982 
This appears to happen because the update buffers are not cleared by calling MergeChangeLog as is done in TCustomCSVDataset.SaveToCSVStream. As a workaround the duplication can prevented by adding the MergeChangeLog call in a TCustomCSVDataset.OnBeforeClose event.


wp:
Now that I know what to do I can also reproduce it even without your change. Each time when the app is closed after a record has been edited and posted, the un-edited record remains in the database file. Condition is that the database file already exists when the application starts; the way my application is written this is true at the second start, or later. No idea, why this makes a difference...

Replaced the TCSVDataset by a TBufDataset, but I do not see the issue here (attached as "bufdataset_duplicate_records.zip")

Could you file a bug report? Add the test project, describe the issue as well as the steps to reproduce it. Mention the results of your own analysis of the issue.

wp:
Here is a simpler test project which shows the issue in a pure FPC program without user interaction: it creates the dataset with a few records, edits and posts one record, closes the dataset and reopens it - after reopening the recordcount has increased by one, and the original version of the edited record is still there.

Martin Lowry:
Bug report submitted. See https://gitlab.com/freepascal.org/fpc/source/-/issues/39925

Navigation

[0] Message Index

[*] Previous page

Go to full version