Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is zero-byte file a valid sqlite database?

Tags:

sqlite

When I call sqlite3_open_v2() on a zero byte file with flag SQLITE_OPEN_READWRITE, the function returns zero. Then the "PRAGMA quick_check;" statement returns a row containing string "ok". So zero-byte file is considered a valid database? Seems a little counter-intuitive?

like image 953
mr49 Avatar asked Nov 21 '25 10:11

mr49


1 Answers

Well I don't think it's "valid". If it's zero bytes, it's nothing, other than a reference. Yes you can open it. But that's not working if the file has >= 1 byte.

So as long as the file is 0 bytes, you can open it; once you start making changes, it will become an SQLite file.

If you open a non-SQLite file and try to make changes, it will give you an error message:

Error: file is encrypted or is not a database

like image 73
Roger Avatar answered Nov 23 '25 22:11

Roger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!