-
final 类
DefaultDatabaseErrorHandler调用SQLiteDatabase如下函数,配置DatabaseErrorHandler的实现,如果为null,默认采用DefaultDatabaseErrorHandler
SQLiteDatabase openOrCreateDatabase(String, android.database.sqlite.SQLiteDatabase.CursorFactory, DatabaseErrorHandler)
SQLiteDatabase openDatabase(String, android.database.sqlite.SQLiteDatabase.CursorFactory, int, DatabaseErrorHandler)-
异常
SQLiteDatabaseCorruptException标识sqlite3数据库文件污染 -
应用内需要捕获
SQLiteDatabaseCorruptException实现自定义行为 定义DatabaseErrorHandler子类;
定义SQLiteOpenHelper子类,调用父类构造函数传递自定义DatabaseErrorHandler;
自定义DatabaseErrorHandler子类,参考DefaultDatabaseErrorHandler源码。 -
导致数据库文件
corrupt原因,参考
- File overwrite by a rogue thread or process
a) Continuing to use a file descriptor after it has been closed; b) Backup or restore while a transaction is active; c) Deleting a hot journal;
- File locking problems
a) Filesystems with broken or missing lock implementations; b) Posix advisory locks canceled by a separate thread doing close(); c) Two processes using different locking protocols; d) Unlinking or renaming a database file while in use; e) Multiple links to the same file;
- Failure to sync
a) Disk drives that do not honor sync requests; b) Disabling sync using PRAGMAs;
- Disk Drive and Flash Memory Failures
Non-powersafe flash memory controllers; Fake capacity USB sticks;
- Memory corruption
- Other operating system problems
- Bugs in SQLite