fix return values of CURSOR-GET and DATABASE-GET
This commit is contained in:
parent
ed7ab6948e
commit
c01134e623
27
c/bdb.c
27
c/bdb.c
|
@ -997,19 +997,9 @@ s48_value scsh_bdb_get(s48_value handle, s48_value skey,
|
|||
S48_GC_UNPROTECT();
|
||||
res = dbp->get(dbp, txnid, &key, &data, flags);
|
||||
|
||||
if (res > 0)
|
||||
s48_raise_os_error(res);
|
||||
|
||||
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 */
|
||||
s48_value scsh_bdb_del(s48_value handle, s48_value skey,
|
||||
|
@ -1074,24 +1064,29 @@ s48_value scsh_bdb_close_cursor(s48_value scursor)
|
|||
}
|
||||
|
||||
/* 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;
|
||||
DBC* dbcp;
|
||||
u_int32_t flags;
|
||||
DBT *key, *data;
|
||||
S48_DECLARE_GC_PROTECT(2);
|
||||
DBT key, data;
|
||||
S48_DECLARE_GC_PROTECT(3);
|
||||
|
||||
S48_GC_PROTECT_2(dbc, sflags);
|
||||
S48_GC_PROTECT_3(dbc, skey, sflags);
|
||||
memset(&key, 0, sizeof(DBT));
|
||||
memset(&data, 0, sizeof(DBT));
|
||||
|
||||
scsh_extract_bytevector_as_DBT(skey, &key);
|
||||
dbcp = scsh_extract_cursor(dbc);
|
||||
flags = s48_extract_integer(sflags);
|
||||
|
||||
S48_GC_UNPROTECT();
|
||||
|
||||
res = dbcp->c_get(dbcp, key, data, flags);
|
||||
res = dbcp->c_get(dbcp, &key, &data, flags);
|
||||
|
||||
CHECK_BDB_RESULT_CODE(res);
|
||||
return scsh_enter_DBT_as_bytevector(data);
|
||||
return scsh_enter_DBT_as_bytevector(&data);
|
||||
}
|
||||
|
||||
/* return a count of duplicates */
|
||||
|
|
|
@ -368,7 +368,7 @@
|
|||
|
||||
;;; DB Cursor : DBC
|
||||
(define-record-type cursor :cursor
|
||||
(make-cursor c-pointer)
|
||||
(really-make-cursor c-pointer)
|
||||
cursor?
|
||||
(c-pointer cursor-c-pointer))
|
||||
|
||||
|
@ -975,15 +975,19 @@
|
|||
result)))))
|
||||
|
||||
(import-lambda-definition bdb-cursor-cget-int
|
||||
(db-handle flags)
|
||||
(cursor key flags)
|
||||
"scsh_bdb_cursor_cget")
|
||||
|
||||
(define (cursor-get cursor . args)
|
||||
(define (cursor-get cursor key . args)
|
||||
(let-optionals args
|
||||
((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)
|
||||
(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))))
|
||||
|
||||
(define (cursor-get/fork . args)
|
||||
|
|
Loading…
Reference in New Issue