Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ejdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,14 @@ func (ejdb *Ejdb) GetColl(colname string) (*EjColl, *EjdbError) {
ejcoll.ejdb = ejdb
ejcoll.ptr = (*[0]byte)(unsafe.Pointer(C.ejdbgetcoll((*C.struct_EJDB)(unsafe.Pointer(ejdb.ptr)), c_colname)))

return ejcoll, ejdb.check_error()
if ejcoll.ptr == nil {
currentError := ejdb.check_error()
if currentError == nil {
currentError = &EjdbError{9000, errors.New("No such collection")}
}
return nil, currentError
}
return ejcoll, nil
}

// Return a slice containing shallow copies of all collection handles (EjColl) currently open.
Expand Down
11 changes: 11 additions & 0 deletions ejdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ func TestGetColl(t *testing.T) {
}
}

func TestGetCollWrongColl(t *testing.T) {
ejdb := open()
coll, err := ejdb.GetColl("NonExistent")
if coll != nil {
t.Error("GetColl() should return nil coll ")
}
if err == nil {
t.Error("GetColl() should return an error")
}
}

func TestGetColls(t *testing.T) {
ejdb := open()
ejdb.CreateColl("MyNewColl", nil)
Expand Down