Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete records in a random file
#2
Let me give you the world's most hidden secret in how to delete files from a database:

Code: (Select All)
Type Warenposten
  invalid As _BYTE
  nummer As String * 4
  artikel As String * 10
  preis As Double
End Type

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...)
Reply


Messages In This Thread
Delete records in a random file - by Kernelpanic - 05-26-2024, 05:37 PM
RE: Delete records in a random file - by SMcNeill - 05-26-2024, 05:54 PM



Users browsing this thread: 2 Guest(s)