forked from kuroneko/gosqlite3
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbackup.go
51 lines (43 loc) · 960 Bytes
/
backup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package sqlite3
// #include <sqlite3.h>
import "C"
type Backup struct {
cptr *C.sqlite3_backup
db *Database
}
func NewBackup(d *Database, ddb string, s *Database, sdb string) (b *Backup, e error) {
if cptr := C.sqlite3_backup_init(d.handle, C.CString(ddb), s.handle, C.CString(sdb)); cptr != nil {
b = &Backup{cptr: cptr, db: d}
} else {
if e = d.Error(); e == OK {
e = nil
}
}
return
}
func (b *Backup) Step(pages int) error {
if e := Errno(C.sqlite3_backup_step(b.cptr, C.int(pages))); e != OK {
return e
}
return nil
}
func (b *Backup) Remaining() int {
return int(C.sqlite3_backup_remaining(b.cptr))
}
func (b *Backup) PageCount() int {
return int(C.sqlite3_backup_pagecount(b.cptr))
}
func (b *Backup) Finish() error {
if e := Errno(C.sqlite3_backup_finish(b.cptr)); e != OK {
return e
}
return nil
}
func (b *Backup) Full() error {
b.Step(-1)
b.Finish()
if e := b.db.Error(); e != OK {
return e
}
return nil
}