fix return values of CURSOR-GET and DATABASE-GET

This commit is contained in:
eknauel 2004-11-22 16:58:07 +00:00
parent ed7ab6948e
commit c01134e623
2 changed files with 22 additions and 23 deletions

31
c/bdb.c
View File

@ -997,18 +997,8 @@ s48_value scsh_bdb_get(s48_value handle, s48_value skey,
S48_GC_UNPROTECT(); S48_GC_UNPROTECT();
res = dbp->get(dbp, txnid, &key, &data, flags); res = dbp->get(dbp, txnid, &key, &data, flags);
if (res > 0) CHECK_BDB_RESULT_CODE(res);
s48_raise_os_error(res); return scsh_enter_DBT_as_bytevector(&data);
switch (res) {
case DB_NOTFOUND:
case DB_KEYEMPTY:
return s48_enter_integer(res);
break;
default:
CHECK_BDB_RESULT_CODE(res);
return scsh_enter_DBT_as_bytevector(&data);
}
} }
/* Delete DBT to corresponding key */ /* Delete DBT to corresponding key */
@ -1074,24 +1064,29 @@ s48_value scsh_bdb_close_cursor(s48_value scursor)
} }
/* retrieve values from cursor */ /* retrieve values from cursor */
s48_value scsh_bdb_cursor_cget(s48_value dbc, s48_value sflags) s48_value scsh_bdb_cursor_cget(s48_value dbc, s48_value skey,
s48_value sflags)
{ {
int res; int res;
DBC* dbcp; DBC* dbcp;
u_int32_t flags; u_int32_t flags;
DBT *key, *data; DBT key, data;
S48_DECLARE_GC_PROTECT(2); S48_DECLARE_GC_PROTECT(3);
S48_GC_PROTECT_2(dbc, sflags); S48_GC_PROTECT_3(dbc, skey, sflags);
memset(&key, 0, sizeof(DBT)); memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT)); memset(&data, 0, sizeof(DBT));
scsh_extract_bytevector_as_DBT(skey, &key);
dbcp = scsh_extract_cursor(dbc); dbcp = scsh_extract_cursor(dbc);
flags = s48_extract_integer(sflags); flags = s48_extract_integer(sflags);
S48_GC_UNPROTECT(); S48_GC_UNPROTECT();
res = dbcp->c_get(dbcp, key, data, flags); res = dbcp->c_get(dbcp, &key, &data, flags);
CHECK_BDB_RESULT_CODE(res); CHECK_BDB_RESULT_CODE(res);
return scsh_enter_DBT_as_bytevector(data); return scsh_enter_DBT_as_bytevector(&data);
} }
/* return a count of duplicates */ /* return a count of duplicates */

View File

@ -368,7 +368,7 @@
;;; DB Cursor : DBC ;;; DB Cursor : DBC
(define-record-type cursor :cursor (define-record-type cursor :cursor
(make-cursor c-pointer) (really-make-cursor c-pointer)
cursor? cursor?
(c-pointer cursor-c-pointer)) (c-pointer cursor-c-pointer))
@ -975,15 +975,19 @@
result))))) result)))))
(import-lambda-definition bdb-cursor-cget-int (import-lambda-definition bdb-cursor-cget-int
(db-handle flags) (cursor key flags)
"scsh_bdb_cursor_cget") "scsh_bdb_cursor_cget")
(define (cursor-get cursor . args) (define (cursor-get cursor key . args)
(let-optionals args (let-optionals args
((flags (or (current-flags) '()))) ((flags (or (current-flags) '())))
(let ((result (bdb-cursor-cget-int cursor (flags->value flags)))) (let ((result
(bdb-cursor-cget-int cursor key (flags->value flags))))
(if (integer? result) (if (integer? result)
(raise-bdb-condition result) (if (or (= result (return-code-value (return-code not-found)))
(= result (return-code-value (return-code key-empty))))
#f
(raise-bdb-condition result))
result)))) result))))
(define (cursor-get/fork . args) (define (cursor-get/fork . args)