Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

querying boolean column #17

Closed
timmer3 opened this issue Feb 21, 2013 · 4 comments
Closed

querying boolean column #17

timmer3 opened this issue Feb 21, 2013 · 4 comments

Comments

@timmer3
Copy link

timmer3 commented Feb 21, 2013

i can see that a boolean column is mapped internally by SqLite to an Integer DataType. no problem with that. but has anyone been able to use Sugar to query a boolean column?

one of my class has this variable:

boolean Sync;

when i try: MyRecord.find(MyRecord.class, "Sync = 0")
it returns no records, even though there are records there with Sync set to false. i've tried all variations on Sync=FALSE sync=false etc.

the strange thing is, if i query for "Sync > 0" i get all the records regardless of the True/False status of the records. can anyone shed some light on this? am i using the wrong syntax?

apologies in advance. new to Java...

@arekolek
Copy link

arekolek commented Aug 9, 2013

You could try:

MyRecord.find(MyRecord.class, "Sync = 'false'");

Or, better yet:

MyRecord.find(MyRecord.class, "Sync = ?", "false");

That's because of the inconsistency I mentioned in #27 I believe it should work with 0 and 1, but instead it maps booleans using String.valueOf, hence "true" and "false" in the database.

On a different note, you might want to take a look at http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html#naming, specifically "If the name you choose consists of only one word, spell that word in all lowercase letters".

@satyan
Copy link
Collaborator

satyan commented Aug 27, 2013

I agree with @arekolek on this and modified the storage types to 0 and 1 for boolean types. If you use it as library, it should store as 0 and 1 now. Also, there's some improvement to the inflate logic to allow for both primitive as well as Object types. Do try it out and let me know if that suits your purpose.

@satyan satyan closed this as completed Aug 27, 2013
@tsuharesu
Copy link

@satyan you changed the way you storage Boolean type but didn changed the way you return it. It's always returning false.

http://github.com/satyan/sugar/blob/master/library/src/com/orm/SugarRecord.java#L284

I changed it to cursor.getString(cursor.getColumnIndex(colName)).equals("1")); and it work right, now.

Sorry, I can't make a pull request, but is only this line that need to be changed.

@satyan
Copy link
Collaborator

satyan commented Sep 19, 2013

@tsuharesu my bad.. it's corrected now. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants