Esempio n. 1
0
func (c *SQLiteConn) lastError() Error {
	return Error{
		Code:         ErrNo(C.sqlite3_errcode(c.db)),
		ExtendedCode: ErrNoExtended(C.sqlite3_extended_errcode(c.db)),
		err:          C.GoString(C.sqlite3_errmsg(c.db)),
	}
}
Esempio n. 2
0
// LastError returns the error for the most recent failed sqlite3_* API call associated with a database connection.
// (See http://sqlite.org/c3ref/errcode.html)
func (c *Conn) LastError() error {
	if c == nil {
		return errors.New("nil sqlite database")
	}
	errorCode := C.sqlite3_errcode(c.db)
	if errorCode == C.SQLITE_OK {
		return nil
	}
	return &ConnError{c: c, code: Errno(errorCode), msg: C.GoString(C.sqlite3_errmsg(c.db))}
}
Esempio n. 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
}
Esempio n. 4
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
}
Esempio n. 5
0
func (b *Backup) Run(npage int, period time.Duration, c chan<- BackupStatus) error {
	var err error
	for {
		err = b.Step(npage)
		if err != nil {
			break
		}
		if c != nil {
			c <- b.Status()
		}
		time.Sleep(period)
	}
	return b.dst.error(C.sqlite3_errcode(b.dst.db))
}
Esempio n. 6
0
func (b *Backup) Run(npage int, sleepNs int64, c chan<- BackupStatus) os.Error {
	var err os.Error
	for {
		err = b.Step(npage)
		if err != nil {
			break
		}
		if c != nil {
			c <- b.Status()
		}
		time.Sleep(sleepNs)
	}
	return b.dst.error(C.sqlite3_errcode(b.dst.db))
}
Esempio n. 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
}
Esempio n. 8
0
func (self *sqlConnection) sqlErrorCode() int {
	return int(C.sqlite3_errcode(self.handle))
}
Esempio n. 9
0
// libErr reports an error originating in SQLite. The error message is obtained
// from the database connection when possible, which may include some additional
// information. Otherwise, the result code is translated to a generic message.
func libErr(rc C.int, db *C.sqlite3) error {
	if db != nil && rc == C.sqlite3_errcode(db) {
		return &Error{int(rc), C.GoString(C.sqlite3_errmsg(db))}
	}
	return &Error{int(rc), C.GoString(C.sqlite3_errstr(rc))}
}
Esempio n. 10
0
// LastError returns the error for the most recent failed sqlite3_* API call associated with a database connection.
// (See http://sqlite.org/c3ref/errcode.html)
func (c *Conn) LastError() error {
	if c == nil {
		return errors.New("nil sqlite database")
	}
	return &ConnError{c: c, code: Errno(C.sqlite3_errcode(c.db)), msg: C.GoString(C.sqlite3_errmsg(c.db))}
}
Esempio n. 11
0
func fillDBError(dbErr *Error, db *C.sqlite3) {
	// See SQLiteConn.lastError(), in file 'sqlite3.go' at the time of writing (Sept 5, 2016)
	dbErr.Code = ErrNo(C.sqlite3_errcode(db))
	dbErr.ExtendedCode = ErrNoExtended(C.sqlite3_extended_errcode(db))
	dbErr.err = C.GoString(C.sqlite3_errmsg(db))
}
Esempio n. 12
0
func (db *Database) Error() error {
	return Errno(C.sqlite3_errcode(db.handle))
}