• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

DB file reading problem

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I am doing the following to read the db file. Below is my schema sepc.
*******************************************
Start of file
4 byte numeric, magic cookie value identifies this as a data file
4 byte numeric, offset to start of record zero
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
*******************************************

raf.readShort()

The problem I have is when I try to print the "length in bytes of field name ", it prints 0. without this I can not make sense of the contents of the record. However, when I execute the last print statement, it prints the entire record correctly. Am I missing something ? Any input is appreciated.

thanks

Vrinda
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your readShort reads the deleteFlag.

Seeking to offset results in skipping the field defnitions which are nice to read if you want a more generic app.
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vrinda,

Furthermore, if you are attempting to read the schema (as your code suggests), you should surely not seek to the first record. The schema data is located before all the record data and immediately behind the field that contains the offset to the first record.

Thus, just omit the seek call and you'll probably be fine.

Alternatively, if you don't want to read the schema, but instead hardcode the field sizes in your code, then keep the seek, but don't expect the first short to be the field size; field sizes are only specified once in the schema and are not repeated in the individual records. As Clemens already indicated, the first short in the record will probably be the delete status flag. (The database formats vary between assignments, so I cannot tell for sure without seeing your instructions.)

Frans.
 
Vrinda Werdel
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Clemens and Frans,

Thanks for your inputs. I am clearly able to visualize the file structure now. Your responses definitely hepled me move fwd.

Thanks

Vrinda
 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic