• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S Record Number Question

 
Katie McGettrick
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I realise this is probably a really silly question, and its my first time to post so I hope I don't annoy anyone

I've just started on my SCJD project and I'm in the design phase of the data access part. I've been looking at the instructions, at the part where it tells you about the fields that are in the database and I notice that there are no record numbers, i.e. no unique identifiers for the records in the database. Now, maybe I've just been using relational databases too long but I can't see how this is going to work.

I could of course read all the records and create record numbers for them on the fly but then how do you find them once they've been written to the database? Am I missing something?
 
Johnny Hastings
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hadled this issue by caching the data in the application. All interactions that the users have with the data is actually with the application cache of the data, not the file itself. When I read in the records, into a Vector, the order in which they get added becomes their key. Occasionally I write them back out to the file (when needed do to changes by the users), and it doesn't matter what order they end up in as/when they go out.

This is my first post here too, but I hope that helps you some.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each record is defined by its offset from the beginning of the database file, with record 0 (or 1, depending on how you count) starting at 1 byte past the last byte of the file header.
If the record is 200 bytes long (for example), and the header 400 bytes (for example), that would mean that you can calculate the location of a record in the database as

if you use zero-based recordIds.

Or more correctly, as there's the flag indicating whether a record has been deleted (which I don't count as part of the record):


Therefore the recordId can be determined as


If you ever needed to calculate it based on the position of a record in the database.
 
Katie McGettrick
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic