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

Possibly Related Threads…
Thread Author Replies Views Last Post
  More info about Random Access files PhilOfPerth 28 954 02-25-2026, 01:50 PM
Last Post: ahenry3068
  random maze map. math help pmackay 4 572 08-10-2025, 11:22 AM
Last Post: pmackay
  Random Number Generator pmackay 14 1,274 07-30-2025, 12:56 PM
Last Post: SMcNeill
  generating a random number in the full range of that number? (Integer, Long) madscijr 2 662 05-01-2025, 09:11 PM
Last Post: madscijr
  Can't attach random-access file PhilOfPerth 7 1,374 08-29-2024, 10:28 AM
Last Post: PhilOfPerth

Forum Jump:


Users browsing this thread: 1 Guest(s)