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
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 actually dont understand and my database file has some strange characteres.... I need help.....
I attachment some printscreen of my databasefile and bold in red...this strange characteres...
1)what's it ???
2) I dont know what mean MAGIC COOK in the begin of file....???
Andrew Monkhouse
author and jackaroo
Marshal Commander
The database file looks reasonable to me. The problem is that you are trying to view it in a text editor, when it is a binary database file.
The JavaRanch SCJD FAQ has some generic information on what the magic cookie is used for.
Take a look at the following hex dump of a similar (but not the same) file:
Offset in bytes
Hex values
Ascii equivalent
0000000
0000 0101 0000 9f00 0700 0400 616e 656d
nul nul soh soh nul nul nul 9f nul bel nul eot n a m e
0000020
4000 0800 6f6c 6163 6974 6e6f 4000 0400
nul @ nul bs l o c a t i o n nul @ nul eot
0000040
6973 657a 0400 0700 6d73 6b6f 6e69 0067
s i z e nul eot nul bel s m o k i n g nul
0000060
0001 7204 7461 0065 0008 6404 7461 0065
soh nul eot r r a t e nul bs nul eot d a t e nul
0000100
000a 6f05 6e77 7265 0800 5000 6c61 6361
nl nul enq o w n e r nul bsnul P a l a c
0000120
2065 2020 2020 2020 2020 2020 2020 2020
e sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp
0000140
2020 2020 2020 2020 2020 2020 2020 2020
sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp
0000200
2020 2020 2020 2020 2020 5320 616d 6c6c
sp sp sp sp sp sp sp sp sp sp sp S m a l l
0000220
6976 6c6c 2065 2020 2020 2020 2020 2020
v i l l e sp sp sp sp sp sp sp sp sp sp sp
0000240
2020 2020 2020 2020 2020 2020 2020 2020
sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp
0000300
2020 2020 2020 2020 2020 3220 2020 5920
sp sp sp sp sp sp sp sp sp sp sp 2 sp sp sp Y
0000320
3124 3035 302e 2030 3032 3530 302f 2f37
$ 1 5 0 . 0 0 sp 2 0 0 5 / 0 7 /
0000340
3732 2020 2020 2020 2020 4300 7361 6c74
2 7 sp sp sp sp sp sp sp sp nul C a s t l
In this case, the blue text is the magic cookie - as you can see, the 4 bytes (00 00 01 01) are reasonable if you look at them as hex characters, but are meaningless as ASCII strings (nul, nul, soh, soh) - WordPad does not even give you the equivalent strings (0x00 = null), it just prints blanks.
The green text is my schema section. Note that I have more data and different sized fields than your instructions, so do not pay too much attention to the actual data being shown.
The brown text is the very first record to be read.
Hi Andrew...thanks again... Now i'm using Notepad++ to see a file....
So....What should I do with the cookie e meta-data scheme ?? Should I validate this values when final user select and run the program ? or just ignore and read the data session ??
Anne Crace
Ranch Hand
Joined: Aug 29, 2005
Posts: 223
posted
0
Fernando,
Get a hex editor like the one Andrew used in the post above. It will be invaluable to you while you are working on this project. There are a few free ones aout there. A good Google query should return a few of them.
SCJP, SCJD
Andrew Monkhouse
author and jackaroo
Marshal Commander
My recommendation is in line with what is in the FAQ entry I mentioned earlier: I would recommend you use this data to validate that the data file is correct before you start working with it.
Were you able to read your .db file already? I created a simple tool (you can find it here) that reads the .db file and prints its content on the console. Take a look at it if you still didn't get to read it. I think it might be helpful!
Champion, do you have one of the assignments? If so, you should have a .db file, which you can read with this tool. If not, unfortunately this file cannot be shared with other people.
Also, please take a look at an important administrative private message I just sent you.