Board index » delphi » Sybase SQL Anywhere (Watcom SQL) and Delphi

Sybase SQL Anywhere (Watcom SQL) and Delphi

For anyone using Sybase SQL Anywhere and Delphi, is there a way to have a
field in a SQL table strictly a boolean?  There is no data type, so I've
had to use a CHAR(1) field and control what is entered through a
TDBCheckBox.  The problem with this is that users can still enter any
character into this field if they use another tool.  

Has anyone come up with a solution for boolean fields?  Thanks for any
suggestions!

Marcus Chapman
mchap...@mstarlabs.com

 

Re:Sybase SQL Anywhere (Watcom SQL) and Delphi


In <331F3068.1...@mstarlabs.com>, Marcus Chapman <mchap...@mstarlabs.com> writes:

Quote
>For anyone using Sybase SQL Anywhere and Delphi, is there a way to have a
>field in a SQL table strictly a boolean?  There is no data type, so I've
>had to use a CHAR(1) field and control what is entered through a
>TDBCheckBox.  The problem with this is that users can still enter any
>character into this field if they use another tool.  

>Has anyone come up with a solution for boolean fields?  Thanks for any
>suggestions!

>Marcus Chapman
>mchap...@mstarlabs.com

SQL Anywhere provides a type, BIT.  BIT is a small int that can only take the
values NULL, 0, 1.  It emulates a BOOLEAN and works great.

----Pat Victorio.

Re:Sybase SQL Anywhere (Watcom SQL) and Delphi


Quote
vict...@exis.net wrote:

> In <331F3068.1...@mstarlabs.com>, Marcus Chapman <mchap...@mstarlabs.com> writes:
> >For anyone using Sybase SQL Anywhere and Delphi, is there a way to have a
> >field in a SQL table strictly a boolean?  There is no data type, so I've
> >had to use a CHAR(1) field and control what is entered through a
> >TDBCheckBox.  The problem with this is that users can still enter any
> >character into this field if they use another tool.

> >Has anyone come up with a solution for boolean fields?  Thanks for any
> >suggestions!

> >Marcus Chapman
> >mchap...@mstarlabs.com

> SQL Anywhere provides a type, BIT.  BIT is a small int that can only take the
> values NULL, 0, 1.  It emulates a BOOLEAN and works great.

> ----Pat Victorio.

Try making a user defined type, say BOOLEAN, and constraining it to
'T' and 'F'

This will work:

CREATE DOMAIN Boolean     CHAR(1)     CHECK (@col IN ('T', 'F'));

Marshall Watts
wa...@inlink.com

Re:Sybase SQL Anywhere (Watcom SQL) and Delphi


Quote
Marcus Chapman <mchap...@mstarlabs.com> wrote:
>For anyone using Sybase SQL Anywhere and Delphi, is there a way to have a
>field in a SQL table strictly a boolean?  There is no data type, so I've
>had to use a CHAR(1) field and control what is entered through a
>TDBCheckBox.  The problem with this is that users can still enter any
>character into this field if they use another tool.  
>Has anyone come up with a solution for boolean fields?  Thanks for any
>suggestions!
>Marcus Chapman
>mchap...@mstarlabs.com

We have had the same problem and found that even when using a BIT
field (SQLAny uses a TINYINT for this) Delphi still picks the field up
as a TSmallIntField NOT a TBooleanField meaning you cant use
'AsBoolean'.

We often need to dump our tables from Sybase system 11 to SQLAny so we
needed to make the usage of bools in our apps consistent across the
two dbms's (and probably more dbms's later).

Our solution was to create 2 functions

        function  AsBool(pField :TField):Boolean;
        function  PutBool(pField:TField; pValue :Boolean):boolean;

which are used instead of saying .AsBoolean and take into account the
field type in the table.

eg.     PutBool(Field,True) translates to Field.AsInteger := 1 on
SQLAny
        and writes the bool straight out on Sys11.

Other Threads