• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing database file

 
subu ananthram
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I have jsut got started with my scjd assignment.The first task was to parse the db file nad print its output.
I parsed the header and I get name,city blab bla

Schema description section.
Repeated for each field in a record:
1 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
1 byte numeric, field length in bytes
end of repeating block

The 1byte numeric is the fieldlength of the payload I believe.
So the only reason I parse the header is to get the filepointer position for the payload? since I get he payload length from the schema in the assignment itself.

so I have a singleton class that gives me the filepointer where the payload starts.
I then parse the file and have a database value object with al lthe fields that I populate....

Am I totally off ..How is everyone else doing it
Regards
Subu
 
subu ananthram
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why cant I have a record number as incremental ie read all the records from the database file and put them into a value object and increment the record numbers one by one ....
This way I dont have to do a seek to read a record
is this worng?
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could do that with the small dataset provided.
But now imagine that database growing to thousands or millions of records.
 
subu ananthram
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yep your'e right
so I seek it with headerLength+recordNumber-1*sizeOfRecord is it?
and read ..
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you let recordNumber start at 1, and take care to put in some braces.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic