dbExpress Memo CodeGear C++

dbExpress Memo CodeGear C++

Postby noonstar » Wed 27 Mar 2013 09:25

Hello,

I've installed the latest dbExpress driver (Trial version) for connections to PostgreSQL databases. I am using CodeGear RADStudio 2007, C++ environment.

Connecting to a database is no problem, but displaying tables with colums of type 'text' is. Using TDBGrid shows "(WIDEMEMO)" for these colums, while the TDBMemo show the actual text of this column. The datatype of the generated clientdatasets' fielddefs are set to ftWideMemo. Changing them to different datatypes still displays "(WIDEMEMO)".

What am I missing? And what to do to show the actual text within a TDBGrid?

Regards,
noonstar
 
Posts: 3
Joined: Wed 27 Mar 2013 08:58

Re: dbExpress Memo CodeGear C++

Postby DemetrionQ » Thu 28 Mar 2013 12:45

Hello.

If you read the field data directly (for example, via SQLQuery1.FieldByName('FiledName').AsString), you will retrieve correct data. The fact that TDBGrid doesn't display TEXT fields is a specificity of TDBGrid, and our dbExpress driver can't affect this. To solve the problem, you can use one of the following ways:

1) Convert field type directly in the sql query, for example:
Code: Select all
  select field1, cast(field2 as varchar(200)) from table

2) Modify data displaying via the TDBGrid->OnDrawColumnCell event, for example :
Code: Select all
void __fastcall TForm1::DBGrid1DrawColumnCell(TObject *Sender, const TRect &Rect,
        int DataCol, TColumn *Column, TGridDrawState State)
{
  if (Column->FieldName == "field2") {
     DBGrid1->Canvas->FillRect(Rect);
     DBGrid1->Canvas->TextOut(Rect.Left + 3, Rect.Top + 3,
              Column->Field->AsString);
  }
}

3) Use another DBGrid component, that can display such data types (TEXT, MEMO etc.) .
DemetrionQ
Devart Team
 
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: dbExpress Memo CodeGear C++

Postby noonstar » Fri 29 Mar 2013 07:49

Hi DemetrionQ,

Thanks for your answers/solutions. I've chosen the first one, while the second one feels like 'reconstruction' of the column data, like you paste some 'image label' within the actual cell.

As for your last remark, I'm not sure what other DBGrid components are available that can do the job. I still do not understand completely why there is a difference using DBMemo, which displays the text datatype correctly, and DBGrid showing the text datatype as WIDEMEMO. The same dbExpress driver is used for both components. Previously I've used a dbExpress driver from another company (not available anymore for my situation), which did not have this issue.

Regards.
noonstar
 
Posts: 3
Joined: Wed 27 Mar 2013 08:58

Re: dbExpress Memo CodeGear C++

Postby DemetrionQ » Tue 02 Apr 2013 09:59

Hello.

A TEXT data type field may contain non-specified length data. Handling such fields like, for instance, ftWideString is inappropriate because data for ftWideString must have a fixed length. It is the purpose of ftWideMemo to handle data of a non-specified length.
TDBMemo displays the content of a TEXT field because it's intended for such purposes - displaying data of a non-specified length (for example, the above mentioned ftWideMemo). To learn more about TDBMemo specifics, see the Embarcadero documentation
http://docwiki.embarcadero.com/Libraries/XE3/en/Vcl.DBCtrls.TDBMemo
DemetrionQ
Devart Team
 
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: dbExpress Memo CodeGear C++

Postby noonstar » Fri 05 Apr 2013 09:21

Hi DemetrionQ,

Thanks for the info. As I've mentioned before, solution 1 is working for me. Still there is something about ftWideMemo, while defining the clientdatasets' fielddef of the specific database field to ftWideMemo does not do the job for me. Is it that only TDBMemo reads the database datatype 'TEXT' and ftWideMemo doesn't?

Regards
noonstar
 
Posts: 3
Joined: Wed 27 Mar 2013 08:58

Re: dbExpress Memo CodeGear C++

Postby DemetrionQ » Mon 08 Apr 2013 16:37

Hello.

dbExpress driver for PostgreSQL is not responsible for data display and cannot affect it. Questions on displaying of different data types in standard visual components can be forwarded to Embarcadero.
DemetrionQ
Devart Team
 
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: dbExpress Memo CodeGear C++

Postby KES103 » Fri 20 Sep 2013 02:30

None of the solutions work for me. I am using C++ Builder 6. Also of note, in Database Desktop, the column headings are shown, but the text or varchar values are blank. Numbers appear in the columns without problem. Only the text values are not automatically inserted into my DBGrid. The values are in the MySQL database tables, so do I need to extract the values and then insert them into my DBGrid?
KES103
 
Posts: 1
Joined: Tue 10 Sep 2013 05:04

Re: dbExpress Memo CodeGear C++

Postby AndreyZ » Mon 23 Sep 2013 12:01

Please check if a dataset contains any data in the fields which values are not shown in TDBGrid. For this, you can use the following code:
Code: Select all
ShowMessage(ClientDataSet.FieldByName('fieldname').AsString);
If the dataset does contain data, remove all columns that you added to the TDBGrid.
AndreyZ
 

Re: dbExpress Memo CodeGear C++

Postby mgrzymala » Fri 20 Dec 2013 11:11

Your DBGrid1DrawColumnCell function works! You just have to be careful to select the OnColumnDraw event form the Events in the GUI for the DBGrid1 - do not define the function manually.

Your suggestion #1 to hardcode the length of the text field as part of the sql query (something like cast or convert(varchar(200),[COLUMN_NAME]) is dangerous: how can you possibly assume that your database field length will NEVER be larger than the size you picked? The moment you retrieve only the first 200 characters and then (after some processing) update you db you are truncating your data and losing whatever did not fit within the 200 characters!
mgrzymala
 
Posts: 1
Joined: Fri 20 Dec 2013 10:34

Re: dbExpress Memo CodeGear C++

Postby AlexP » Tue 24 Dec 2013 11:50

Hello,

Indeed, if the data size is larger than the size specified on casting, the data will be cut. Therefore, to display data, you should either use the DBGrid1DrawColumnCell event or use third-party components that can display data from Memo fields
AlexP
Devart Team
 
Posts: 5528
Joined: Tue 10 Aug 2010 11:35


Return to dbExpress driver for PostgreSQL