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).


CODE:

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

db.execSQL("CREATE TABLE IF NOT EXISTS "
         + TABLE_NAME
         + " (Id TEXT, Age INTEGER,"
         + " Spy BLOB);");


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

LOGCAT:
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
and
league_id = ?", @league.id ])

In my production log, I get this error:

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


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
that...}
Any ideas on how to handle booleans with SQLite (or where else to
look) would be appreciated.

thanks,
Jim


--~--~---------~--~----~------------~-------~--~----~



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...

http://forums.realsoftware.com/viewtopic.php?f=3&t=3974&hilit=+no+such+column+

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

Jiim




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


Sponsored Links


Other Threads

1. Saving images from MMS

Just curious if there is any ideas or apps in progress that would allow some 
attachment management? Like saving images from an MMS or being able to save 
mp3 files from emails. I have picture messages and don't see an option to 
save perhaps I'm missing something. Any input on this would be helpful.

Thanks,
O.

--~--~---------~--~----~------------~-------~--~----~

2. Any Android Suggestion Page

Hi,

Can anyone tell me if there is any Android Suggestion Page where I can
post suggestions.
I'm a member of AndroidForums.com and there are many very good ideas
in there.
It would be sad if the Android Developers don't get to know them.

Thanks to all that helped make Android be like it is now!

kind regards,

Oberox

--~--~---------~--~----~------------~-------~--~----~

3. Ad supported applications

4. Lunar Lander "game loop" (was: How fast is the T-Mobile G1?)

5. How to access Android Market without a G1? (Where to find one's submitted app)

6. Components overlap

7. new version of 1.0?