Commits

Anonymous committed e6fb8be

expose open flags, and error codes

  • Participants
  • Parent commits cb40992

Comments (0)

Files changed (3)

     ...
 
     kc := cabinet.New()
-    err = kc.Open("some_db.kch")
+    err = kc.Open("some_db.kch", cabinet.KCOWRITER | cabinet.KCOCREATE)
     err = kc.Set([]byte("hello"), []byte("world"))
     world, err = kc.Get([]byte("hello"))
     err = kc.Close()
 to use any byte array as either key or value. An example from the test
 suite to read an integer out of the database:
 
+    var n int64
     v, err = kc.Get([]byte("numbers"))
     binary.Read(bytes.NewBuffer(v), binary.BigEndian, &n)
 
 
 CONSTANTS
 
+const KCEBROKEN int = C.KCEBROKEN
+
+const KCEDUPREC int = C.KCEDUPREC
+
+const KCEINVALID int = C.KCEINVALID
+
+const KCELOGIC int = C.KCELOGIC
+
+const KCEMISC = C.KCEMISC
+
+const KCENOIMPL int = C.KCENOIMPL
+
+const KCENOPERM int = C.KCENOPERM
+
+const KCENOREC int = C.KCENOREC
+
+const KCENOREPOS int = C.KCENOREPOS
+
+const KCESUCCESS int = C.KCESUCCESS
+
+const KCESYSTEM = C.KCESYSTEM
+
 const KCMADD int = C.KCMADD
 
 const KCMAPPEND int = C.KCMAPPEND
 
 const KCMSET int = C.KCMSET
 
+const KCOAUTOSYNC int = C.KCOAUTOSYNC
+
+const KCOAUTOTRAN int = C.KCOAUTOTRAN
+
+const KCOCREATE int = C.KCOCREATE
+
+const KCONOLOCK int = C.KCONOLOCK
+
+const KCONOREPAIR = C.KCONOREPAIR
+
+const KCOREADER int = C.KCOREADER
+
+const KCOTRUNCATE int = C.KCOTRUNCATE
+
+const KCOTRYLOCK int = C.KCOTRYLOCK
+
+const KCOWRITER int = C.KCOWRITER
+
+
+FUNCTIONS
+
+func EcodeName(ecode int) string
+
 
 TYPES
 
 
 func (kcc *KCCUR) Del()
 
+func (kcc *KCCUR) Ecode() int
+
+func (kcc *KCCUR) Emsg() string
+
 func (kcc *KCCUR) Get(advance bool) (k, v []byte, err os.Error)
 
 func (kcc *KCCUR) GetKey(advance bool) (k []byte, err os.Error)
 
 func (kc *KCDB) Dump(filename string) (err os.Error)
 
+func (kc *KCDB) Ecode() int
+
 func (kc *KCDB) EndTran(commit bool) (err os.Error)
 
 func (kc *KCDB) Get(key []byte) (value []byte, err os.Error)
 
 func (kc *KCDB) Merge(sdbs []*KCDB, mode int) (err os.Error)
 
-func (kc *KCDB) Open(filename string) (err os.Error)
+func (kc *KCDB) Open(filename string, mode int) (err os.Error)
 
 func (kc *KCDB) Path() (path string, err os.Error)
 
 
 func (kc *KCDB) Values() (out chan []byte)
 
+
+SUBDIRECTORIES
+
+	.hg
     ...
 
     kc := cabinet.New()
-    err = kc.Open("some_db.kch")
+    err = kc.Open("some_db.kch", cabinet.KCOWRITER | cabinet.KCOCREATE)
     err = kc.Set([]byte("hello"), []byte("world"))
     world, err = kc.Get([]byte("hello"))
     err = kc.Close()
 to use any byte array as either key or value. An example from the test 
 suite to read an integer out of the database:
 
+    var n int64
     v, err = kc.Get([]byte("numbers"))
     binary.Read(bytes.NewBuffer(v), binary.BigEndian, &n)
 
 	"unsafe"
 )
 
+const KCOREADER int = C.KCOREADER
+const KCOWRITER int = C.KCOWRITER
+const KCOCREATE int = C.KCOCREATE
+const KCOTRUNCATE int = C.KCOTRUNCATE
+const KCOAUTOTRAN int = C.KCOAUTOTRAN
+const KCOAUTOSYNC int = C.KCOAUTOSYNC
+const KCONOLOCK int = C.KCONOLOCK
+const KCOTRYLOCK int = C.KCOTRYLOCK
+const KCONOREPAIR = C.KCONOREPAIR
+
+const KCESUCCESS int = C.KCESUCCESS
+const KCENOIMPL int = C.KCENOIMPL
+const KCEINVALID int = C.KCEINVALID
+const KCENOREPOS int = C.KCENOREPOS
+const KCEBROKEN int = C.KCEBROKEN
+const KCENOPERM int = C.KCENOPERM
+const KCEDUPREC int = C.KCEDUPREC
+const KCENOREC int = C.KCENOREC
+const KCELOGIC int = C.KCELOGIC
+const KCESYSTEM = C.KCESYSTEM
+const KCEMISC = C.KCEMISC
+
+const KCMADD int = C.KCMADD
+const KCMSET int = C.KCMSET
+const KCMAPPEND int = C.KCMAPPEND
+const KCMREPLACE int = C.KCMREPLACE
+
 type KCDB struct {
 	db *C.KCDB
 }
 	return &KCDB{db}
 }
 
-func (kc *KCDB) error() os.Error {
-	err := C.kcecodename(C.kcdbecode(kc.db))
-	return os.NewError(C.GoString(err))
+func (kc *KCDB) Ecode() int {
+	return int(C.kcdbecode(kc.db))
 }
 
-func (kc *KCDB) Open(filename string) (err os.Error) {
+func EcodeName(ecode int) string {
+	return C.GoString(C.kcecodename(C.int32_t(ecode)))
+}
+
+func (kc *KCDB) error() os.Error {
+	return os.NewError(EcodeName(kc.Ecode()))
+}
+
+func (kc *KCDB) Open(filename string, mode int) (err os.Error) {
 	name := C.CString(filename)
 	defer C.free(unsafe.Pointer(name))
-	if C.kcdbopen(kc.db, name, C.KCOWRITER|C.KCOCREATE) == 0 {
+	if C.kcdbopen(kc.db, name, C.uint32_t(mode)) == 0 {
 		err = kc.error()
 	}
 	return
 	return
 }
 
-const KCMADD int = C.KCMADD
-const KCMSET int = C.KCMSET
-const KCMAPPEND int = C.KCMAPPEND
-const KCMREPLACE int = C.KCMREPLACE
-
 func (kc *KCDB) Merge(sdbs []*KCDB, mode int) (err os.Error) {
 	count := len(sdbs)
 	csdbs := make([]*C.KCDB, count)
 	return
 }
 
+func (kcc *KCCUR) Ecode() int {
+	return int(C.kccurecode(kcc.cur))
+}
+
+func (kcc *KCCUR) Emsg() string {
+	err := C.kccuremsg(kcc.cur)
+	return C.GoString(err)
+}
+
 func (kcc *KCCUR) error() os.Error {
-	err := C.kccuremsg(kcc.cur)
-	return os.NewError(C.GoString(err))
+	return os.NewError(kcc.Emsg())
 }
 
 func (kcc *KCCUR) Del() {
 		for {
 			k, err := cur.GetKey(true)
 			if err != nil {
-				log.Printf("GetKey(true): %s", err)
+				if cur.Ecode() != KCENOREC {
+					log.Printf("GetKey(true): %s", err)
+				}
 				break
 			}
 			out <- k
 		for {
 			v, err := cur.GetValue(true)
 			if err != nil {
-				log.Printf("GetValue(true): %s", err)
+				if cur.Ecode() != KCENOREC {
+					log.Printf("GetValue(true): %s", err)
+				}
 				break
 			}
 			out <- v
 		for {
 			k, v, err := cur.Get(true)
 			if err != nil {
-				log.Printf("Get(true): %s", err)
+				if cur.Ecode() != KCENOREC {
+					log.Printf("Get(true): %s", err)
+				}
 				break
 			}
 			out <- &Item{k, v}

File cabinet_test.go

 
 func newCabinet(t *testing.T, filename string) *KCDB {
 	kc := New()
-	err := kc.Open(filename)
+	err := kc.Open(filename, KCOWRITER | KCOCREATE )
 	if err != nil {
 		t.Fatalf("Open(): %s", err)
 	}