Hi.
I'm using the latest UniDac for MySQL and SQL Server with RAD 2007 Win32.
I've this problem:
I write a SQL.Text query in TUniQuery, like say:
select * from Customers order by name.
My program at runtime executes the query and TUniQuery automatically creates the fields corresponding to the Customers table.
Now I want to add a calculated (or in-memory) field to the TUniQuery.
The istruction Fields.Add raise an exception saying that this operation is not allowed with an open dataset.
So I tried to create the calculated field before opening the query.
But in this way when I open the TUniQuery, it does not automatically create the fields of the Customer's table.
So after beeing opened, the TuniQuery has only one field, the calculated one.
How can I solve this problem?
Thanks
NOTE: I cannot know the fields of the table Customers before have opened it.
Add fields at runtime
To create the fields of your SQL query, use the following code:
After that add calculated fields and then open the query.
Code: Select all
UniQuery.FieldDefs.Update;
for i := 0 to UniQuery.FieldDefList.Count - 1 do
with UniQuery.FieldDefList[i] do
if (DataType ftUnknown) and not (DataType in ObjectFieldTypes) then
CreateField(UniQuery, nil, UniQuery.FieldDefList.Strings[i]);
-
- Posts: 7
- Joined: Mon 09 Jun 2008 07:49
Thanks for your reply.
It does what I need.
But, how can the command
get the list of fields?
Does it send the query to MySQL?
And after, when I open the query, does it send the query again?
PS.
Can I add non calculated field?
For example with a Customers table with phisical columns:
"code, name"
can then Uniquery component keep in memory a field "State"?
I use this field for an elaboration on the customers table. I write there an information that I reuse, but it is not phisically on the database.
Thanks
It does what I need.
But, how can the command
Code: Select all
UniQuery.FieldDefs.Update;
Does it send the query to MySQL?
And after, when I open the query, does it send the query again?
PS.
Can I add non calculated field?
For example with a Customers table with phisical columns:
"code, name"
can then Uniquery component keep in memory a field "State"?
I use this field for an elaboration on the customers table. I write there an information that I reuse, but it is not phisically on the database.
Thanks