• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

URLyBird 1.1.3 Schema description section Data File Format

 
Ranch Hand
Posts: 221
Scala Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,


I am having a hard time trying to figure out how to make sense and read the Schema Description Section in the Data File Format.

With my assignment I got:

***************************************************************

Data file Format
The format of data in the database file is as follows:

Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
2 byte numeric, number of fields in each record

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


Data section.
Repeat to end of file:
1 byte flag. 00 implies valid record, 0xFF 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

End of file

All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.
Database schema
The database that URLyBird uses contains the following fields:
Field descriptive name Database field name Field length Detailed description
Hotel Name name 64 The name of the hotel this vacancy record relates to
City location 64 The location of this hotel
Maximum occupancy of this room size 4 The maximum number of people permitted in this room, not including infants
Is the room smoking or non-smoking smoking 1 Flag indicating if smoking is permitted. Valid values are "Y" indicating a smoking room, and "N" indicating a non-smoking room
Price per night rate 8 Charge per night for the room. This field includes the currency symbol
Date available date 10 The single night to which this record relates, format is yyyy/mm/dd.
Customer holding this record owner 8 The id value (an 8 digit number) of the customer who has booked this. Note that for this application, you should assume that customers and CSRs know their customer ids. The system you are writing does not interact with these numbers, rather it simply records them. If this field is all blanks, the record is available for sale.

***************************************************************


I know once I figure out how to read the Schema Description Section of my Data File I will be able to calculate the offset to the first record.
However following the description above and trying to read the database file with the Solaris "od -A d -c" command it doesn't make any sense.
Is there any other command in Solaris or any other Operating System to read the file so I can make sense of the Schema Description Section and calculate the offset from the beginning of
the file to the first record?


Thanks in advance,


Carlos.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Carlos, the data file or schema isn't that hard to understand.

Carlos Morillo wrote:
Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
2 byte numeric, number of fields in each record

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


Data section.
Repeat to end of file:
1 byte flag. 00 implies valid record, 0xFF 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

End of file



First it mentions the magic cookie value (4 bytes) then the number of fields (2 bytes). Given these 2 items and your schema... the second number (number of fields) should match with the number of column headings given in the schema section.

The schema description section tells you the column headings like "Name", "Location" etc. There is one set of info for each field: field name (eg Name), field length (eg 64).

Then the data section starts off with 1-byte delete flag then each field's data on its own line.

To start reading the data file, you may want to use RandomAccessFile class to read and write. Recall 4 byte is an integer and 2 byte is a short. So to read your magic cookie value you can do raf.readInt()

Hope this help you to start off.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, Carlos. Welcome to the JavaRanch family!

I don't know if you already took a look at this, but I have posted a tool that reads the .db file (you can find it here). Please take a look at that. I think it will help you understanding how to deal with the database schema.
 
Carlos Morillo
Ranch Hand
Posts: 221
Scala Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roberto,


Awesome! Fantastic!
I was able to read the file with the code you supplied.


I had to do some minor changes like changing some constant values according to the format of my file and
commenting in the main() method the variables related to record Length since record Length it is not
specified in my assignment.

Thanks for your valuable help!
I do really appreciate it and also thanks for the Welcome!



Best Regards,


Carlos.
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic