Пример #1
0
func (self *KcDb) Close() error {
	defer C.kcdbdel(self.cdb)
	if C.kcdbclose(self.cdb) == kcFalse {
		return errors.New(fmt.Sprintf("close: %s", C.GoString(C.kcecodename(C.kcdbecode(self.cdb)))))
	}
	return nil
}
Пример #2
0
func OpenKcDb(dbFile string) (*KcDb, error) {
	db := new(KcDb)
	cdb := C.kcdbnew()
	cDbFile := C.CString(dbFile + "#type=kch#opts=c#zcomp=lzma#msiz=536870912")
	defer C.free(unsafe.Pointer(cDbFile))
	if C.kcdbopen(cdb, cDbFile, C.KCOWRITER|C.KCOCREATE|C.KCOTRYLOCK) == kcFalse {
		errCode := C.kcdbecode(cdb)
		return nil, errors.New(fmt.Sprintf("open: %s", C.GoString(C.kcecodename(errCode))))
	}
	db.cdb = cdb
	return db, nil
}
Пример #3
0
// Returns a readable string to the last occurred error in the database
func (d *DB) LastError() string {
	errMsg := C.GoString(C.kcecodename(C.kcdbecode(d.db)))
	return errMsg
}
Пример #4
0
func (kc *KCDB) Ecode() int {
	return int(C.kcdbecode(kc.db))
}
Пример #5
0
// LastError returns a KCError instance representing the last occurred error in
// the database.
func (d *DB) LastError() error {
	errMsg := C.GoString(C.kcecodename(C.kcdbecode(d.db)))
	return KCError(errMsg)
}