2

Given: Records stored as a simple string DatabaseEntry key-value, keys looks like:

  1. NODE_1
  2. NODE_1_PROP_1
  3. NODE_1_PROP_2
  4. NODE_1_PROP_3
  5. NODE_2
  6. NODE_2_PROP_1
  7. NODE_2_PROP_2
  8. NODE_2_PROP_3

How to: Select only records which IDs starts with NODE_1, result 1-4 ?

I’ve used Cursor.getNext(), but general problem with Cursor class is that it keeps going to the next record, so if I would go in that way I’ll have to evaluate key prefix every time in order to stop when cursor will be on NODE_2.

Rrr
  • 1,747
  • 3
  • 17
  • 22

2 Answers2

0

You need to use secondary database. The idea of secondary database is you provide additional criteria for every record. So given your example, you need to provide secondary key creator, which will take "NODE_1_PROP_1" and return "NODE_1" as it's secondary key. Then you may query secondary database for "NODE_1" and it will return all records having the "NODE_1" as key prefix. The key point is that you not only using keys, but any appropriate content of your record. Make sure you allow sorted duplicates in secondary database.

HTH.

jdevelop
  • 12,176
  • 10
  • 56
  • 112
0

I've solved this through transforming string to binary arrays, is this case NODE_1_PROP_1 will go before NODE_2, which is the issue when I've used strings as a keys.

Rrr
  • 1,747
  • 3
  • 17
  • 22