Пример #1
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
}
Пример #2
0
// Open opens a database.
//
// There are constants for the modes: READ and WRITE.
//
// READ indicates read-only access to the database, and WRITE indicates read
// and write access to the database (there is no write-only mode).
func Open(dbfilepath string, mode int) (*DB, error) {
	d := &DB{db: C.kcdbnew(), mode: mode, Path: dbfilepath}
	dbname := C.CString(dbfilepath)
	defer C.free(unsafe.Pointer(dbname))
	cMode := C.uint32_t(C.KCOREADER)
	if mode > READ {
		cMode = C.KCOWRITER | C.KCOCREATE
	}
	if C.kcdbopen(d.db, dbname, cMode) == 0 {
		errMsg := d.LastError()
		return nil, KCError(fmt.Sprintf("Error opening %s: %s", dbfilepath, errMsg))
	}
	return d, nil
}
Пример #3
0
func New() *KCDB {
	db := C.kcdbnew()
	return &KCDB{db}
}