public class

RepairKit

extends Object
java.lang.Object
   ↳ com.tencent.wcdb.repair.RepairKit

Class Overview

Database repair toolkit to parse a corrupted database file and write its content to another (newly created) database.

Summary

Nested Classes
class RepairKit.MasterInfo Class represent master info backed up from a SQLiteDatabase, which can be used in recovery on database file with corrupted header. 
Constants
int FLAG_ALL_TABLES Flag indicates all tables and indices should be written to the destination database, regardless to how table filters are set.
int FLAG_NO_CREATE_TABLES Flag indicates no CREATE TABLE or CREATE INDEX statement should be executed on the destination database.
Public Constructors
RepairKit(String path, byte[] key, SQLiteCipherSpec cipherSpec, RepairKit.MasterInfo master)
Open a corrupted database for repairing.
Public Methods
boolean isDataCorrupted()
Retrieve whether data is corrupted.
boolean isHeaderCorrupted()
Retrieve whether database header is corrupted.
boolean isSaltCorrupted()
Retrieve whether KDF salt is corrupted.
static String lastError()
Retrieve the last error message.
boolean output(SQLiteDatabase db, int flags)
Parse corrupted database and output its content to db.
void release()
Close corrupted database and release all resources.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int FLAG_ALL_TABLES

Flag indicates all tables and indices should be written to the destination database, regardless to how table filters are set.

Constant Value: 2 (0x00000002)

public static final int FLAG_NO_CREATE_TABLES

Flag indicates no CREATE TABLE or CREATE INDEX statement should be executed on the destination database.

Constant Value: 1 (0x00000001)

Public Constructors

public RepairKit (String path, byte[] key, SQLiteCipherSpec cipherSpec, RepairKit.MasterInfo master)

Open a corrupted database for repairing.

Database is successfully opened and ready to be parsed when the constructor returns without throwing exceptions. The caller should catch SQLiteException in case of failure due to file opening error, wrong password, or unrecoverable corruption.

Backup master info can be provided for better chance of recovery. Backup master info can be saved before the database is corrupted by calling save(SQLiteDatabase, String, byte[]). To use backup master info on recovery, call load(String, byte[], String[]) on saved info and pass it as master argument.

Table filters can be applied to recover only selected tables. Calling make(String[]) or load(String, byte[], String[]) to generate table filters.

Parameters
path path to the corrupted database to be repaired
key password to the encrypted database, or null for plain-text database
cipherSpec cipher description, or null for default settings
master backup master info and/or table filters
Throws
SQLiteException when corrupted database cannot be opened.
IllegalArgumentException when path is null.

Public Methods

public boolean isDataCorrupted ()

Retrieve whether data is corrupted.

Returns
  • true if corrupted

public boolean isHeaderCorrupted ()

Retrieve whether database header is corrupted.

Returns
  • true if corrupted

public boolean isSaltCorrupted ()

Retrieve whether KDF salt is corrupted.

Returns
  • true if corrupted

public static String lastError ()

Retrieve the last error message.

Returns
  • last error message

public boolean output (SQLiteDatabase db, int flags)

Parse corrupted database and output its content to db.

This method does not return until repairing is finished. Don't call it in the main thread or it will cause ANR.

Parameters
db destination database to be written
flags flags affects repair behavior
Returns
  • true if at least one row is successfully repaired

public void release ()

Close corrupted database and release all resources. Do not call any methods after this method is called.