I haven't written a blog for a while. I 've been on a business trip for a week, and I'm busy with the task of completing the project system,
When writing a system today, I am working on a basic task to read the description text of fields in the specified table from SQL Server. I used to use ADO. Now I use the dbexpress component instead, use the dbexpress component to read the return value of fn_listextendedproperty in SQL Server. The returned field value is tvarbytesfield,
The SQL statement is:
Const
Sqlselecteextproperty = 'select * From: fn_listextendedproperty (null, ''user'', ''dbo', ''table'', ''% s '', ''column'', default )';
Neither the dbexpress component tsqlquery nor tsqldataset can directly read the value of the field "value". The original return value of fn_listextendedproperty "value" is of the 'SQL _ variant "type, and the return value is of the tvarbytesfield type in Delphi, it is found that the value of this field read by the dbexpress component cannot be converted into a pointer type. It can only be read by the pointer type pointer before processing. The returned results are not what I need, in fact, the descriptive text description of the columns in the table is saved in the field "value. At the beginning, I only thought about how to use dbexpress to process the tvarbytesfield type, it took about half a day to read data from the tvarbytesfield field in tsqlquery and convert the data to the desired character. In the end, there was no result and I entered a dead end.
Finally, there is no way. Take a break after dinner. Oh, I thought it was up. Since dbexpress cannot handle tvarbytesfield well, why should I use this type? I can process the returned results before returning them.
Modify:
Const
Sqlselecteextproperty = 'select objname as column_name, cast (value as varchar (100) as column_description from: fn_listextendedproperty (null, 'user', 'dbo '', ''table'', ''% s', ''column'', default )';
// Execution example
VaR
Aquery: tsqlquery;
Begin
Aquery: = tsqlquery. Create;
Aquery. Connection: = sqlconnection1;
Aquery. SQL. Text: = format (sqlselecteextproperty, ['mytablename']);
Aquery. open;
Showmessage (aquery. fieldbyname ('column _ description ');
Aquery. Free;
End;
The problem is solved. It was too late, wasting half a day. However, it turns out that it is better to use the dbexpress component to process some data type return values of SQL Server than to use ADO. For example, I used
When you select ident_current ('mytablename'), The dbexpress component will report an error. Now I have heard that this bug has been fixed and I have not tried it yet.