PostgreSQL - Type mismatch (Expecting: String actual: Memo)

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
eduardomendes
Posts: 28
Joined: Wed 24 Feb 2010 14:08

PostgreSQL - Type mismatch (Expecting: String actual: Memo)

Post by eduardomendes » Mon 09 May 2011 14:32

My situation (Unidac for Delphi7 Version 3.70.0.17):

ProviderName = PostgreSQL (version 8.4)

TUniquery component has only one field declared:
TestField - TStringField - Size = 4

UniQuery1.Close;
UniQuery1.SQL.Clear;
UniQuery1.SQL.Add('SELECT ''Yes'' AS TestField');
UniQuery1.Open;


When I run the query the following error occurs:

---------------------------
Project1
---------------------------
UniQuery1: Type mismatch for field 'TestField', expecting: String actual: Memo.
---------------------------
OK
---------------------------

How can I fix that problem ?

Thanks!

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 10 May 2011 09:56

Hello,

To resolve the problem, you should set the UnknownAsString specific option to True like:

Code: Select all

UniQuery1.SpecificOptions.Values['UnknownAsString']:= 'true';

eduardomendes
Posts: 28
Joined: Wed 24 Feb 2010 14:08

Post by eduardomendes » Tue 10 May 2011 17:00

Perfect....

Thanks!

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Wed 11 May 2011 06:26

Hello,

It is good to see that this problem was solved. If any other questions come up, please contact us.

eduardomendes
Posts: 28
Joined: Wed 24 Feb 2010 14:08

Post by eduardomendes » Wed 11 May 2011 11:42

Hello AlexP,

my situation was resolved with SpecificOptions 'UnknownAsString', but if I run other query the following error occurs:


Config:
TUniConnection.ProviderName = PostgreSQL
TUniConnection.SpecificOptions.Values['Charset'] := 'Latin1'
TUniQuery.SpecificOptions.Values['UnknownAsString'] := 'True'
TUniQuery has one field - TPREG - TStringField - Size 5


Table:
CREATE TABLE TABLE_TEST (TPREG VARCHAR(1));


Query:
SELECT
CASE WHEN TPREG = 'Y' THEN 'YES' ELSE 'NO' END AS DsTPREG
FROM TABLE_TEST;


Error:
---------------------------
Project1
---------------------------
UniQuery1: Type mismatch for field 'DsTPREG', expecting: String actual: Memo.
---------------------------
OK
---------------------------


How can I fix that problem ?

Thanks!

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Wed 11 May 2011 13:26

Hello,

This problem is connected with the fact that PostgreSQL returns the type of this field as SQL_TEXT instead of SQL_VARCHAR, so it is the dtMemo type.
To resolve the problem you can use the following workaround:
convert data type directly like

SELECT cast(
CASE WHEN TPREG = 'Y' THEN 'YES' ELSE 'NO' END as character(5)) AS DsTPREG
FROM TABLE_TEST;

Post Reply