Hi John,
just spent a bit of time playing around with this. In order to replicate the working environment, I have performed these tests via MapBasic scripts compiled to .mbx and then run, as opposed to doing everything from the MapBasic window in MapInfo.
If I leave my driver settings as they are (i.e. treating Bools as Char) then the problem remains that I will need to distinguish between a database and regular setup:
In a regular native-type setup, I can do a Select query on a table based on a logical column being True or False. In most cases we'll have something like
dim lLogical as logical
lLogical = 'determined in the code
Select * From some_table Where logical_column = lLogical
In a database setup, I open the same table but the logical column is now Char(1). The table has 11 rows, all but 1 are "F".
Dim lLogical as Logical
lLogical = True
Select * From some_table Where logical_column = lLogical selects all records, not just 1.
If I change it to Select * From some_table Where logical_column = "T" then it gives me the correct result. Alternatively I could have Where logical_column = Str$(lLogical), and this also gives the correct result. So with this last method I could get around having a 'If DBMS_Setup Else'-block before each query on logical columns, but I'd still need to go and do this in our code.
So then I changed my driver settings to not treat Bools as Char. I re-uploaded my test table to the database with EasyLoader, and the logical column is now stored as Boolean and the correct values have been retained for each row. Browsing the table (opened as a live table) the values are displayed as 0 for False, 1 for true, as expected. But the same Select query, with the lLogical variable set to True now selects all records when it should only select 1. This seems weird given that True is defined as 1 in the MapBasic.def file, the values in the table are listed as 1 or 0 in the table, so I would have expected this to work. Weirder still is that if I change it to ‘select where logical_column = 1’ (or ‘select where logical_column = True’) I get a data type mismatch error.
Then, given the bug you described, I changed the value from 1 to 0 in the MapInfo browser window for 1 record, and committed this change back to the db. But when browsing the table in pgAdmin it shows the recently changed value correctly so the logical column can’t have been read-only.
So to sum this up, leaving treat Bools as Char would mean that I either have 2 different select queries for databse and regular setups, or use the Str$() function (which would still require trailing through the existing code). If I change my driver settings, the problem is that I also can’t query a logical column based on the value of a variable or even simply 1 or True. In both cases I think it is fair to say that it doesn’t work as one would expect!
Interested to hear what you make of this...
Cheers,
Alex