[yunqa.de] Re: how to search for boolean value

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Tue, 30 Jun 2009 12:46:12 +0200

At 15:24 29.06.2009, Rael Bauer wrote:

>I have a field in sqlite database declared as BOOLEAN, and also set it's value 
>with 
>Dataset.FieldByName('bool_field').AsBoolean. 

DISQLite3 does not have a BOOLEAN field type. If you declare a field as 
BOOLEAN, DISQLite3 will assign a NUMERIC type affinity to it.

The recommended representation of boolean values is INTEGER: 1 stands for true, 
0 = false. Storage for 0 and 1 values is optimized. The TDISQLite3UniDirQuery 
class wrapper follows this recommendation.

>If I view the table in SQLite Spy then values show up as true or false.

Just like DISQLite3, SQLiteSpy does not know BOOLEAN values. I suppose you 
should see 1 or 0, but not "true" of "false".

>How do I construct a sql statement to search on such a boolean value, e.g:
>select * from table where bool_field = TRUE.

Following the above recommendation, you should do it like this:

  CREATE TABLE t (b INTEGER);
  INSERT INTO t VALUES (1);
  INSERT INTO t VALUES (0);

  SELECT * FROM t WHERE b;

Ralf 

_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: