Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: How to delete records in database???

 
Dave Knipp
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am curious if anyone knows how to delete certain portions of a file with RandomAccessFile.
Data.delete(int recNo) says this :
Deletes a record, making the record number and associated disk storage available for reuse.

So maybe it just means that we are supposed to reuse the space within the file for any records that get created ??? How did everyone implement this, I'm pretty sure im just going to have any new records that are created, use the space in the file where the deleted one is and then write over the deleted record's contents in the file with the contents of the new record. Is this similar to what everyone else did?
Thanks,
Dave
[ November 20, 2003: Message edited by: Dave Knipp ]
[ November 20, 2003: Message edited by: Dave Knipp ]
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm pretty sure im just going to have any new records that are created, use the space in the file where the deleted one is and then write over the deleted record's contents in the file with the contents of the new record. Is this similar to what everyone else did?

Yup, given there was a deleted flag in front of the record. Remember
when you delete you dont really delete the record from the file. You update
its flag indicator to indicate its a deleted record. So if you have 10
records and number 3 is deleted and you add a new record it would go in
space 3. If you have 10 records and none are deleted your new record would
become record number 11. Make sense?

I am curious if anyone knows how to delete certain portions of a file with RandomAccessFile.

Remember you dont need to, just overwrite the flag indicator, simply something like
1. Set your raf to the correct offset of the flag indicator of the given record (you must perform a raf.seek(xxxx);
2. In my case the flag was a short so I was writing a short
3. raf.writeShort(deleteIndicator);
in my case deleteIndicator = -32768 or 0X8000
 
Dave Knipp
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill,
Totally understand, thats what i was thinking but i just wanted to check and see if was on the right page. hmm interesting you have a short as your flag? I actually have a boolean as mine, heres what my instructions say:

1 byte flag. 00 implies valid record, 0xFF implies deleted record

So i just read it in with RAF.readBoolean(); and then write it with RAF.writeBoolean(deletedStatus).
Thanks for your reply,
Dave
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you got it. interesting yours is boolean
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic