Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

kv_table::index::upper_bound() doesn't wrong correctly with secondary keys #1096

Open
Max-B1 opened this issue May 11, 2021 · 0 comments
Open

Comments

@Max-B1
Copy link

Max-B1 commented May 11, 2021

auto cmp = it.key_compare(key);
if (cmp == 0) {
++it;
}

if there are a few exactly the same secondary keys upper_bound(key) == lower_bound(key).
Generic example:

struct record
{
   uint64_t               id;
   std::string            str_key;
   auto by_str_key() const { return std::make_pair(str_key, id); }
};
EOSIO_REFLECT(record, id, str_key)

struct record_table : eosio::kv_table<record>
{
   KV_NAMED_INDEX("by.id"_n, id);
   KV_NAMED_INDEX("by.str.key"_n, by_str_key);
   record_table(eosio::name self)
   {
      init(self, "table"_n, "eosio.kvram"_n, id, by_str_key);
   }
};
//...
   auto t = record_table{get_self()};
   t.put(record{.id = 0, str_key = "first"});
   t.put(record{.id = 1, str_key = "first"});
   t.put(record{.id = 2, str_key = "second"});

   eosio::check(t.by_str_key.lower_bound("first") != t.by_str_key.upper_bound("first"), "upper_bound() doesn't work correctly");
//...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant