MySQL BOOLEAN = TINYINT(1)

Code patches written by our users to solve certain "problems" that were not solved, yet.

Moderators: gto, cipto_kh, EgonHugeist, mdaems

Post Reply
karpik
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 25.07.2008, 14:04

MySQL BOOLEAN = TINYINT(1)

Post by karpik »

in some cases (ex JvDBGrid) it is helpfull to have BooleanField
instead of TSmallIntField (checkboxes in grid)

unfortunately this patch only disables exception for persistent fields
I dont know how to deal with dynamic fields autodetection

maybe someone else can do this

Code: Select all

procedure TZAbstractRODataset.CheckFieldCompatibility(Field: TField;FieldDef: TFieldDef);

(...)
  CheckTypeSizes = [ftBytes, ftVarBytes, ftBCD, ftReference];

begin
+  {MySQL BOOLEAN = TINYINT(1)}
+  if (Field.DataType = ftBoolean) and (FieldDef.DataType = ftSmallint) then
+    exit
+  else
  with Field do
  begin
    if (BaseFieldTypes[DataType] <> BaseFieldTypes[FieldDef.DataType]) then
      DatabaseErrorFmt(SFieldTypeMismatch, [DisplayName,
        FieldTypeNames[DataType], FieldTypeNames[FieldDef.DataType]], Self);
    if (DataType in CheckTypeSizes) and (Size <> FieldDef.Size) then
        DatabaseErrorFmt(SFieldSizeMismatch, [DisplayName, Size,
          FieldDef.Size], Self);
  end;
end;
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

You could try to change the ConvertMySQLTypeToSQLType function (ZdbcMysqlUtils.pas) to return stBoolean instead of stShort. This is done for the ENUM('Y','N') fields now. I'm afraid this will cause conflicts when updating records. Maybe even when reading records. So to implement this we would need to add a property to the query for switching between enum-bools and tinyint bools.

Adding this feature in the official zeoslib package looks quite ambitious to me as it would probably require heavy changes.

Mark
Image
Post Reply