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

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

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

Post by Ludek » Wed 12 Oct 2011 08:28

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.

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Post by Ludek » Wed 12 Oct 2011 09:34

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.

AndreyZ

Post by AndreyZ » Fri 14 Oct 2011 08:45

SDAC dataset components inherit fields compatibility checking from the TDataSet component. You can use your way to receive errors in this case.

Post Reply