I have a PHP web application that stores serialized arrays in a SQLite database. The database got corrupted ('General error: 11 database disk image is malformed') so I tried to rebuild the database with these commands:
$ sqlite3 db_corrupted.sqlite3
.mode insert
.output dump.sql
.dump
.exit
$ sqlite3 db_restore.sqlite3
.read dump.sql
.exit
However when I open the web application I get alot of 'unserialize(): Error at offset 654 of 2288 bytes' notices.
After some investigation it turns out that all serialized arrays with newlines in them have this error. So I suspect the newlines inside an array value are not correctly imported.
When I look in the dump.sql file I would see this:
INSERT INTO table VALUES('a:1:{i:0;s:7:"foo
bar";}');
Which seems ok I suppose: string of length 7, 6 letters, 1 newline. But when I get the value with php from the created db_restore.sqlite3 database probably the string length of 7 is no longer exactly intact somehow (which results in the error at unserializing).
How do I correctly .dump and .read back linebreaks into an SQLite database?
Aucun commentaire:
Enregistrer un commentaire