1. llibra
  2. kcdbm


llibra  committed ee1e330

Implemented KC.CUR.LOW:GET and KC.CUR:GET.

  • Participants
  • Parent commits ea424d0
  • Branches default

Comments (0)

Files changed (3)

File src/cur.lisp

View file
  • Ignore whitespace
     (body #'kccurgetvalue "Can't get the value of the current record."
           cur step)))
+(defun get (cur step)
+  (let ((step (convert-to-foreign step :boolean)))
+    (with-foreign-objects ((key-len 'size_t)
+                           (value-buf :pointer)
+                           (value-len 'size_t))
+      (aif/ptr (kccurget cur key-len value-buf value-len step)
+               (values it
+                       (mem-aref key-len 'size_t)
+                       (mem-aref value-buf :pointer)
+                       (mem-aref value-len 'size_t))
+               (error cur "Can't get the data of the current record.")))))
 (in-package :kc.cur)
 (flet ((body (fn cur step as)
     (body #'kc.cur.base:get-key cur step as))
   (defun get-value (cur step &key (as :string))
     (body #'kc.cur.base:get-value cur step as)))
+(defun get (cur step &key (as :string))
+  (let ((as (if (consp as) as (cons as as))))
+    (multiple-value-bind (key-buf key-len value-buf value-len)
+        (kc.cur.base:get cur step)
+      (with-kcmalloced-pointer (key-buf key-buf)
+        (with-kcmalloced-pointer (value-buf value-buf)
+          (values (foreign-string->x (car as) key-buf key-len)
+                  (foreign-string->x (cdr as) value-buf value-len)))))))

File src/packages.lisp

View file
  • Ignore whitespace
 (defpackage :kyoto-cabinet.cursor.base
   (:nicknames :kc.cur.base)
   (:use :cl :cffi :kc.ffi :kc.type :kc.var :kc.conv :kc.util)
-  (:shadow :error :delete)
-  (:export :error :db :delete :jump :with-cursor :get-key :get-value))
+  (:shadow :error :delete :get)
+  (:export :error :db :delete :jump :with-cursor :get-key :get-value :get))
 (defpackage :kyoto-cabinet.cursor.low-level
   (:nicknames :kc.cur.low)
   (:use :kc.cur.base)
-  (:export :get-key :get-value))
+  (:export :get-key :get-value :get))
 (defpackage :kyoto-cabinet.cursor
   (:nicknames :kc.cur)
   (:use :cl :cffi :kc.ffi :kc.type :kc.var :kc.conv :kc.util :kc.cur.base)
-  (:shadow :get-key :get-value)
+  (:shadow :get-key :get-value :get)
   (:shadowing-import-from :kc.cur.base :error :delete)
-  (:export :error :db :delete :jump :with-cursor :get-key :get-value))
+  (:export :error :db :delete :jump :with-cursor :get-key :get-value :get))

File t/cur.lisp

View file
  • Ignore whitespace
           (lambda (c) (kc.cur:get-value c nil))
           (lambda (v) (equal "1" v)))))
+(5am:test get/low/value
+  (with-new-db (db)
+    (kc.db:set db "x" "1")
+    (kc.cur:with-cursor (cur db)
+      (multiple-value-bind (key-buf key-len value-buf value-len)
+          (kc.cur.low:get cur nil)
+        (kc.util:with-kcmalloced-pointer (key-buf key-buf)
+          (kc.util:with-kcmalloced-pointer (value-buf value-buf)
+            (flet ((->string (buf len)
+                     (cffi:foreign-string-to-lisp buf :count len)))
+              (let ((key (->string key-buf key-len))
+                    (value (->string value-buf value-len)))
+                (5am:is (equal "x" key))
+                (5am:is (equal "1" value))))))))))
+(5am:test get/value
+  (with-new-db (db)
+    (kc.db:set db "x" "1")
+    (kc.cur:with-cursor (cur db)
+      (multiple-value-bind (key value) (kc.cur:get cur nil)
+        (5am:is (equal "x" key))
+        (5am:is (equal "1" value))))))
 (flet ((body (fn)
          (with-new-db (db)
            (kc.db:set db "x" "1")
   (5am:test (get-value/low/step :compile-at :definition-time)
     (body (lambda (cur step)
             (kc.ffi:kcfree (kc.cur.low:get-value cur step)))))
+  (5am:test (get/low/step :compile-at :definition-time)
+    (body (lambda (cur step)
+            (multiple-value-bind (kb kl vb vl) (kc.cur.low:get cur step)
+              (declare (ignore kl vl))
+              (kc.ffi:kcfree kb)
+              (kc.ffi:kcfree vb)))))
   (5am:test (get-key/step :compile-at :definition-time)
     (body #'kc.cur:get-key))
   (5am:test (get-value/step :compile-at :definition-time)
-    (body #'kc.cur:get-value)))
+    (body #'kc.cur:get-value))
+  (5am:test (get/step :compile-at :definition-time)
+    (body #'kc.cur:get)))