Return 1 if the cursor is pointing to a named DB record
@ -1506,6 +1506,13 @@ MDB_txn *mdb_cursor_txn(MDB_cursor *cursor);
*/
MDB_dbi mdb_cursor_dbi(MDB_cursor *cursor);
/** @brief Check if the cursor is pointing to a named database record.
*
* @param[in] cursor A cursor handle returned by #mdb_cursor_open()
* @return 1 if current record is a named database, 0 otherwise.
int mdb_cursor_is_db(MDB_cursor *cursor);
/** @brief Retrieve by cursor.
* This function retrieves key/data pairs from the database. The address and length
@ -9087,6 +9087,18 @@ mdb_cursor_dbi(MDB_cursor *mc)
return mc->mc_dbi;
}
int
mdb_cursor_is_db(MDB_cursor *mc)
{
if (mc && (mc->mc_flags & C_INITIALIZED) && mc->mc_snum) {
MDB_node *leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
if ((leaf->mn_flags & (F_DUPDATA|F_SUBDATA)) == F_SUBDATA)
return 1;
return 0;
/** Replace the key for a branch node with a new key.
* Set #MDB_TXN_ERROR on failure.
* @param[in] mc Cursor pointing to the node to operate on.
@ -272,7 +272,7 @@ int main(int argc, char *argv[])
while ((rc = mdb_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
MDB_dbi db2;
if (memchr(key.mv_data, '\0', key.mv_size-1) || ((char *)key.mv_data)[key.mv_size=1] != '\0')
if (!mdb_cursor_is_db(cursor))
continue;
count++;
rc = mdb_dbi_open(txn, key.mv_data, 0, &db2);
@ -229,7 +229,7 @@ int main(int argc, char *argv[])
if (memchr(key.mv_data, '\0', key.mv_size-1) || ((char *)key.mv_data)[key.mv_size-1] != '\0')
if (rc == MDB_SUCCESS)