]> git.sur5r.net Git - openldap/commitdiff
Add MDB_GET_CURRENT
authorHoward Chu <hyc@symas.com>
Wed, 19 Sep 2012 13:15:09 +0000 (06:15 -0700)
committerHoward Chu <hyc@symas.com>
Wed, 19 Sep 2012 13:15:09 +0000 (06:15 -0700)
return whatever the cursor is currently pointing at

libraries/libmdb/mdb.c
libraries/libmdb/mdb.h

index c0eb6252c25ff0b6022d14f522e7ee24b68d8415..807294c28dda61904cedad5dc4512be67469b11e 100644 (file)
@@ -4261,6 +4261,33 @@ mdb_cursor_get(MDB_cursor *mc, MDB_val *key, MDB_val *data,
        assert(mc);
 
        switch (op) {
+       case MDB_GET_CURRENT:
+               if (!mc->mc_flags & C_INITIALIZED) {
+                       rc = EINVAL;
+               } else {
+                       MDB_page *mp = mc->mc_pg[mc->mc_top];
+                       if (!NUMKEYS(mp)) {
+                               mc->mc_ki[mc->mc_top] = 0;
+                               rc = MDB_NOTFOUND;
+                               break;
+                       }
+                       rc = MDB_SUCCESS;
+                       if (IS_LEAF2(mp)) {
+                               key->mv_size = mc->mc_db->md_pad;
+                               key->mv_data = LEAF2KEY(mp, mc->mc_ki[mc->mc_top], key->mv_size);
+                       } else {
+                               MDB_node *leaf = NODEPTR(mp, mc->mc_ki[mc->mc_top]);
+                               MDB_GET_KEY(leaf, key);
+                               if (data) {
+                                       if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
+                                               rc = mdb_cursor_get(&mc->mc_xcursor->mx_cursor, data, NULL, MDB_GET_CURRENT);
+                                       } else {
+                                               rc = mdb_node_read(mc->mc_txn, leaf, data);
+                                       }
+                               }
+                       }
+               }
+               break;
        case MDB_GET_BOTH:
        case MDB_GET_BOTH_RANGE:
                if (data == NULL || mc->mc_xcursor == NULL) {
index 7fc1bf217ee6c6305c3d944aa19d5cb501a467ae..925bf17d37f7fbb3d8590c80b8a75a3abe4ed3dc 100644 (file)
@@ -229,6 +229,7 @@ typedef enum MDB_cursor_op {
                                                                Only for #MDB_DUPSORT */
        MDB_GET_BOTH,                   /**< Position at key/data pair. Only for #MDB_DUPSORT */
        MDB_GET_BOTH_RANGE,             /**< position at key, nearest data. Only for #MDB_DUPSORT */
+       MDB_GET_CURRENT,                /**< Return key/data at current cursor position */
        MDB_GET_MULTIPLE,               /**< Return all the duplicate data items at the current
                                                                 cursor position. Only for #MDB_DUPFIXED */
        MDB_LAST,                               /**< Position at last key/data item */