Beispiel #1
0
func (kc *KCDB) Open(filename string, mode int) (err error) {
	name := C.CString(filename)
	defer C.free(unsafe.Pointer(name))
	if C.kcdbopen(kc.db, name, C.uint32_t(mode)) == 0 {
		err = kc.error()
	}
	return
}
Beispiel #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
}
Beispiel #3
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
}