phamtanlong / csharp-sqlite

Automatically exported from code.google.com/p/csharp-sqlite
Other
0 stars 0 forks source link

Error while opening the places.sqlite of Firefox 4 #112

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,

thanks for the really great library.

I was trying to open the places.sqlite file of Firefox 4 and to read the places 
table with SELECT * FROM moz_places ORDER BY last_visit_date DESC
but it was failing with the error "file is not a database or is encrypted"

After debugging I could find that 
in the file  btree_c.cs  on line 2689 
the comparison   if ( page1[19] > 1 )  
fires the error 26, because page1[19] in my case is equal 2.

After uncommenting the line 2691 it works fine and I can read the table data 
without any other errors.

My question is - is the comparison in the line 2689 important?
Or maybe some last format changes allow values of the byte 19 to be greater 
than 1?

Best regards,
Ilya Ratchinski 

Original issue reported on code.google.com by d...@inweb20.net on 25 Apr 2011 at 10:14

GoogleCodeExporter commented 8 years ago
yes, places.sqlite is a WAL enabled database;

If there are unwritten pages in the places.sqlite file, you will corrupt the 
database by resetting byte 19 (database format)

See http://www.sqlite.org/wal.html

Backwards Compatibility

The database file format is unchanged for WAL mode. However, the WAL file and 
the wal-index are new concepts and so older versions of SQLite will not know 
how to recover a crashed SQLite database that was operating in WAL mode when 
the crash occurred. To prevent older versions of SQLite from trying to recover 
a WAL-mode database (and making matters worse) the database file format version 
numbers (bytes 18 and 19 in the database header) are increased from 1 to 2 in 
WAL mode. Thus, if an older version of SQLite attempts to connect to an SQLite 
database that is operating in WAL mode, it will report an error along the lines 
of "file is encrypted or is not a database".

Original comment by noah.hart@gmail.com on 16 May 2011 at 6:52