boolean field as selection criteria?

927 views
Skip to first unread message

larham

unread,
Nov 16, 2010, 10:32:11 PM11/16/10
to ORMLite Users
Using latest 4.4 on android, I am trying to track down a problem with
empty results. It may have to do with a boolean field. When I look
at the db contents, I see SMALLINT 1 stored for "true", but when I
look at a query translation, it seems to be using the string 'true' as
the lookup value.

What am I doing wrong?

thanks,

larry

---------------------------------
The object is defined:

@DatabaseTable(tableName = "course")
public class Course extends LoginDependent implements IUpdateable {
@DatabaseField(generatedId = true)
private Integer _id;

...

@DatabaseField(columnName = IS_MY_COLUMN)
private boolean my;

...
----------------------------------
On android emulator, this turns into a SMALLINT field:

sqlite> .schema course
.schema course
CREATE TABLE `course` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT ,
<edit> , `my` SMALLINT );


---------------------------------
When I query I use:

Dao<Course, Integer> dao = getDao(Course.class);
QueryBuilder b = dao.queryBuilder();
b.where().eq(Course.LOGIN_COLUMN, login)
.and()
.eq(Course.IS_MY_COLUMN, Boolean.TRUE);
results.addAll(dao.query(b.prepare()));

----------------------------------
when I debug into the 4.4 core, I see the following command statement
generated at line 77 of StatementBuilder.java

SELECT * FROM `course` WHERE (`login` = 10 AND `my` = 'true' )

and empty results.
----------------------------------

Gray Watson

unread,
Nov 17, 2010, 1:20:54 AM11/17/10
to ormlit...@googlegroups.com
On Nov 16, 2010, at 10:32 PM, larham wrote:

> Using latest 4.4 on android, I am trying to track down a problem with
> empty results. It may have to do with a boolean field. When I look
> at the db contents, I see SMALLINT 1 stored for "true", but when I
> look at a query translation, it seems to be using the string 'true' as
> the lookup value.

I can reproduce this Larry and I'll get a fix out tonight. There were two bugs. One was with query handling of true in general which affected certain database types. Once this was fixed the internal conversion from true/false -> 1/0 was tripping up the Android code.

Sorry for this. I've now added much better testing of querying for all data-types on all database variants.
gray

Larry Hamel

unread,
Nov 18, 2010, 1:23:41 AM11/18/10
to ormlit...@googlegroups.com
Thanks, Gray, 4.5 is working nicely; it's very kind of you to respond quickly. ORMLite is doing a lot of heavy lifting for me, despite its name.

larry

Gray Watson

unread,
Nov 18, 2010, 2:52:27 PM11/18/10
to ormlit...@googlegroups.com
On Nov 18, 2010, at 1:23 AM, Larry Hamel wrote:

> Thanks, Gray, 4.5 is working nicely; it's very kind of you to respond quickly. ORMLite is doing a lot of heavy lifting for me, despite its name.

Great to hear Larry. Thanks also for commenting and giving ORMLite a thumbs up on SourceForge.
gray

Jeff Gonzales

unread,
May 28, 2014, 4:28:16 PM5/28/14
to ormlit...@googlegroups.com
Hi,

I am having a similar problem to this.  I have an Oracle database with a boolean value stored as a 1 or 0 in a column of type NUMBER.  I am using Android ORMlite with the field defined as boolean.  The sqlite database on my device shows this column with "true" and "false" values.  Why is this?  What's worse, the values returned from the QueryBuilder always have "false" as a value.

Has this problem been fixed?  I am using ORMlite 4.48.  Is this the latest version?  I see versions 4.5 through 4.9 but they appear to be old.  What gives?

Thanks,
Jeff

Gray Watson

unread,
Aug 6, 2014, 7:41:56 PM8/6/14
to ORMLite Users
Sorry for the delay dude.

So I'm a little confused which is why I haven't responded sooner. Are you using Oracle or Sqlite? In Oracle the default it to store boolean values as 1 and 0. Android sqlite also should be storing 1 and 0 in the database although both of them convert to/from Java and JDBC/Android formats.

1) So you read entities from Oracle. Are they being read correctly? Do they have the correct boolean fields?
2) When you save the entities to Sqlite, you are saying that the booleans are being converting to true/false? You've dumped the database and seen this?
3) When you read entities from Sqlite. Are they being read correctly? Do they have the correct boolean fields?

How are specifically configuring ORMLite to take between two database types?
gray
> --
> You received this message because you are subscribed to the Google Groups "ORMLite Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ormlite-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jeff Gonzales

unread,
Aug 6, 2014, 8:04:03 PM8/6/14
to ormlit...@googlegroups.com, 256...@gmail.com
Hi Gray,

No problem.  It's been awhile so I will have to look at my notes.

I'm sorry for the confusion before.  I just started a new job and am just learning the ropes for this particular shop's setup.  They are running Oracle on their server, but ORMLite is working with SQLite on our mobile devices (Android).  

If I recall correctly, there was some mismatch between true/false and 0/1 values.  I worked around this problem by using an integer type for that particular column, but I'd like to get to the bottom of this in case I need to use a boolean value in the SQLite database in the future.

I'll write back to you with more details as soon as I can.

Thanks,
Jeff


You received this message because you are subscribed to a topic in the Google Groups "ORMLite Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ormlite-user/V39vwKvQ1sI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ormlite-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages