dbCheckbox not updating - delphi

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

dbCheckbox not updating - delphi

Post by marsheng » Tue 05 Jun 2018 13:20

I have a dbcheckbox and the changes are not being recorded. I can check and uncheck the box but nothing is stored.

In MySql I tried setting the type to Char(1), Bit, Int(1) and binary. Char and Binary do not cause Delphi to crash. In the fieldkind of Delphi, all MySql fields come through as fkData.

In the object inspector, Delphi seems to know what is TStringField and TIntegerField but there is no where to change this type.

Not sure how to go forward other than writing code.
Thanks Wallace.

ViktorV
Devart Team
Posts: 2413
Joined: Wed 30 Jul 2014 07:16

Re: dbCheckbox not updating - delphi

Post by ViktorV » Thu 07 Jun 2018 09:07

To solve your task, you can use the system type tinyint(1). For example:

Code: Select all

BoolField tinyint(1)
When working with MySQL, UniDAC creates a TBooleanField for these fields.
Also you can use Data Type Mapping for fields of the system type Bit. Before connecting, you can set the following rule Data Type Mapping:

Code: Select all

MyConnection.DataTypeMap.AddDBTypeRule(myBit, ftBoolean);
This rule will be applied to the data of the system type Bit. To use constants myBit you need to add MyDataTypeMap unit in the uses section.
Also, you can map data of the system type Bit using the 'Field Name' of the needed columns:

Code: Select all

MyQuery.DataTypeMap.AddFieldNameRule(YourFieldName, ftBoolean);

marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Re: dbCheckbox not updating - delphi

Post by marsheng » Thu 07 Jun 2018 09:58

Thanks Viktor

tinyInt(1) worked and Delphi sees this as a Boolean field. Not sure why Delphi doesn't recognize an actual Boolean field.

Cheers Wallace.

ViktorV
Devart Team
Posts: 2413
Joined: Wed 30 Jul 2014 07:16

Re: dbCheckbox not updating - delphi

Post by ViktorV » Thu 07 Jun 2018 10:55

It is good to see that the problem has been solved.
Feel free to contact us if you have any further questions about our products.

Post Reply