java.lang.Object | |
↳ | com.tencent.wcdb.repair.BackupKit |
Data backup toolkit based on table traversal.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | FLAG_FIX_CORRUPTION | Flag indicates when database corruption detected, try to read more data if possible rather than return failure immediately. | |||||||||
int | FLAG_INCREMENTAL | Flag indicates incremental backup is performed. | |||||||||
int | FLAG_NO_CIPHER | Flag indicates no encryption is used on backup data. | |||||||||
int | FLAG_NO_COMPRESS | Flag indicates no compression is used on backup data. | |||||||||
int | FLAG_NO_CREATE_TABLE | Flag indicates no "CREATE TABLE" statement should be output to backup file. | |||||||||
int | RESULT_CANCELED | Result code that indicates operation has been cancelled. | |||||||||
int | RESULT_FAILED | Result code that indicates operation failure. | |||||||||
int | RESULT_OK | Result code that indicates successful operation. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
BackupKit(SQLiteDatabase db, String outPath, byte[] key, int flags, String[] tableDesc)
Create and initialize a backup task.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
cancel()
Cancel the current running backup operation.
| ||||||||||
String |
lastError()
Get the last error message.
| ||||||||||
void |
release()
Cleanup and release this backup task.
| ||||||||||
int |
run()
Run backup task.
| ||||||||||
int |
statementCount()
Retrieve total count of statements had been output during the last time
run()
was called. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Flag indicates when database corruption detected, try to read more data if possible rather than return failure immediately.
Flag indicates incremental backup is performed. Incremental backup appends new data to the end of the backup file instead of overwriting. Use this flag with conditional backup to implement incremental backup.
Flag indicates no encryption is used on backup data.
Flag indicates no compression is used on backup data.
Flag indicates no "CREATE TABLE" statement should be output to backup file. When backup file created this way is being recovered, it won't execute "CREATE TABLE" or "CREATE INDEX" statement.
Result code that indicates operation has been cancelled.
Result code that indicates operation failure.
Result code that indicates successful operation.
Create and initialize a backup task.
Conditional or incremental backup can be implemented by passing non-null to tableDesc argument.
tableDesc
should be array with length of a multiple of 2. The elements with
even index are table name white-list to be backed up. Tables not listed are ignored.
The elements with odd index are condition expression used in WHERE-clause when
data to be backed up is selected, which can be null to indicate unconditional selection.
For example, the array listed below tells to
backup only the whole contact
table and message
table with
column id
greater than 100.
new String[] {
"contact", null,
"message", "id > 100",
};
db | database to be backed up. |
---|---|
outPath | path to the output backup file. |
key | key for backup file encryption. Pass null to skip encryption. |
flags | flags to the backup operation. |
tableDesc | table description for conditional backup. |
SQLiteException | when backup operation cannot be initialized. |
---|---|
IllegalArgumentException | when outPath is null. |
Cancel the current running backup operation.
This method can be called on threads other than the one called run()
Calling this method causes run()
to interrupt as quickly as possible and
return RESULT_CANCELED
Get the last error message.
Cleanup and release this backup task. No further operations should be done on this object after calling it.
Run backup task.
Note: this method will not return until backup is finished or cancelled. Do not call this method directly on the main thread or it will probably cause ANR.
RESULT_OK
, RESULT_CANCELED
or RESULT_FAILED
.
Retrieve total count of statements had been output during the last time run()
was called.