Skip to content

Commit

Permalink
Fixed starts-with and index scanning.
Browse files Browse the repository at this point in the history
  • Loading branch information
gcv committed Oct 4, 2009
1 parent 610d068 commit 1af2a2f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/cupboard/db/bdb_je.clj
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,7 @@
<= :back
starts-with :forward
:forward))
;; only two exact-matching comparison functions: = and starts-with
exact (or (= comparison-fn =) (= comparison-fn starts-with))
exact (= comparison-fn =)
;; Use this function to extract the value from the database entry which
;; the cursor points to which matters for this scan.
res-compval-fn (if (db-cursor-primary? db-cursor)
Expand Down
16 changes: 15 additions & 1 deletion src/test/cupboard/db/bdb_je.clj
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
(is (empty? (db-join-cursor-next j)))))))))))


(deftest cursor-scans
(deftest cursor-scans-1
(with-db-sec [idx1 *db-env* *db* "idx1"
:allow-create true
:key-creator-fn :a
Expand Down Expand Up @@ -339,6 +339,20 @@
[ [12 {:a 12}] ])))))


(deftest cursor-scans-2
(with-db-sec [idx1 *db-env* *db* "idx1"
:allow-create true
:key-creator-fn :a
:sorted-duplicates true]
(db-put *db* 1 {:a "abc123"})
(db-put *db* 2 {:a "def456"})
(db-put *db* 3 {:a "def789"})
(db-put *db* 4 {:a "ghi789"})
(with-db-cursor [cur1 idx1]
(is (= (db-cursor-scan cur1 "def" :comparison-fn starts-with)
[ [2 {:a "def456"}] [3 {:a "def789"}] ])))))


(deftest transactions
(let [path (make-temp-dir)]
(with-db-env [e path :allow-create true :transactional true]
Expand Down

0 comments on commit 1af2a2f

Please sign in to comment.