Boolean Fields (as CHAR fields in Firebird)

Forum related to Firebird

Moderators: gto, cipto_kh, EgonHugeist

rfwoolf
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 28.09.2008, 20:46

Boolean Fields (as CHAR fields in Firebird)

Postby rfwoolf » 28.09.2008, 21:03

As you know Firebird doesn't have a BOOLEAN field type.
Their "solution" is to create a domain of type CHAR, with length 1, with values "Y" or "N".
But this only causes me problems in Delphi.

1) Does TZTable have a nice way of solving this problem so that the field is read as BOOLEAN?
2) If you're good with Firebird and Delphi, please let me know what else I must do in delphi to be able to treat these fields as BOOLEAN?

seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Postby seawolf » 30.09.2008, 22:26

Firebird does not support boolean fields, so a good way is the creation of a char(1) field .. or ..

delphi has a function called BoolToStr and viceversa, which can be useful for your purposes, but in this case you have to create a varchar(5) as field

rfwoolf
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 28.09.2008, 20:46

Postby rfwoolf » 01.10.2008, 01:21

Hi Seawolf. Thanks for your answer. Yes I already have changed it to length 5 and replaced all the 'Y' with 'True' and all the 'N' with 'False.
This worked fine (and took me hours and hours to do) until I realised that one section of my application now doesn't work because I don't have proper boolean fields.

I have already spent about 4 hours trying to fix it. The easiest solution would be if it could be read as a BOOLEAN field in Delphi - but instead I have to search through probably a few thousand lines of codes changing away from Boolean to String.

What a @#R$#@ing nightmare!

sfxcc
Senior Boarder
Senior Boarder
Posts: 95
Joined: 13.05.2010, 18:48

Boolean Field SOLVED - The best Way to be compatible

Postby sfxcc » 19.05.2010, 22:50

Im having the same problem.

My grid have boolean editor and doesnt work cause is a smallint or a char(1) or (5) field ... (as we like to ).


So there is another way,


Zeos Support for this ?????
How can we request this to zeos team ????

Can be done in fb the next :

CREATE DOMAIN BOOLEAN
AS SMALLINT
CHECK(Value is null or value on (0,1));


IMPORTANT GADGET
IMPORTANT GADGET
IMPORTANT GADGET

So if zeos got the BOOLEAN identifier check if is a number or text ( if text the size 1 or 5)

TbooleanField is a word (B) keep on the record WORDBOOL.
So the record is keep on memory (zeos components control record structure in memory) so they can just check for the DOMAIN name ( filed type) and translate when send to server.

If zeos team develop this, not dificult ( built in on components )
This Just worked fine.


IMPORTANT GADGET
IMPORTANT GADGET
IMPORTANT GADGET PLEASE ZEOS TEAM

Anyway i can do it with some extra code, ill post it when is friendly .. but is much better be Zeos Builtin.

:thanks: :prog2:
where's the code ..

exdatis
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 18.05.2010, 06:27

Postby exdatis » 20.05.2010, 06:48

You can add new field in TZtable(add fields dialog) calculated, then
onCalcFields event:
//procedure...
if table_field.value='Y' then
calc_field.value=True
else
calc_field.value=False;

//set table_field visible false, and calc_field visible true

sfxcc
Senior Boarder
Senior Boarder
Posts: 95
Joined: 13.05.2010, 18:48

Best Way bye now to solve this leaving your code intact.

Postby sfxcc » 20.05.2010, 18:04

This works just perfect.

I was forced to sniff around code to solve this so i did this :

We have on delphi field this code :
- - - - TStringField.GetASBoolean : Boolean;
var
s : string :
begin
s := getasstring;
Result := (length(s)>0)and(S[1] in ['T','t','Y','y']);
end;
This means that if the field is a text at least from 1 char and the 1st char of string is ( T,t,Y,y) as boolean is true Other char is FALSE


USE THEN : VARCHAR(1) or what u want VARCHAR(5) for True or False or Yes or No word but the best is T F ( as SetasBoolean do).

(T or F char will be automatic posted by setasboolean function).




Create this type on your unit ( must be in the unit u ll use setdatatype() procedure ..... )

Type
TMyBoolType = class(TField)
end;


procedure justchangeType(dataset:TDataset);
var
aa: integer;
begin

For aa := 0 to dataset.fields,count - 1 do
if (dataset.fields[aa].datatype = ftString)and(dataset.fields[aa].size=1) then
begin
TMyBoolType(dataset.fields[aa]).setdatatype(ftBoolean);
//this will trick the field type dont do with other field type (only TStringField) or ull get
" Access Error Cant be read as Boolean"
end;

end;


OnDataModuleCreate Do:
begin
justchangeType(MyTable1);
justchangeType(MyTable2);
justchangeType(MyTable3);
end;

Best Way bye now to solve this without change a dbgrid with boolean editor and "works fine" .

Can read and write values withou a problem ( on the oncalc u can only read not write asboolean and with this u can keep all your code intact without any other changes).

[align=justify]/* BEWARE IN CASE U USE A STRING OF VARCHAR BUT NOT FOR THE BOOLEAN (THE BEST IS USE VARCHAR(1) AS DEMO TO GARANTIE YOU WILL NOT HAVE PROBLEMS THEN) */

SO ILL NOT TAKE RESPONSABILITIES FOR ANY KIND OF ERRORS OR DAMAGE ETC ,USE IT AT YOUR OWN RISK.
[/align]
So what i did in SQL :

CREATE DOMAIN BOOLEAN
AS VARCHAR(1)
CHECK(value is null or value in ('T','F'));

CREATE TABLE CoolStuff(
cs_id INTEGER,
cs_dsc VARCHAR(250),
cs_iscool BOOLEAN,
cs_tosell BOOLEAN,
primary key (cs_id)
);




Hope This will Solve problem to all of you , did solve greatly to me.

:cheers: :prog2: :coolp:
where's the code ..

User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Postby mdaems » 26.05.2010, 22:23

Hi,

I'm not an FB expert, but there's some ConvertInterbase6ToSqlType function in ZDbcInterbase6Utils.pas which seems to indicate FB has some kind of boolean type.
Don't know if you can use that to make zeoslib handle booleans in combination with FB, however.

Mark
Image

sfxcc
Senior Boarder
Senior Boarder
Posts: 95
Joined: 13.05.2010, 18:48

Postby sfxcc » 17.03.2012, 15:39

Firebird uses RDB_BOOLEAN = 17 and when Firebird sends this value 17 , which datatype we must use ?
where's the code ..

amarildolacerda
Junior Boarder
Junior Boarder
Posts: 30
Joined: 12.08.2011, 12:42
Location: Brazil
Contact:

Postby amarildolacerda » 28.04.2012, 12:35

it was code in FB 3.0 as you can see at http://asfernandes.blogspot.com.br/


Return to “Firebird”

Who is online

Users browsing this forum: No registered users and 1 guest