Booleans crash my SQLite INSERT...

by gymshoe » Mon, 29 Sep 2008 21:55:16 GMT

Sponsored Links
 I have successfully created a test database and do not have trouble
inserting records containing text or integers. However, when I try to
insert a boolean value I get an error "no such column:true". (For
speed of execution, I would prefer to be able to just store booleans
in the database "directly", as opposed to using code to convert
boolean values to 0's and 1's).


String Id_ = "007";
Integer age_ = 39;
Boolean spy_ = true;

         + TABLE_NAME
         + " (Id TEXT, Age INTEGER,"
         + " Spy BLOB);");

db.execSQL("INSERT INTO "+ TABLE_NAME +" (Id, Age, Spy)"
        + " VALUES ("+ Id_ + ","+ age_ +","+ spy_+");");

09-29 21:26:11.493: VERBOSE/SQLHelper-onCreate(26139): Table was
created in SQLHelper.onCreate...
09-29 21:26:11.493: ERROR/Database(26139): Failure 1 (no such column:
true) on 0x7a7c8 when preparing 'INSERT INTO table1 (Id, Age, Spy)
VALUES (007,39,true);'.

09-29 21:26:11.503: ERROR/Database(26139): Error executing INSERT INTO
table1 (Id, Age, Spy) VALUES (007,39,true);

09-29 21:26:11.513: DEBUG/AndroidRuntime(26139): Shutting down VM

If I run the same code without the boolean (i.e. only include Id
(string) and age (integer) it works fine. I have tried using TEXT and
INTEGER for the data-format for Spy ("Id TEXT, Age INTEGER, Spy
TEXT"), without effect (not unexpected given manifest typing of
sqlite3).  Finally, I get the same error ("no such column:..") if
instead of saving a boolean to the database, I try to save a Drawable
(using "photo BLOB" syntax).

Upon google search, the only thing I could find which was similar was
a problem with Ruby on Rails (RoR) giving a similar SQLite3 error:
"Does sqlite3 handle booleans differently than MySQL? It seems to
choke when I query based on a boolean. For example: In my controller,
I have this:

@gameweek = Gameweek.find(:first, :conditions => [ "current = true
league_id = ?", ])

In my production log, I get this error:

ActiveRecord::StatementInvalid (SQLite3::SQLException: no such
true: SELECT * FROM gameweeks   WHERE (current = true and league_id =
LIMIT 1): "
Apparently, this RoR problem is resolved by using the following
@gameweek = Gameweek.find(:first, :conditions => [ "current = ? and
league_id = ?",true, ])

So I tried this kind of format for android:
{db.execSQL("INSERT INTO "+ TABLE_NAME + " (Id, Age, Spy)" + " VALUES
("+ Id_ + ","   + age_ +",[?,"+ spy_+"]);");
But this didn't work - maybe it's not quite the right syntax, maybe
because it isn't part of a "WHERE" clause? I don't know.

{Oh, I am still using 0.9SDK, but didn't think it likely related to
Any ideas on how to handle booleans with SQLite (or where else to
look) would be appreciated.



Booleans crash my SQLite INSERT...

by gymshoe » Tue, 30 Sep 2008 10:23:28 GMT

 fter several fruitless hours of google searching, I submitted the
above question. I then got lucky and found the answer...

Basically, just insert the boolean value in single quotes: i.e.


On Sep 29, 3:55pm, gymshoe <[EMAIL PROTECTED]> wrote:

Sponsored Links

Other Threads

1. How to connect to a server that runs on a localhost with the same eclipse program as the emulator?

How to connect to a server that runs on a localhost with the same
eclipse program as the emulator?

i need the emulator to connect to a server
both of them are in the building process so they both
are running on the same eclipse for check
but the emulator for some reason cant connect to the localhost
so can someone plase tell me how can it be done....:)
thnx in advance..

2. What Adapter to use to populate a Spinner dynamically?

I am trying to populate a spinner from a database and I get this exception:

ERROR/AndroidRuntime(1623): java.lang.IllegalStateException:
android.widget.Spinner is not a  view that can be bounds by this

Any example around on how to populate a spinner from a database?




3. ODBC Driver

4. Can Spinner OnItemSelectedListener use View's drawable state to detect drop-down?

5. How to get a GL11Ext instance to call OpenGL Extension functions?

6. Please review my short code !

7. Android app communicating with the "outside"