是否有用于在Linux中验证SQLite数据库的命令行实用程序?

时间:2023-02-05 05:33:00

I am looking for a command line utility to validate SQLite databases. I ran into a situation in some inherited code where an application fails to startup because an attempt to access a database produced the following error:

我正在寻找一个命令行实用程序来验证SQLite数据库。我遇到了一些继承代码的情况,其中一个应用程序无法启动,因为尝试访问数据库会产生以下错误:

database disk image is malformed

So I need to instrument some validation code in the application. Additionally, though, I need a tool that I can run from the Linux prompt to tell me simply if the database is corrupt or not.

所以我需要在应用程序中检测一些验证代码。另外,我需要一个工具,我可以从Linux提示符运行,告诉我数据库是否已损坏。

Thanks

2 个解决方案

#1


9  

You can do something like this:

你可以这样做:

sqlite3 database.db "PRAGMA integrity_check"

#2


7  

You can use PRAGMA integrity_check on the database.

您可以在数据库上使用PRAGMA integrity_check。

If the Database is corrupted you can use this SQLite command:

如果数据库已损坏,您可以使用此SQLite命令:

cd $DATABASE_LOCATION
echo '.dump'|sqlite3 $DB_NAME|sqlite3 new_repaired_$DB_NAME
mv $DB_NAME corrupt_$DB_NAME
mv new_repaired_$DB_NAME $DB_NAME

#1


9  

You can do something like this:

你可以这样做:

sqlite3 database.db "PRAGMA integrity_check"

#2


7  

You can use PRAGMA integrity_check on the database.

您可以在数据库上使用PRAGMA integrity_check。

If the Database is corrupted you can use this SQLite command:

如果数据库已损坏,您可以使用此SQLite命令:

cd $DATABASE_LOCATION
echo '.dump'|sqlite3 $DB_NAME|sqlite3 new_repaired_$DB_NAME
mv $DB_NAME corrupt_$DB_NAME
mv new_repaired_$DB_NAME $DB_NAME