CSVExporter does not export whole dataset lazarus / 16-Databases ---------------------------------------------------------------------- egsuh · 2022-02-15 04:27 I have to set the dataset to first, e.g.    DataSet1.First;  // --- without this, only current and afterwards records are exported.    with TCSVExporter.Create(nil) do begin           Dataset:= Dataset1;           FileName:= filename;           Execute;           Free;                         end; Is this intended or kind of bug? ---------------------------------------------------------------------- Thaddy · 2022-02-15 05:07 This is intended. While working on an open dataset the cursor (not visible, but database cursor) is keeping state (remembers where it is) So if you want to export the whole data, you will always need to move to the first record. This is how most, if not all, databases work. A good introduction is : https://docs.microsoft.com/en-us/azure/data- explorer/kusto/management/databasecursor or: https://www.essentialsql.com/database-cursor/ But in this case my sum up is a bit shorter and to the point. (except I left out that you can clone cursors, so you can return to the previous state, but you get the point) ---------------------------------------------------------------------- Lansdowne · 2022-02-15 10:41 Is this really true ? I would be horrified if that happened to me.  As it is, I often export (or let us say backup) some tables to CSV but make my own routine as it is simple in my case.  So I have not used/looked at this function. If am typing a Word document, or plain text using Notepad++, or even a Pascal unit in the IDE, I am able to save/backup/export the file I'm working on at any time.  Of course, the whole document is saved not just the portion forward from the cursor.  No reason to expect a data table to be treated differently. In a database there are record -level tasks, Read data, write data, lock, commit etc.  Then there are table level tasks, Open, close, save, pack, restructure, reindex etc. I would expect an Export-to-CSV routine to do this Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i with Table do begin  SetBookmark   //save the current cursor  First;  While not Eof do begin    WriteRecordToCSV;    Next;  end;   GotoBookmark  // restore the cursorend;//with If the routine does not include the   First; line then in my opinion it is defective.  Users will imagine the function does what the name implies and could lose valuable data. ---------------------------------------------------------------------- wp · 2022-02-15 11:00 Look at the sources (fpDBExport): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TCustomDatasetExporter = Class(TComponent)  ...    Property FromCurrent : Boolean Read FFromCurrent Write FFromCurrent Default True;  end; Function TCustomDatasetExporter.Execute : Integer;...begin    ...        try          If not FromCurrent then          Dataset.First;          While not (Dataset.EOF or FCanceled) do            ... So, yes, it IS intended, but can be handled also by setting the FromCurrent property to false. I cannot comment on why the developer chose the default value to be true (I would have selected false), but this cannot be changed any more without breaking user code.