Board index » cppbuilder » TQuery, Getting field names

TQuery, Getting field names

How do I get the field names of a 'Select * from x' without doing the
query?

In ODBC, just prepare, then read the field names.
In BDE
Query1->Prepare();
if (Query1->Fields->Count==0) ShowMessage("Error");

is returning 'Error'.

 

Re:TQuery, Getting field names


Hi, Valence!

Without actually executing the SQL, the TQuery does not know for certain
the fields.

If the query is dynamically generated, you must do it that way. You can
always use a query you can be sure won't return results.

If the query is known at design time, create persistent fields.
Persistent fields should be able to be enumerated without executing the
query.

------
Mark Cashman, TeamB C++ Builder
http://www.temporaldoorway.com/programming/index.htm
C++ Builder, JBuilder programming information
Home of The C++ Builder Programmer's Webring - Join us!
------

Re:TQuery, Getting field names


Thank you Mark,

I will query first for a dummy record, that'll give me the fields. Maybe,
long term Borland.com will put a GetFieldNames function out there or
somethin' so that that expense won't be necessary.

Thanks again.

Quote
"Mark Cashman (TeamB)" wrote:
> Hi, Valence!

> Without actually executing the SQL, the TQuery does not know for certain
> the fields.

> If the query is dynamically generated, you must do it that way. You can
> always use a query you can be sure won't return results.

> If the query is known at design time, create persistent fields.
> Persistent fields should be able to be enumerated without executing the
> query.

> ------
> Mark Cashman, TeamB C++ Builder
> http://www.temporaldoorway.com/programming/index.htm
> C++ Builder, JBuilder programming information
> Home of The C++ Builder Programmer's Webring - Join us!
> ------

Other Threads