This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to count the totle record number?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic