Trouble putting boolean values into postgres

From: richard terry <rterry(at)gnumed(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Trouble putting boolean values into postgres
Date: 2008-02-03 21:36:57
Message-ID: 200802040836.57168.rterry@gnumed.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I'm having trouble saving the contents of a checkbox value into my postgres
database.

CREATE TABLE contacts.data_addresses
(
pk serial NOT NULL,
street text NOT NULL,
fk_town integer NOT NULL,
preferred_address boolean,
postal_address boolean,
head_office boolean,
fk_type integer,
CONSTRAINT data_addresses_pkey PRIMARY KEY (pk)
)

In my code (this was in gambas basic)

I have a class file call cAddress, which contains amongst a few others these
lines:

PUBLIC preferred_address AS Boolean
PUBLIC postal_address AS Boolean

In my main form which contains a couple of check boxes, when I collect data I
do the following:

currentAddress = New cAddress

When I collect the data I've entered I do this

currentAddress preferred_address = chkpreferredAddress.value
currentAddress postal_address = chkPostalAddress.value
currentAddress .HeadOffice = FALSE  (which I want to be false here)

I then have a file I call modContactsDBI which contains all the sql calls to
my postgres database, which I call from the form as follows:

modContactsDBI.person_address_save(currentAddress, currentPerson.pk)

in modContactsDBI the subroutine is this:

PUBLIC SUB person_address_save(address AS cAddress, pk_person AS Integer)

In this routine I construct the sql to send to the database from the values in
passed to the routine

bla bla...
sql = sql & address.preferred_address & ", "
sql = sql & address.postal_address & ", "
etc....

What happens is interesting in the the sql ends up looking like this:

Insert into data_addresses (street, fk_town, postal_address,
preferred,head_office) VALUES("1 Any Street",922,T,T, , 1)

Note the section here ************T,T, , *******************

ie what was True in the chkPostal checkbox (ie TRUE) ends up as a T, which
postgres spits the dummy at, and what was Head_Office which I set to False
(or even if another chbox.value was FALSE, there ends up nothing in its spot
in the query, as shown above (the blank space between the two comma's.

If I cut and paste the query from the console into pgadmin and substitute the
text TRUE, TRUE, FALSE, then it works,

Any ideas, thanks in advance.

Richard

Browse pgsql-novice by date

  From Date Subject
Next Message Peter Jackson 2008-02-04 12:28:59 User Auth.
Previous Message Andreas Kretschmer 2008-02-03 18:48:26 Re: Where clause...