2
auto index = table.get_index<N(exp)>();
auto upper = index.upper_bound(100);
for(auto itr = index.begin(); itr != upper; ) {
    itr = index.erase(itr);
}

above is not work, who can give me an exmaple

1 Answer 1

3

From your code I assume you want to delete all entries on the table that have less than 100 exp.

The biggest problem I see here is not limiting how many items you delete from the table. As in this code you can possibly be telling the contract to delete 1000's of items in a single action. Which causes a "transaction took too long" error.

void eraseFromTable(int count) {
    auto index = table.get_index<N(exp)>();
    auto upper = index.upper_bound(100);
    for(auto itr = index.begin(); count > 0 && itr != upper; count--) {
        itr = index.erase(itr);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.