2

How do we query tables in EOS? Specifically like the WHERE clause in SQL Database?

I see examples that uses iterator to find if the record exists, however I don't see it as the right approach specially if we have large sets of data.

I can use get and find for the primary key, but what about for other keys?

1

You can use primary key or index to query the data.

For the query where, the index provide find and lower_bound and upper_bound method, which returns the iterator, if you have more than one rows, just use code like it below:

while(iter != xxx.end()) {
   iter++;
}

for lower_bound or upper_bound, or

while(iter != xxx.end() && iter->yourdata == yourquery) {
   iter++;
}

for find.

  • I think the second condition needs to be != aswell. Otherwise the loop will just check the first element and finish then. – TeeAttack42 Jul 12 '18 at 7:02
  • @TeeAttack42 if you use find method, means that you want to get all the same data with your query, so use == – Jimmy Guo Jul 12 '18 at 7:05
  • Yes but the index needs to be build on that value to use find. If you want to query a value the index is not build upon you can't use find and this condition because the loop will be likely to stop after the first element. So maybe the code/answer should get some context. – TeeAttack42 Jul 12 '18 at 7:37
  • I see, so there's really no way for us to avoid the use of iterator for this kind situation? Thanks! – Dominic Jul 12 '18 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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