objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.41k stars 302 forks source link

Version +3 Bug , can not use string type on any filters while the field type is string #1048

Closed SecretKeeper closed 2 years ago

SecretKeeper commented 2 years ago

i am sure this is bug for version +3.0.0 , because everything work well until 2.9.2-RC4

i have a model like this

@Entity
data class OBKeyValue(
    @Id
    var id: Long = 0,
    var key: String = "",
    var value: String = ""
)

val query = oBKeyValueBox.query().in(OBKeyValue_.key, arrayof("token", "user_id").build()

it throws

None of the following functions can be called with the arguments supplied.

in(Property<OBKeyValue!>!, IntArray!) defined in io.objectbox.query.QueryBuilder
in(Property<OBKeyValue!>!, LongArray!) defined in io.objectbox.query.QueryBuilder

or

val query2 = oBKeyValueBox.query().equal(OBKeyValue_.key, "qqq").build()

and this one throws:

None of the following functions can be called with the arguments supplied.

equal(Property<OBKeyValue!>!, Date!) defined in io.objectbox.query.QueryBuilder
equal(Property<OBKeyValue!>!, Boolean) defined in io.objectbox.query.QueryBuilder
equal(Property<OBKeyValue!>!, ByteArray!) defined in io.objectbox.query.QueryBuilder
equal(Property<OBKeyValue!>!, Long) defined in io.objectbox.query.QueryBuilder

or any other queries it throws given error like this, it should work with String , because key or value field are string and you can use any type except String!!!!!

ONLY for equal you can use new syntax , but this just only work with equal and you can not use in or any other filters!!!: val query = oBKeyValueBox.query(OBKeyValue_.key equal key).build() // works

as i said it just happen on +3.0.0

any ideas?

ajans commented 2 years ago

Yes, I just updated to ObjectBox 3.1.1 and noticed the same error as you. I saw something about this in the changelogs and checked the signature of the equal-function. There is now one variant of the equal-function with String which takes a third argument, StringOrder order:

io.objectbox.query.QueryBuilder#equal(io.objectbox.Property, java.lang.String, io.objectbox.query.QueryBuilder.StringOrder)

The changelog mentions here:

For the existing Query API, String property conditions now require to explicitly specify case. See the documentation of StringOrder for which one to choose (typically StringOrder.CASE_INSENSITIVE).

That should fix it.

The same applies for the in-function.

greenrobot-team commented 2 years ago

@ajans Thanks for the summary!

@ourfamilygithub This project follows semantic versioning. So if there is a major release (e.g. 2.x.x -> 3.x.x) there are likely breaking changes. You can find details about changes in the change log or the releases page here on GitHub.

greenrobot-team commented 2 years ago

Closing as this appears to be resolved. ✅ Feel free to comment with more information or create a new issue.