Open-minded: dbexpress processes the returned values of fn_listextendedproperty and obtains descriptive text of fields in the table.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.