problem displaying data in grid in pgsql

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
albourgz
Posts: 160
Joined: Wed 06 May 2009 12:17
Location: belgium

problem displaying data in grid in pgsql

Post by albourgz » Mon 28 Nov 2016 12:45

Unidac 6.4.16, c++ builder xe10 pro, vcl win32 app.

Code: Select all

QDict->SQL->Strings[0]="SELECT ID, DTON, WHAT, RC, AUTO, DUREE, substr(command, 1, {fn LOCATE('''',command) } -1) as pgm FROM thetable";
QDict->DataTypeMap->AddFieldNameRule("PGM", ftWideString);
command is character varying 256 (in oracle varchar2(256 char)).
DBMonitor: sql translation is correct.
This query is source of a TCrDBGrid.
Query from db monitor copied to pgadmin gives the good results.
Problem in postgres: only 20 first chars of substr(command, 1, {fn LOCATE('''',command) } -1) are displayed in the grid. (only in postgres, connected to oracle display is fine!!!!).

Any hint?

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: problem displaying data in grid in pgsql

Post by azyk » Wed 30 Nov 2016 14:10

In the provided sample for PostgreSQL the substr construction does not return field length that is not set in the mapping rule either, therefore UniDAC sets string field length by default (20).

To solve the issue set exact value to the field length in Data Type Mapping rule. For example, the rule can look like this:

Code: Select all

QDict->DataTypeMap->AddFieldNameRule("PGM", ftWideString, 256);

albourgz
Posts: 160
Joined: Wed 06 May 2009 12:17
Location: belgium

Re: problem displaying data in grid in pgsql

Post by albourgz » Wed 30 Nov 2016 15:48

Why is string field length by default different for Oracle and for Postgres?

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: problem displaying data in grid in pgsql

Post by azyk » Thu 01 Dec 2016 10:17

The default size(20) does not depend on the used DBMS, property Size default 20; is written in implementation of the standard TStringField class and its descendant TWideStringField.

During SQL query execution UniDac requests for recordset fields metadata from DBMS, including the size. Oracle for T-SQL substr function returns the size in metadata, therefore UniDAC sets the size to the PGM field which is returned by Oracle. PostgreSQL for T-SQL substr function in metadata does not return the size, therefore UniDAC does not set the size to the PGM field. As the size for TWideStringField is not set by any others, the size takes a value by default.

Post Reply