Hello Ian,
At 13:07 09/03/2004 -0600, Ian Bicking wrote:
>Clifford Ilkay wrote:
[snip]
>>Anyway, now I can insert but, SQLObject always inserts a "t" regardless
>>of whether I specify the boolean should be true or false. Here is the code:
>>
>>>>>from SQLObject import *
>>>>>conn = PostgresConnection('user=cilkay dbname=testdb')
>>>>>class Person(SQLObject):
>>... _connection = conn
>>... firstName = StringCol()
>>... lastName = StringCol()
>>... isMember = BoolCol()
>>...
>>
>>>>>Person.createTable()
>>>>>p = Person.new(firstName="Donald", lastName="Duck", isMember="t")
>>>>>p = Person.new(firstName="Mickey", lastName="Mouse", isMember="f")
>>>>>p = Person.new(firstName="Minnie", lastName="Mouse", isMember="0")
>>>>>p = Person.new(firstName="Pluto", lastName="Dog", isMember="False")
>>>>>p = Person.new(firstName="Goofy", lastName="Dog", isMember="false")
>
>Those are all "true" values in the Python sense (any non-empty string is
>considered true). 0 (the integer) or None or False are all false in the
>Python sense.
Thank you very much for pointing out this simple error on my part. Once I
used isMember=False or isMember=True, it worked as expected.
>>testdb=# select * from person;
>> id | last_name | is_member | first_name
>>----+-----------+-----------+------------
>> 1 | Duck | t | Donald
>> 2 | Mouse | t | Mickey
>> 3 | Mouse | t | Minnie
>> 4 | Dog | t | Pluto
>> 5 | Dog | t | Goofy
>>(5 rows)
>>As you can see, I tried various ways of expressing "False" but none of
>>them seemed to work. What am I missing? Also, why is the order of the
>>columns not the same as the order that was specified in the class definition?
>
>I'm not sure what you mean by the order.
According to the docs, the SQL create script that SQLObject would execute
when we run Person.tableCreate() for the above class should be:
create table person (
id int primary key autoincrement,
first_name text,
last_name text,
is_member boolean
);
If you look at the output of the describe table below, you will notice that
the order of the columns is not as we would have expected if the SQL create
script were actually as above.
testdb=# \d person
Table "public.person"
Column | Type | Modifiers
------------+---------+------------------------------------------------------
id | integer | not null default nextval('public.person_id_seq'::text)
last_name | text |
is_member | boolean |
first_name | text |
Indexes:
"person_pkey" primary key, btree (id)
If the order of the columns is not as one would expect, that would wreck
INSERT statements that rely on the position of columns rather than the
absolute name of the columns. This is probably not a problem in SQLObject
but it could be if one uses other tools to manipulate the same database.
Regards,
Clifford Ilkay
Dinamis Corporation
3266 Yonge Street, Suite 1419
Toronto, Ontario
Canada M4N 3P6
Tel: 416-410-3326
|