2 Replies Latest reply: Aug 2, 2014 7:14 AM by 2724282 RSS

    Get record by recno

    2724282

      I want to get record by record number using cursor. I use btree, which is configured to support recno (pdb->set_flags(DB_RECNUM);

      I found how to get recno by record and it work:

      unsigned int Recno()
        {
        db_recno_t recno;
        Dbt numValue;
        memset(&numValue, 0, sizeof(numValue));
        numValue.set_data(&recno);
        numValue.set_ulen(sizeof(recno));
        numValue.set_flags(DB_DBT_USERMEM);
      
      
        //int ret = bdbCursor->c_get(bdbCursor, Key, &data, DB_GET_RECNO)) != 0
        bdbCursor->get(&Key, &numValue, DB_GET_RECNO);
      
      
        return (unsigned int)recno;
        }
      }}{
      

      I trying to do same to get record by recno, but BD just crached and no show error message.

      bool MoveToRecno(db_recno_t recno)
        {
        memset(&Key, 0, sizeof(Key));
        Key.set_data(&recno);
        Key.set_size(sizeof(recno));
        Key.set_flags(DB_DBT_USERMEM);
        int ret = bdbCursor->get(&Key, &Value, DB_SET_RECNO);  //program crached here
        return ret == 0;
       }