4
votes

I have following TSQLDataSet in my Delphi 7 application. It is fetching 2 fields (ID and Name) from table MyTable.

object SQLDataSet: TSQLDataSet
    GetMetadata = False
    CommandText = 'select * from MyTable'
    MaxBlobSize = -1
    Params = <>
    SQLConnection = mySQLConnection

    object SQLDataSetID: TIntegerField
      FieldName = 'ID'
      ProviderFlags = [pfInUpdate, pfInWhere, pfInKey]
      Required = True
    end
    object SQLDataSetNAME: TStringField
      FieldName = 'NAME'
      Required = True
      Size = 50
    end
end

When I migrated to the Delphi XE4, I am getting following error:

class EDatabaseError with message 'SQLDataSet: Type mismatch for field 'NAME', expecting: String actual:WideString'

What could be the possible cause of this problem and how should I get rid of it?

Note: I am using firebird 2.5.2.

1
Try changing TStringField to TWideStringFieldZigiZ
@ZigiZ - Thanks for your comments. This will solve the problem but why should I do it. I followed a link isatsara.blogspot.in/2012/01/… where this suggestion was given but I did not get his explanation. Also this one forums.devart.com/viewtopic.php?t=22080 . How should I justify this change to others?user1556433
What is the type in the Firebird database for the NAME field of table MyTable?Jeroen Wiert Pluimers
@JeroenWiertPluimers - It is of varchar(50) type in firebirduser1556433
This sounds like an encoding issue, so please update your answer with: the character set encodings of your database, table and TSQLConnection. The easiest is to have a small DDL of a database plus single table, and the .DFM + .PAS part of a very simple form + connection + dataset. That way we can reproduce your problem. What I think happens is that your database is using some form of Unicode encoding, and the Delphi side of things thinks the encoding is UTF-16 hence expecting WideString.Jeroen Wiert Pluimers

1 Answers

0
votes

Change the TStringField to TWideTStringfield

object SQLDataSet: TSQLDataSet
    GetMetadata = False
    CommandText = 'select * from MyTable'
    MaxBlobSize = -1
    Params = <>
    SQLConnection = mySQLConnection

    object SQLDataSetID: TIntegerField
      FieldName = 'ID'
      ProviderFlags = [pfInUpdate, pfInWhere, pfInKey]
      Required = True
    end
    object SQLDataSetNAME: **TWideStringField**
      FieldName = 'NAME'
      Required = True
      Size = 50
    end
end