• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with reading record

 
David Gibson
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I read a record I thought I could pass in the record number and by using this formula I could read the record at recNo :-
recordDataOffset + (recNo * recordSize)
The problem is that I am alway the same number of bytes out as the record number I pass in, so I can fix the equation by doing the following :-
recordDataOffset + (recNo * recordSize) + recNo.
But I don't understand why this is so!! Am I reading in wrong and why does this hack work?
 
Min Huang
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably your recordSize is off by 1? Make sure you tally up the field lengths + valid flag lengths right.
 
David Gibson
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick rely Min
And sure enough if I add one to the record size the original equation works fine ( again another hack ). The problem is that I read in the record size from the db file itself, so does this mean that I have duff data? Or should I add one for a reason?
 
Michael Hartman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The extra byte is for the delete flag at the beginning of each record. 0x00 for a non-deleted record, 0xFF for a deleted one. So, the record size is 1 + length of each column.
 
David Gibson
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Love You
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic