예제 #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)),
	}
}
예제 #2
0
파일: sqlite.go 프로젝트: npowern/gosqlite
// 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))}
}
예제 #3
0
파일: sqlite.go 프로젝트: vaibhav2800/forge
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
}
예제 #4
0
파일: backup.go 프로젝트: gidden/cloudlus
// 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
}
예제 #5
0
파일: sqlite.go 프로젝트: vaibhav2800/forge
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))
}
예제 #6
0
파일: sqlite.go 프로젝트: pcgod/grumble
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))
}
예제 #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
}
예제 #8
0
파일: low.go 프로젝트: lye/go-db-sqlite3
func (self *sqlConnection) sqlErrorCode() int {
	return int(C.sqlite3_errcode(self.handle))
}
예제 #9
0
파일: util.go 프로젝트: gidden/cloudlus
// 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))}
}
예제 #10
0
파일: sqlite.go 프로젝트: pkf/gosqlite
// 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))}
}
예제 #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))
}
예제 #12
0
파일: database.go 프로젝트: rwj/gosqlite3
func (db *Database) Error() error {
	return Errno(C.sqlite3_errcode(db.handle))
}