The Unofficial Newsletter of Delphi Users - by Robert Vivrette



 
Archiving Data in TTables and TQueries

Matt Hamilton - mhamilton@bunge.com.au

I've used this in my own projects a few times, and I thought it was worth sharing. It is a nice method to archive your database.

Often it is necessary to put in place some sort of backup or archive procedure. If you are unlucky and don't have 3rd-party backup programs, then you might want to build it into your app. I have done this in several apps by copying the necessary data to "CSV" (comma separated value) files.

Here is the idea: You collate all the fields you want to save into a query, then write the entire query off to a CSV file. At some later date you can 'pipe' the data back in either by using a TBatchMove component, or simply reversing the technique shown here.

Anyway, the code:

And there you have it! This procedure copies all the data in ArchiveQry to a file whose name is specified in the parameter AFilename. After you have copied it out, you could prompt the user to delete the real data, or flag it as archived, or whatever.

Cheers!