Page 1 of 1

MySQL BOOLEAN = TINYINT(1)

Posted: 19.09.2008, 12:04
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;

Posted: 19.09.2008, 13:13
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