getStateByrange-字符串指示的结尾用于精确搜索
当在Java链中使用GetStateByrange(大概还有其他语言)时,搜索“ Asset10”通过“ Asset11”将检索Asset10,以及Asset10之后的字符(例如Asset100,Asset101 ...)。
是否有任何特征或控制序列可以防止这种情况,并且只能检索资产10? Unicode null和字符串的结尾似乎没有任何区别。
When using getStateByRange in Java chaincode (and presumably other languages also), a search for "asset10" through "asset11" will retrieve asset10, and anything with characters after asset10 (e.g. asset100, asset101...).
Is there any character or control sequence to prevent this, and just retrieve asset10? Unicode NULL and end of string don't appear to make any difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Hyperledger织物中的GetStateByrange方法在钥匙上进行了词典搜索。搜索从指定的startkey(包含性)开始,然后升至但不包括指定的endkey(独家)。您还可以指定空字符串(
“”
)来创建一个无限的搜索,该搜索将迭代器返回使用基本键(而不是复合键!)的所有资产。在您的示例中,getStateByrange(“ asset10”,“ asset11”)检索键,例如“ Asset10”,“ Asset100”,“ Asset101”,等等,因为此订购范围在起始和结束范围内,钥匙。
词典排序是指基于其ASCII值的字符串中字符的比较。例如,在ASCII中,“ A”出现在“ B”之前,A“在“ A”之前,等等。因此,当使用GetStateByrange时,按词典进行排序,并且查询根据此顺序返回开始键和端键之间的所有键。
在您的示例中,搜索将“ Asset11”中的最后一个1与第7个字符进行比较,该字符是“ Asset1 0 1”中的0,并确定它在词典上较小,因此将其添加到返回列表。
如果您只想接收资产10,就可以制作:
或使EndKey的最后一个字符成为适合您需求的最小的ASCII角色,也可以是“ Asset10!”例如,因为这将满足您的搜索标准。
The GetStateByRange method in Hyperledger Fabric performs a lexicographical search on the keys. The search starts from the specified startKey (inclusive) and goes up to, but not including, the specified endKey (exclusive). You can also specify the empty string (
""
) to create an unbounded search, that returns an iterator to all assets with basic keys (not composite keys!).In your example, GetStateByRange("asset10", "asset11") retrieves keys such as "asset10", "asset100", "asset101", and so on, because of this ordering as they fall within the range defined by the start and end keys.
Lexicographical ordering means the comparison of characters in a string based on their ASCII values. For example, in ASCII, "a" comes before "b", "A" comes before "a", and so on. Therefore, when using GetStateByRange, keys are sorted lexicographically, and the query returns all keys between the start and end keys based on this ordering.
In your example, the search compares the final 1 in "asset11" to the 7th character, which is a 0 in "asset101" and determines that it is lexicographically smaller, and therefore adds it to the return list.
If you just want to receive asset10, you can make:
Or make the last character of the endKey the smallest ASCII character that suits your needs, it could also be "asset10!" for example, as this would satisfy your search criteria.