Hello,
I have a problem with the boolean fields.
I connected a PgDataSource to a PGtable. The table linked to the PGTable contains one boolean field. I also connected the PgDataSource with the standard DBGrid shipped with Delphi.
When I open the table I have the boolean column showing True/False correctly. I can change the value by typing True/False or T/F in the DBGrid but if I type Yes/No or y/n or 0/1 or on/off I have an error message "Yes is not a valid boolean value for field xxxx".
I double checked and ran an update query from pgAdmin shipped with PosgtreSQL and all the combinations above are accepted and the value of the fields are amended accordingly.
How can I fix this in PGDac ?
Many thanks
Pio Pio
Boolean fields
Re: Boolean fields
Hello,
If, when setting a boolean field value from Grid, the standard TBooleanField.SetAsString method described in the DB.pas module is used, in which the comparison occurs as follows:
then, as shown in the example, the following values are allowed for False: F, Fa, Fal, Fals and False; for True - T, Tr, Tru and True, respectively.
If you want to use any other values for input, you should create an OnSetText event handler for your Boolean field, for example:
If, when setting a boolean field value from Grid, the standard TBooleanField.SetAsString method described in the DB.pas module is used, in which the comparison occurs as follows:
Code: Select all
if AnsiCompareText(Value, Copy(FTextValues[False], 1, L)) = 0 then
SetAsBoolean(False)
else
if AnsiCompareText(Value, Copy(FTextValues[True], 1, L)) = 0 then
SetAsBoolean(True)
else
DatabaseErrorFmt(SInvalidBoolValue, [Value, DisplayName]);
If you want to use any other values for input, you should create an OnSetText event handler for your Boolean field, for example:
Code: Select all
procedure TForm1.PgTable1f_boolSetText(Sender: TField; const Text: String);
begin
if AnsiIndexText(Text,['On', 'Yes', 'Y','1']) > -1 then
TBooleanField(Sender).AsBoolean := True
else if AnsiIndexText(Text,['Off', 'No', 'N', '0']) > -1 then
TBooleanField(Sender).AsBoolean := False
else
DatabaseErrorFmt(SInvalidBoolValue, [Text, Sender.DisplayName]);
end;
Re: Boolean fields
Hello again,
I have added the code you suggest but I get an error message on the line "DatabaseErrorFmt(SInvalidBoolValue, [Text, Sender.DisplayName]);" because the identifier SInvalidBoolValue in not declared. Do I have to include any unit ?
As Yes/No or y/n or 0/1 or on/off are accepted by default by PostgreSQL http://www.postgresql.org/docs/9.1/stat ... olean.html I suggest to include them in the values accepted by default.
I have added the code you suggest but I get an error message on the line "DatabaseErrorFmt(SInvalidBoolValue, [Text, Sender.DisplayName]);" because the identifier SInvalidBoolValue in not declared. Do I have to include any unit ?
As Yes/No or y/n or 0/1 or on/off are accepted by default by PostgreSQL http://www.postgresql.org/docs/9.1/stat ... olean.html I suggest to include them in the values accepted by default.
Re: Boolean fields
Hello,
The SInvalidBoolValue constant is described in the DBConsts.pas standard module. As I wrote before, validation of the values assigned to TBooleanField is performed in the DB.pas standard module, and we cannot modify this behaviour, therefore you should offer your suggestions to modify this functionality to Embarcadero developers.
The SInvalidBoolValue constant is described in the DBConsts.pas standard module. As I wrote before, validation of the values assigned to TBooleanField is performed in the DB.pas standard module, and we cannot modify this behaviour, therefore you should offer your suggestions to modify this functionality to Embarcadero developers.