Closed JamesGay473 closed 4 years ago
Nice work. Thanks.
This issue is being tracked here: https://issues.couchbase.com/browse/CBL-609
For reasons that I do not entirely understand, this is expected behavior. The information that the value at a particular key is a boolean is lost during the conversion to a Map. The underlying type used to represent a boolean is Long: in the map, the value is type Long. This behavior is buried deep in our data representation and is not likely to change. Closing, with some embarrassment, as "works as designed"
I wouldn't say expected behavior, but SQLite itself has no boolean type, only integers, and we have some tweaks in our query code to preserve the distinction. It looks like they're not working in this case, for some reason.
Reopening on advice from @snej
This is a bug in LiteCore. Fixed in https://github.com/couchbase/couchbase-lite-core/commit/da4791a9f0d0de8e79b2161f70c7011ba146c6e6 ... currently on the dev branch, which is being merged to master "soon".
Hi both - thanks for looking into this and for the information about the issue. Sounds like it was a pain to fix so really appreciate your efforts!
This has been fixed on master
. Unfortunately, there are still other problems on that branch, so I don't recommend trying it just yet. Will ping when it gets stable again
Even after the fix is out, it's better to follow Postel's Law (be lenient in what you accept) and not assume a specific boxed type. There are other circumstances where LiteCore cannot tell that a value is a boolean and will treat it as an int: basically any time the value comes from a SQLite operator/function. So a == b
has integer type, as does s LIKE 'foo'
.
Does this mean that, in Java, the correct way to handle things that might be Booleans is to get them as Objects and test their type?
Honestly it's been so long since I used Java, I don't remember what the boxed classes look like. But it sounds like yes, you would have to test whether it's a Boolean or not.
@JamesGay473 HEAD on master is in pretty good shape, now, if you are interested in trying the fix.
I've filed an additional bug, https://issues.couchbase.com/browse/CBL-658, to track fixing the cases that @snej mentions above
Hey!
I've encountered a small issue with CBL 2.6.2 CE whereby if an explicit projection is specified for a
Query
andtoMap()
is called on theResult
then values in the map which are expected to beBoolean
are actually returned asLong
(where 'true' =1L
and 'false' =0L
).I thought originally that this might be linked to CBL-49 but the issue doesn't seem to occur when
SelectResult.all()
is used as demonstrated by this existing unit test: https://github.com/couchbase/couchbase-lite-java/blob/c3f003dea33037f6172dbf9a337b65d5519768e2/lib/src/shared/test/java/com/couchbase/lite/QueryTest.java#L1627I've modified that test to highlight the issue but if you would like any more information then let me know.