Esempio n. 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
}
Esempio n. 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
}
Esempio n. 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
}
Esempio n. 4
0
func EcodeName(ecode int) string {
	return C.GoString(C.kcecodename(C.int32_t(ecode)))
}
Esempio n. 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)
}