• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to check a valid database file?

 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, folks

Finally I have finished my implementation of the DBAccess interface.

When my Database object is first created I run a set a checks or validations over the database file, many of them are performed while loading the database metadata.

I will share with you the checks that I run over the file and I would appreciate your comments or that you share any further validations that you perform.

  • The file must exists.
  • The file size must a positive number bigger than 0.
  • The file encoding must be supported.
  • The magic cookie must be a positive number bigger than 0. (???).
  • The number of fields must be positive number bigger than 0.
  • The length of the field names must be positive numbers

  • bigger than 0
  • The field name matches regex: "[\\w&&[^\\d]]\\w+"
  • The field size is a positive number bigger the 0.
  • The header size must be a positive integer no smaller than 6 (magic cookie + number of fields = 6 bytes)
  • The record size must be a positive integer bigger than 0.
  • The size of data section of the database file is equal to the fileSize - headersize. Therefore the following criteria must be true: ((fileSize - headerSize) % recordSize)==0


  • I have serious doubt about the semantic meaning of the magic cookie field. But I am currently checking it is a positive integer.

    Any comments or further checks?
    [ July 19, 2006: Message edited by: Edwin Dalorzo ]
     
    Oliver Weikopf
    Ranch Hand
    Posts: 58
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Wow, that's a lot of testing! I personally don't do many of these.

    But for the cookie: The way I understand it, the cookie must always have the same value to identify the file as a file of the appropriate format.
    So I took a look at the file, and noted the cookie. A file is only deemed to have the correct format by my Data class if the cookie has that exact value.
     
    Mihai Radulescu
    Ranch Hand
    Posts: 918
    IntelliJ IDE Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Edwin,

    Nice list, you just give some new ideas about some checks( ).
    And now about the cookie, you also must check the cookie value (must be the same with the one from sun). This is the way how you identify your database file.
    If this check fails that means you deal with an other file and may be this file has an other format that you expect.
     
    Edwin Dalorzo
    Ranch Hand
    Posts: 961
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    My worry is if the magic cookie in the file the evaluator is going to use is different from the one in my file. Because that would make the application start-up fail, or at least will prevent the user from starting the database server.

    I was rather thinking about removing the magic cookie check, in order to avoid unforeseen issues during the evaluation.
     
    Oliver Weikopf
    Ranch Hand
    Posts: 58
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Edwin Dalorzo:
    My worry is if the magic cookie in the file the evaluator is going to use is different from the one in my file. Because that would make the application start-up fail, or at least will prevent the user from starting the database server.

    I was rather thinking about removing the magic cookie check, in order to avoid unforeseen issues during the evaluation.


    The entire point of the cookie is to assert that the file you're using has the correct format. Leaving it out in case you're using the wrong file is a bit schizophrenic, don't you think?

    I recommend making the check, that's what the cookie is there for. Also, I assume that during evaluation the db file you're including will be used, since they emphasise so much that you need to include it.
    [ July 20, 2006: Message edited by: Oliver Weikopf ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic