dbExpress Memo CodeGear C++
dbExpress Memo CodeGear C++
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,
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,
-
- Devart Team
- Posts: 271
- Joined: Wed 23 Jan 2013 11:21
Re: dbExpress Memo CodeGear C++
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:
2) Modify data displaying via the TDBGrid->OnDrawColumnCell event, for example :
3) Use another DBGrid component, that can display such data types (TEXT, MEMO etc.) .
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
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);
}
}
Re: dbExpress Memo CodeGear C++
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.
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.
-
- Devart Team
- Posts: 271
- Joined: Wed 23 Jan 2013 11:21
Re: dbExpress Memo CodeGear C++
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/Librarie ... ls.TDBMemo
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/Librarie ... ls.TDBMemo
Re: dbExpress Memo CodeGear C++
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
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
-
- Devart Team
- Posts: 271
- Joined: Wed 23 Jan 2013 11:21
Re: dbExpress Memo CodeGear C++
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.
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.
Re: dbExpress Memo CodeGear C++
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?
Re: dbExpress Memo CodeGear C++
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:If the dataset does contain data, remove all columns that you added to the TDBGrid.
Code: Select all
ShowMessage(ClientDataSet.FieldByName('fieldname').AsString);
Re: dbExpress Memo CodeGear C++
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!
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!
Re: dbExpress Memo CodeGear C++
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
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