multi index table 循环删除(eos循环删除表记录)

版权声明:转载请说明出处 https://blog.csdn.net/weixin_39842528/article/details/86716460

业务上需要对一个游戏下的所有赌注进行删除,之前遍历游戏下赌注的时候用的for循环进行的遍历,习惯性的在下面添加了erase一直失败,又因为EOS渣渣般的debug信息输出,实在找不到原因。代码如下:

auto idx = bets.get_index<N(bygameid)>();
for (auto bet_itr = idx.find(game.id); bet_itr != idx.end(); bet_itr++) {
    idx.erase(bet_itr);
}

怀疑跟索引获取的时间有关,所以干脆改成用while并将索引的获取放到了循环内,完美解决。具体原因后面有时间再研究了,业务上要做的东西太多,只能先不求甚解了。

while (true) {
    auto idx = bets.get_index<N(bygameid)>();
    auto bet_itr = idx.find(game.id);
    if (bet_itr == idx.end()) {
        break;
    }
    idx.erase(bet_itr);
}

猜你喜欢

转载自blog.csdn.net/weixin_39842528/article/details/86716460