Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to count the totle record number?

 
Nick Lee
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,all
In my db file,there isn't record number to read, and it's hard for me to count the totle record number? Does anybody have good solution on that?
Thx
Nick
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
think about what you DO have, although its not very clear you can find total number of records in the header/schema, you just have to spend a few seconds looking at it
 
frank sun
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
according to the data file, you could get the:
db.length; headerLength; RecordLength; RecordFlagLength, It's for your reference.
recordCount=(db.length - headerLength)/(RecordLength + RecordFlagLength),
That's your total record count.
As to the record number, you also could calculate it out.
Frank
 
Larry Li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And besides the above, I think when add and delete we should also consider the recordNum if keeps it as a data class variable.
Add: if (do not occupy deleted record position)
recordNum++;
else
keep it untouched;
delete:
keep it untouched;
Am I right?

Larry
 
S. Ganapathy
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
record is record. If it is deleted logically (with delete flag 1 for deleted, and 0 for active), no need to consider whether the record is deleted. So, deleted record will also get counted. While displaying all active records, index the file pointer to the first position, read the delete flag, if it is active, proceed to read, else, index to next record position, and so on till EOF. If user asks for specific record, say recordNo 5, and if it is logically deleted, display RecordNotFoundException with appropriate exception message.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic