Page 1 of 1

column datatype changed, no error in app, but corrupted data

Posted: Wed 12 Oct 2011 08:28
by Ludek
Hi Devart,
I currently changed datatype in one table from smallint to int, changed nothing in sources, the exe runs. BUT: the shown values are corrupted! for example, if the table contains value 666666, the exe shows 11306.
I know, I need to change TSmallintField to TIntegerField. But, I think, the sdac should somehow warn/raise an exception, i find this EXTREMELY dangerous for data validity!

Please help me, how could i avoid the data corruption. The source has >1000000 lines of code and about 100 columns have been changed (typically foreign keys)

Thanks, Ludek.

Posted: Wed 12 Oct 2011 09:34
by Ludek
solved myself, in custom subclass overriden a protected virtual method

Code: Select all

procedure TMyMSQuery.CheckFieldCompatibility(Field: TField;
  FieldDef: TFieldDef);
begin
  if (field.datatype = ftSmallint) and (fielddef.datatype = ftInteger) then
    DatabaseErrorFmt(SFieldTypeMismatch, [field.DisplayName,
      FieldTypeNames[field.DataType], FieldTypeNames[FieldDef.DataType]], Self)
  else
    inherited;
end;
and using one hack (see Hallvard's blog) also replaced the same VMT item directly in TMSQuery. Now I'm getting the errors.

Posted: Fri 14 Oct 2011 08:45
by AndreyZ
SDAC dataset components inherit fields compatibility checking from the TDataSet component. You can use your way to receive errors in this case.