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 deal with the db file

 
Shengzhi Peng
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how to access the data of db file . May i have some idea ? The structure as follow:
Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
4 byte numeric, total overall length in bytes of each record
2 byte numeric, number of fields in each record

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

Data section.
Repeat to end of file:
1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information
I am waiting for help.Thank you very much for your advice.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java David,

Your name violates the Naming Policy, please change it at Your Profile.

Nick
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems that you have disclosed too much information on the DB structure, I am not sure whether this also violates the Javaranch policy.

Anyway, as the instructions specified, the 1st x bytes are magic cookie (a number), the following y bytes are total overall length in bytes of each record (a number), the following z bytes are number of fields in each record (a number). You can the read in the corresponding number of bytes, and then convert them into numbers.

After that, you can create a loop to read the records. Each record lengths y btes as specified in the header. Based on the given information, you can then read in the whole dataset, construct each data object and use an appropiate data structure to hold the data.

Nick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic