Announcement

Collapse
No announcement yet.

Simplest way to delete an entry from random file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simplest way to delete an entry from random file

    Hi,
    I have a simple Random file and I need to
    write an operation which removes a selected
    entry/record from the file. Is there a simplest
    way to perform this operation, apart from copying
    all records (excluding the one to delete) and save
    them to another file?

    Thanks,
    Chris

    ------------------

  • #2
    Not in DOS, any more than in Windows. You can make a file shorter,
    but you can't leave holes in the middle.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      What many databases do is have a field or byte in the database
      that indicates whether it is active or not. You don't delete
      the record but reset the field/byte to the inactive state.
      Your database reviews this field/byte during normal processing
      to see if it should exclude it when necessary.

      Then at some later time you do a "database compress" to remove
      the inactive records. A good benefit of this method is that
      a "deleted" record can easily be recovered by resetting the
      field/byte active again (as long as you do it prior to a database
      compress )

      ------------------
      Every day I try to learn one thing new,
      but new things to learn are increasing exponentially.
      At this rate I’m becoming an idiot faster and faster !!!
      ------------------
      George W. Bleck
      Lead Computer Systems Engineer
      KeySpan Corporation
      My Email



      [This message has been edited by George Bleck (edited May 07, 2003).]
      <b>George W. Bleck</b>
      <img src='http://www.blecktech.com/myemail.gif'>

      Comment


      • #4
        Originally posted by Tom Hanlin:
        Not in DOS, any more than in Windows. You can make a file shorter,
        but you can't leave holes in the middle.

        Ah.... I understand what Tom's trying to say her but it isn't what it sounds like.

        You can't "delete" or "remove" a record from the middle but you can set all the bytes (or a single byte) to CHR$(0) to indicate that the record is empty and can be used again.

        More difficultly you could move the last record upto this position or even (shudder) move each of the following records up one then, in either case, use SETEOF to chop off the last record.



        ------------------
        C'ya
        d83
        C'ya
        Don

        http://www.ImagesBy.me

        Comment


        • #5
          Marking a record as "Deleted" is one of the most common approaches, since it involves almost no overhead.

          Combined with an index engine such as PowerTREE, you can easily keep track of the remaining records regardless of their physical order.

          In addition, maintaining another index to keep track of deleted/empty records (so they can be reused in order reduce the rate at which the file grows with new entries) is also very straightforward.



          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment

          Working...
          X