Skip to content

Commit 6d40aa1

Browse files
committed
Changed interface for backup step
1 parent f4a65d9 commit 6d40aa1

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

backup.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ type Backup struct {
1313
b *C.sqlite3_backup
1414
}
1515

16-
func IsDone(err error) bool {
17-
sqlErr, ok := err.(Error)
18-
if !ok {
19-
return false
20-
}
21-
22-
return sqlErr.Code == ErrDone
23-
}
24-
2516
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*Backup, error) {
2617
destptr := C.CString(dest)
2718
defer C.free(unsafe.Pointer(destptr))
@@ -34,12 +25,18 @@ func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*Backup,
3425
return nil, c.lastError()
3526
}
3627

37-
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) {
3833
ret := C.sqlite3_backup_step(b.b, C.int(p))
39-
if ret != 0 {
40-
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)}
4138
}
42-
return nil
39+
return false, nil
4340
}
4441

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

error.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ var (
4545
ErrNotADB = ErrNo(26) /* File opened that is not a database file */
4646
ErrNotice = ErrNo(27) /* Notifications from sqlite3_log() */
4747
ErrWarning = ErrNo(28) /* Warnings from sqlite3_log() */
48-
ErrDone = ErrNo(101)
4948
)
5049

5150
func (err ErrNo) Error() string {

0 commit comments

Comments
 (0)