Repeat to end of file:
1 byte flag. 00 implies valid record, 0xFF implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information
When I create a new record do I need to write the value for bytes into File ?
Without writing these Bytes , the program worked fine .
After I wrote the bytes 00 once and then 0xFF I saw the data was misplaced .
PLease guide me on whether I should write it or not .
I mean, assume that you created a new record, how your application will know that it is a valid record ? It will check this field, and the field will be blank ( assuming that you didn't put the valid or invalid byte on this field), how does your application will check it ??
You could just write on this field if it was an invalid record, BUT you must justify this decision on your choices.txt and tell why you did things this way.
The Death of one is a tragedy, but the Death of a million is just a statistic. Joseph Stalin
Naveen Narayanan wrote:If you have a null padded (0x00) db file, you might escape, without writing a valid- flag especially for a newly created record.
Hum... I'm not sure if I agree with that. I mean, this value has to be written under any circunstance. Remember that other applications that the guys from URLyBird and B&S use also use the same .db file that we do.
Matheus Mendes wrote:I already saw some friends lost points because they don't reuse the deleted records...
Hum... well, the spec doesn't really say that we must reuse deleted entries. The comments of the create() method suggest that we can reuse deleted entries, so it's pretty likely that your friends lost points due to other reasons.
Reading your replies following questions come to my mind
1:-Is soft Delete allowed ? Am I expected only to set the flag while deleting the record ?But specifications say 'Deleting record makes the record number and associated disk storage available for reuse" So as I understand I need to physically delete it .
2:-Flag is one byte and when I write 0xFF , placement of data gets disturbed when I read that record.
Even while declaration
byte b = 0xFF
I see error , "Possible Loss of Precision "
If I print it then it prints as -1 and not 255 .
I am not sure if one byte space in file can accommodate 0xFF
Please advice me on how should I proceed on this .
I mean, this value has to be written under any circunstance
Yes, probably writing that value is secure, otherwise its a bit vulnerable alternative
the spec doesn't really say that we must reuse deleted entries
Fair enough, spec says "possibly reusing a deleted entry" ... , choice is on the developer
So as I understand I need to physically delete it
If you do that, you might have to go for these things
* wipe out a record from file.
* push all the following records, 1 record up.
Why don't think like just marking a record with a flag, so that you can treat it as a deleted-one and possibly later
reuse for a new record-creation
Joined: Oct 27, 2009
Thanks Naveen for your help .
I still not have understood how can I write the unsigned byte 0xFF to file If I need to write 0xFF to indicate that record is soft deleted.