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

Verifying the db file

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The requirments dont spell out how to verify the db file, just mentions that the cookie specifys it is a db file. I am not realy sure how flexible we are supposed to be with the db file. In my case I check
1. the cookie value to be the same value as give in my db file.
2. check the number of records to be 7.
2. the header information, which include the field lengths and field names to be the same as the requirements.

So even a slight change in the database file, such as a change in the field name would cause my Data object to throw an exception screaming incorrect data file format. I was wondering if I am being too strict in this regard or if I am misinterpreting something.

Any opinons would be appriciated
 
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Inuka. I think verifying the cookie value as valid is sufficient to verify the validity of a data file. If, however, you would also like to verify that not only the file is valid, but its header section is also valid (and hence you can ppresumably read the records,) then of course one could argue for more extensive checks...

But there is one thing that may place unnecessary restrictions on the data in the data file. The header could be changed, presumably, in the future, and then the code would fail even though the data would still be valid as per new schema.
[ October 19, 2004: Message edited by: Anton Golovin ]
 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Anton,
I am also thinking of adding a builder pattern to allow flexibility in the database and client(not sure yet). Eitherway I see what you mean.
[ October 19, 2004: Message edited by: Inuka Vincit ]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Inuka:

I think step 2 - check the number of records to be 7 is unncessary. The database file would possibly grow as we are required to implement the createRecord method, unless you are referring to the very first initialization of the system.

I agree with Anton that checking the cookie value alone is sufficient. Meanwhile, I am curious about how you check the value. Do you
1. hardcode the value in your soucecode OR
2. set it and store it in the property file OR
3. guess it from the file name OR
4. some other ways...

What I found interesting is that the database file name reflects the magical cookie value. For my URLyBird 1.2.3 assignment, the db file is "db-1x3.db" and the magical cookie value is "00 00 01 03"; while my friend is doing the Contractor assignment, her db file is "db-2x2.db" and the magical cookie value is "00 00 02 02". Of course, this is a bad choice as no official guarantee is provided.

By checking the cookie value, do u mean we know the value prior to running the applicatoin? Though the value is not specified in the instruction.
 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read the cookie from the file I got and assumed it was the same for all. I think instead of checking for the exact value which I am doing now I am just going to check formatting.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Ni:

What I found interesting is that the database file name reflects the magical cookie value. For my URLyBird 1.2.3 assignment, the db file is "db-1x3.db" and the magical cookie value is "00 00 01 03"; while my friend is doing the Contractor assignment, her db file is "db-2x2.db" and the magical cookie value is "00 00 02 02". Of course, this is a bad choice as no official guarantee is provided.



This IS interesting.. it matches my file too.. db-1x2.db and the cookie is 01 02..
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For db-1x2.db (for my assignment) magic cookie is 00 00 01 02.

William, You just uncovered something.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a curious observation: my URLyBird 1.2.3 db file name is db-1x3.db and the magic cookie is 00 00 01 03. I believe the magic cookie matchs the file name when Sun creates the file.

Best Regards.
 
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good eye William!

Every few months or so, someone new on the forum makes this realization, and we have verified it over the course of time. The magic cookie used to verify the database file is indeed related to the database name. I believe the two are generated together.
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw a lot of topics where the magic cookie was something like this:
00 00 01 03

I read my cookies in this way:
int fileCookie = dbFile.readInt();
and i recieved e.g. 259
Is it Okey? Or should i read the cookie in another way?
Thanks a lot for your comments!
Olena
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Olena,

I believe you can read in your cookie which ever way you want. The verification is internal to the Data class, so it doesn't matter if you are using int or hex. The pattern was noticed in hex, that's all.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic