• 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

Q: when to verify magic number?

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The db file has a magic number to identify the type of db the program suppose to work with. I think I would like to check it at the early stage of the startup of the program, either in alone or server (rmi seems irrelevant). Should I worry about some other database operations in the case that during program's execution, the underlying database file is changed?

If there is a file locking mechanism, then this won't be a problem. Or, I should just take the simple assumption: if the db file is given, then it is the file to be used. I should only verify when user updates it (or I can simply disable the file update button so that program allows only one file/port configuration).

Thanks for your comments
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andy,

Personally I think it is a good idea to check the magic number at the time your application starts up (stand alone app or server app - as you said, there is no point checking it for each client).

If you don't do this, then you have no assurances that the data you are reading in is actually making sense. If you ignore the magic cookie, and hard code the field sizes (I am recommending against both practices by the way), then it would be possible for your program to appear to run on any input, but produce absolutely meaningless results.

You should not have to worry about some other application changing the underlying database while you are using it - the instructions have a line stating that "at any moment, at most one program is accessing the database file".

Regards, Andrew
 
Andy Zhu
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Andrew. Very appreciate your comments.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic