SQLite File validation
Have a quick question. I am using a SQLite database file in my C# application. At the moment it is not password protected. But it will be in case it is needed as a solution for my question.
Question is is there is a way I can check is the SQLite file in associate with my application is a real SQLite file or not. I am doing a,
File.Exists (filepath)
check at the moment which works fine. But it is possible that someone can create a file with my file extension so 开发者_开发知识库how can I verify that it is a valid Sqlite file ????
Thanks in advance !
You could check the first 16 bytes in the file:
The well known 16-byte sequence that begins every SQLite database file is:
0x53 0x51 0x4c 0x69 0x74 0x65 0x20 0x66 0x6f 0x72 0x6d 0x61 0x74 0x20 0x33 0x00
(from http://www.sqlite.org/fileformat.html)
That is, assuming the password protection doesn't mess those bytes up too.
精彩评论