Beispiel #1
0
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
}
Beispiel #2
0
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*Backup, error) {
	destptr := C.CString(dest)
	defer C.free(unsafe.Pointer(destptr))
	srcptr := C.CString(src)
	defer C.free(unsafe.Pointer(srcptr))

	if b := C.sqlite3_backup_init(c.db, destptr, conn.db, srcptr); b != nil {
		return &Backup{b: b}, nil
	}
	return nil, c.lastError()
}
Beispiel #3
0
func NewBackup(dst *Conn, dstTable string, src *Conn, srcTable string) (*Backup, error) {
	dname := C.CString(dstTable)
	sname := C.CString(srcTable)
	defer C.free(unsafe.Pointer(dname))
	defer C.free(unsafe.Pointer(sname))

	sb := C.sqlite3_backup_init(dst.db, dname, src.db, sname)
	if sb == nil {
		return nil, dst.error(C.sqlite3_errcode(dst.db))
	}
	return &Backup{sb, dst, src}, nil
}
Beispiel #4
0
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*SQLiteBackup, error) {
	destptr := C.CString(dest)
	defer C.free(unsafe.Pointer(destptr))
	srcptr := C.CString(src)
	defer C.free(unsafe.Pointer(srcptr))

	if b := C.sqlite3_backup_init(c.db, destptr, conn.db, srcptr); b != nil {
		bb := &SQLiteBackup{b: b}
		runtime.SetFinalizer(bb, (*SQLiteBackup).Finish)
		return bb, nil
	}
	return nil, c.lastError()
}
Beispiel #5
0
// newBackup initializes an online backup operation from src.srcName to
// dst.dstName.
func newBackup(src *Conn, srcName string, dst *Conn, dstName string) (*Backup, error) {
	srcName += "\x00"
	dstName += "\x00"

	bkup := C.sqlite3_backup_init(dst.db, cStr(dstName), src.db, cStr(srcName))
	if bkup == nil {
		return nil, libErr(C.sqlite3_errcode(dst.db), dst.db)
	}

	b := &Backup{src, dst, bkup}
	runtime.SetFinalizer(b, (*Backup).Close)
	return b, nil
}
Beispiel #6
0
// NewBackup initializes and returns the handle to a backup.
func NewBackup(d *Database, ddb string, s *Database, sdb string) (b *Backup, e error) {
	dname := C.CString(ddb)
	defer C.free(unsafe.Pointer(dname))
	sname := C.CString(sdb)
	defer C.free(unsafe.Pointer(sname))

	if cptr := C.sqlite3_backup_init(d.handle, dname, s.handle, sname); cptr != nil {
		b = &Backup{cptr: cptr, db: d}
	} else {
		e = d.Error()
	}
	return
}
Beispiel #7
0
// NewBackup initializes the backup/copy of the content of one database (source) to another (destination).
// The database name is "main", "temp", or the name specified in an ATTACH statement.
//
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupinit)
func NewBackup(dst *Conn, dstName string, src *Conn, srcName string) (*Backup, error) {
	if dst == nil || src == nil {
		return nil, errors.New("nil sqlite backup source or destination")
	}
	dname := C.CString(dstName)
	sname := C.CString(srcName)

	sb := C.sqlite3_backup_init(dst.db, dname, src.db, sname)
	C.free(unsafe.Pointer(sname))
	C.free(unsafe.Pointer(dname))
	if sb == nil {
		return nil, dst.error(C.sqlite3_errcode(dst.db), "backup init failed")
	}
	return &Backup{sb, dst, src}, nil
}