Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q: when to verify magic number?

 
Andy Zhu
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • 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
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks, Andrew. Very appreciate your comments.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic