forked from mirror/go-sqlite3
Changed interface for backup step
This commit is contained in:
parent
f4a65d9497
commit
6d40aa115a
23
backup.go
23
backup.go
|
@ -13,15 +13,6 @@ type Backup struct {
|
||||||
b *C.sqlite3_backup
|
b *C.sqlite3_backup
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsDone(err error) bool {
|
|
||||||
sqlErr, ok := err.(Error)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return sqlErr.Code == ErrDone
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*Backup, error) {
|
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*Backup, error) {
|
||||||
destptr := C.CString(dest)
|
destptr := C.CString(dest)
|
||||||
defer C.free(unsafe.Pointer(destptr))
|
defer C.free(unsafe.Pointer(destptr))
|
||||||
|
@ -34,12 +25,18 @@ func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*Backup,
|
||||||
return nil, c.lastError()
|
return nil, c.lastError()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Backup) Step(p int) error {
|
// Backs up for one step. Calls the underlying `sqlite3_backup_step` function.
|
||||||
|
// This function returns a boolean indicating if the backup is done and
|
||||||
|
// an error signalling any other error. Done is returned if the underlying C
|
||||||
|
// function returns SQLITE_DONE (Code 101)
|
||||||
|
func (b *Backup) Step(p int) (bool, error) {
|
||||||
ret := C.sqlite3_backup_step(b.b, C.int(p))
|
ret := C.sqlite3_backup_step(b.b, C.int(p))
|
||||||
if ret != 0 {
|
if ret == 101 {
|
||||||
return Error{Code: ErrNo(ret)}
|
return true, nil
|
||||||
|
} else if ret != 0 {
|
||||||
|
return false, Error{Code: ErrNo(ret)}
|
||||||
}
|
}
|
||||||
return nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Backup) Remaining() int {
|
func (b *Backup) Remaining() int {
|
||||||
|
|
1
error.go
1
error.go
|
@ -45,7 +45,6 @@ var (
|
||||||
ErrNotADB = ErrNo(26) /* File opened that is not a database file */
|
ErrNotADB = ErrNo(26) /* File opened that is not a database file */
|
||||||
ErrNotice = ErrNo(27) /* Notifications from sqlite3_log() */
|
ErrNotice = ErrNo(27) /* Notifications from sqlite3_log() */
|
||||||
ErrWarning = ErrNo(28) /* Warnings from sqlite3_log() */
|
ErrWarning = ErrNo(28) /* Warnings from sqlite3_log() */
|
||||||
ErrDone = ErrNo(101)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (err ErrNo) Error() string {
|
func (err ErrNo) Error() string {
|
||||||
|
|
Loading…
Reference in New Issue