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. Timing and using Intent MediaAction.ImageCapture to take pictures

I'm still working only on the emulator, but I am seeing some unexpected behavior when using an Intent to take a picture via MediaAction.ImageCapture. At first, I thought everything was working as I wished: from my application, control was transferred to the Camera application, which allowed me to take a picture, review it, and then control transferred back to my original application. I did notice that the picture taken seemed to be the same regardless of how long I waited, and since the 2.1 emulator has a moving block in the picture stream, that seemed odd. The block should have been in a different location depending on when I took the picture. After adding more logging, it appears that the picture is being taken immediately, but control doesn't transfer back to my application, it stays in the camera, until I've taken another picture and accepted it. I would prefer the first behavior, put the user in Camera mode, let them take and review the picture, and then return to my application. Has anyone else dealt with this in a way other than writing your own camera app? I know that there is also an outstanding issue having to do with image size, but I'm hoping by the time I'm finished with the rest of my application, some of the Intent/MediaAction stuff will have been resolved, like picture resolution. Thanks, Ray --

2. $200 per live wallpaper

paying $200 per original, cool, live wallpaper for 2.1

hit me up with ideas or your portfolio. thanks!


3. Help with listview!

4. play audio file from weblink in android

5. Picasa web album sync with nx1

6. urgent help Integrating code with Android home screen code.

7. Adding contacts to a custom account