Delete records in a random file - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Delete records in a random file (/showthread.php?tid=2736) |
Delete records in a random file - Kernelpanic - 05-26-2024 The example is a random file that is connected to an index file. A kind of ISAM file management. The practical sense should be: One cannot simply delete a record from a random file; For example, the data record with the item number (key) 2345 should be deleted. To make this possible, entry 2345 in the index file must first be deleted, but the data record number, which is also saved and refers to the random file, remains intact. By deleting entry 2345 in the index file, all occupied entries in the index file move down, while the "deleted" entry with the data record number is stored as the first free field above it. The effect is that if a new data record is written, then the "deleted" data record is overwritten. In this respect, a random data record has been deleted after all. - So much for the theory. The template for the example is from a book. There is no error message, but the result is not convincing! I can't figure out why nothing useful is displayed. But there must be a logical error somewhere. Maybe someone could look at the whole thing and find the error. Thanks! Create random file: Code: (Select All)
Output of the data Code: (Select All)
RE: Delete records in a random file - SMcNeill - 05-26-2024 Let me give you the world's most hidden secret in how to delete files from a database: Code: (Select All) Type Warenposten Now, compare that to what you have in your own code above. See the extra entry? With a flip of that single byte in each record, you can flag a record as being "deleted" or "invalid".... And, most amazingly, since the record is still there -- just flagged "invalid" -- you can now also add an option to "undelete" and validate that record once again! Yo just built a RECYCLE BIN into your database! That's all it takes to expand that random record that much! Now, if you want to PACK the database, or PURGE deleted files, all you do is basically write a short routine to run the length of the database: FOR i = 1 TO Record_Length GET #1,i, record IF record(i).invalid THEN 'skip record ELSE PUT #2, ,record END IF NEXT Copy all the records from the old database over to a new database, as long as that "invalid" flag hasn't been set for them. It's much more efficient than trying to rebuild/reindex the database with every "delete", and you have the option of scheduling it for times when the user isn't using the database for anything else. (Like a 2AM repacking time every Sunday night...) RE: Delete records in a random file - Kernelpanic - 05-27-2024 Quote:Copy all the records from the old database over to a new database, as long as that "invalid" flag hasn't been set for them.I know this is the standard method that is found in every relevant manual. The procedure I described is something I have never read in any other instructions. I'll have to look at the suggestions again. Thanks for that. The main reason for my request for help has probably been lost somehow, because my current problem is that both programs work together without displaying an error, but the result is wrong. Why is that? It have to a logical misteke. Until I can not fix this error, I can not try indexing. |