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. How can I see all of applications source on Eclipse?

Hi guys!

I downloaded android source using Git. However, I have no idea to use
them on Eclipse.

I'd like to develop android application based on original source such
as AlarmClock, Calculator..
I'm not sure if it's possible..
I tried to move application's source files to Eclipse but they have A
LOT of error...

Could anyone tell me how to use and see android source for
applications ??

Thanks~!


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

2. MapView Tutorial - map not shown

Hello everyone,

I'm working on a navigation application and was going through the
MapView Tutorial on the official Android website. I have followed the
instructions in the Map View Tutorial, Obtaining the Maps API key, and
Signing exactly, but no map whatsoever. I'm using Eclipse Ganymed and
SDK 1.5, so according to the Signing section, everything should work
fine - I have JAVA_HOME set up properly as well as PATH pointing to
the java/bin directory, where keytool is located. I also checked the
firewall to see if it was blocking Eclipse or the emulator, resolved
that, but still no map! What else can I try to have the map shown?

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

3. How should I use BatteryManager to get battery states?

4. How do i Autoscroll the ListView with some specified time interval

5. How to create a simple list of names, with personal image for each row

6. Stack Over Flow Error on using SDK 1.5_r1

7. Streaming WMV & Watch It Using G1 Device