Skip to content

Commit f87f73c

Browse files
committed
Merge pull request #130 from shuhaowu/sqlite-backup-step-done-check
Added an IsDone method for backup
2 parents 9d2ae37 + 6d40aa1 commit f87f73c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

backup.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*Backup,
2525
return nil, c.lastError()
2626
}
2727

28-
func (b *Backup) Step(p int) error {
28+
// Backs up for one step. Calls the underlying `sqlite3_backup_step` function.
29+
// This function returns a boolean indicating if the backup is done and
30+
// an error signalling any other error. Done is returned if the underlying C
31+
// function returns SQLITE_DONE (Code 101)
32+
func (b *Backup) Step(p int) (bool, error) {
2933
ret := C.sqlite3_backup_step(b.b, C.int(p))
30-
if ret != 0 {
31-
return Error{Code: ErrNo(ret)}
34+
if ret == 101 {
35+
return true, nil
36+
} else if ret != 0 {
37+
return false, Error{Code: ErrNo(ret)}
3238
}
33-
return nil
39+
return false, nil
3440
}
3541

3642
func (b *Backup) Remaining() int {

0 commit comments

Comments
 (0)