Page 1 of 1

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

Posted: Mon 09 May 2011 14:32
by eduardomendes
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!

Posted: Tue 10 May 2011 09:56
by AlexP
Hello,

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

Code: Select all

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

Posted: Tue 10 May 2011 17:00
by eduardomendes
Perfect....

Thanks!

Posted: Wed 11 May 2011 06:26
by AlexP
Hello,

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

Posted: Wed 11 May 2011 11:42
by eduardomendes
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!

Posted: Wed 11 May 2011 13:26
by AlexP
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;