1. Title: Enable topic test, saved successfully. Network response: the value of error_code is 0. See Figure 1.

2. Returning to the document page, the title is: Enable topic, and the added word “test” is not displayed. That is, after saving successfully, the document remains unchanged. See Figure 2.

3. Checking the history versions, there is also no record of the recent modification. See Figure 3.

4. When creating a new API document and saving it, the response fails: {“error_code”:10103,”error_message”:”request fail”}. See Figure 4.

{
"error_code": 10103,
"error_message": "request fail"
}
5. ShowDoc is written based on the ThinkPHP framework. Checking the runtime log file, /Application/Runtime/Logs/Api/20_09_11.log. Error reported: ERR: 11:database disk image is malformed. See Figure 5.

[ 2020-09-11T13:09:52+08:00 ] 10.42.1.14 /server/index.php?s=/api/page/save
ERR: 11:database disk image is malformed
[ SQL语句 ] : INSERT INTO page (page_title,page_content,page_comments,item_id,cat_id,addtime,author_uid,author_username) VALUES ('222','欢迎使用ShowDoc!','','67','669','1599800992','96','wangqiang@chinamcloud.com')
[ 2020-09-11T13:10:53+08:00 ] 10.42.1.14 /server/index.php?s=/api/page/save
ERR: 11:database disk image is malformed
[ SQL语句 ] : INSERT INTO page (page_title,page_content,page_comments,item_id,cat_id,addtime,author_uid,author_username) VALUES ('222','欢迎使用ShowDoc!','','67','669','1599801053','96','wangqiang@chinamcloud.com')
6. Move showdoc.db.php to showdoc.db.php_mv_0911bak. Copy showdoc.db.php_0820bak to showdoc.db.php. See Figure 6.

bash-4.4# mv showdoc.db.php showdoc.db.php_mv_0911bak
bash-4.4# ls
showdoc.db.php.bak showdoc.db.php_0311bak showdoc.db.php_0820bak showdoc.db.php_0911bak showdoc.db.php_mv_0911bak
bash-4.4# ls -l
total 200860
-rwxrwxrwx 1 nobody nobody 24115200 Aug 21 16:48 showdoc.db.php.bak
-rwxrwxrwx 1 nobody nobody 24398848 Aug 21 16:48 showdoc.db.php_0311bak
-rwxrwxrwx 1 nobody nobody 50750464 Aug 21 16:48 showdoc.db.php_0820bak
-rwxr-xr-x 1 nobody nobody 53199872 Sep 11 05:27 showdoc.db.php_0911bak
-rwxrwxrwx 1 nobody nobody 53199872 Sep 11 05:16 showdoc.db.php_mv_0911bak
bash-4.4# cp showdoc.db.php_0820bak showdoc.db.php
bash-4.4# ls -l
total 265372
-rwxr-xr-x 1 nobody nobody 50750464 Sep 11 05:34 showdoc.db.php
-rwxrwxrwx 1 nobody nobody 24115200 Aug 21 16:48 showdoc.db.php.bak
-rwxrwxrwx 1 nobody nobody 24398848 Aug 21 16:48 showdoc.db.php_0311bak
-rwxrwxrwx 1 nobody nobody 50750464 Aug 21 16:48 showdoc.db.php_0820bak
-rwxr-xr-x 1 nobody nobody 53199872 Sep 11 05:27 showdoc.db.php_0911bak
-rwxrwxrwx 1 nobody nobody 53199872 Sep 11 05:16 showdoc.db.php_mv_0911bak
bash-4.4#
7. Create a new API document, save it successfully with no further errors, and upon returning to the document page, the document is created successfully. See Figure 7.

8. Edit the API document, save it successfully, and upon returning to the document page, the document has changed. See Figure 8.

9. Therefore, it can be determined that there is an issue with the SQLite file, which requires analysis and repair. Search for “sqlite repair” in Google. Open the first URL: https://www.recoveryandmanagement.com/repair-sqlite-database-manually/ . Manually repair the SQLite database. Recover SQLite data from the corrupted database.
10. Here, use a simple manual trick to repair the SQLite database. Download: SysInfoTools-SQLite-Database-Recovery.exe. After installation, open the database file: showdoc.db.php. See Figure 9.

11. When opening the table: page, an error is reported: Corruption in file Cell content area. No errors are reported when opening other tables. See Figure 10.

12. Because it is a demo version, repair work cannot be performed using this software. Reference URL: https://stackoverflow.com/questions/18259692/how-to-recover-a-corrupt-sqlite3-database/18260642 .
PS E:\Develop\2020> sqlite3 showdoc.db.php "PRAGMA integrity_check"
*** in database main ***
Main freelist: 3 of 3 pages missing from overflow list starting at 0
Page 34 is never used
Page 35 is never used
Page 36 is never used
Page 95 is never used
13. Use .dump to dump the entire database and use these commands to create a new database to retrieve some or most of the records. The generated file: showdoc.db.php_repair. Its size is 0 KB. See Figure 11.

PS E:\Develop\2020> sqlite3 showdoc.db.php ".dump" | sqlite3 showdoc_repair.db
14. Reference URL: https://blog.csdn.net/sangyongjia/article/details/54910104 . You can attempt to repair the corrupted database file through a simple export and import method. See Figure 12.

PS E:\Develop\2020> sqlite3 showdoc.db.php
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .output "tmp.sql"
sqlite> .dump
sqlite> .quit
PS E:\Develop\2020> sqlite3 new.sqlite3
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .read "tmp.sql"
sqlite> .quit
15. Finally, generate the files: tmp.sql, new.sqlite3. Rename new.sqlite3 to showdoc.db.php. Overwrite it onto the server. See Figure 13.

PS E:\Develop\2020> sqlite3 new.sqlite3 "PRAGMA integrity_check"
ok
PS E:\Develop\2020> sqlite3 showdoc.db.php "PRAGMA integrity_check"
ok
16. After redeploying the container, the save is successful and the document has changed. This matches expectations. See Figure 14.

