Link to home
Start Free TrialLog in
Avatar of yc
yc

asked on

How to change the index of query at runtime?

1. How to change the primary key of query at runtime?
2. Can i do it when the query is open?
3. How to use the second index with query?

Thanks for any help.

Ye Chen
Avatar of kretzschmar
kretzschmar
Flag of Germany image

hi yc,

what does you mean? a query has no primary key and no second index. Some databases use indexes automatically for the query some must explezit said to use an index for the query.

for changes a must query closed and reopened except changes on the filteroptions.

meikl
Avatar of EmmDieh
EmmDieh

The query optimizer of the underlying database system chooses the indexes automatically. Sometimes you can manually add your own plan of the indexes used.
In order to sort the result set of a query you'll have to use the "order by" clause of the "select" statement. To apply different sort orders you'll have to close the query change the "order by" clause und re-open the query.
Ex.:  select a, b, c from d order by c, b, a
So, you cannot change the order of the rows of the query-result-set while the query is open.

Avatar of yc

ASKER

Hi, EmmDieh

When i use "order by " in SQL clause, i can modify but not update the query through DBGrid. Why?

It is very important for me to modify and post when use non-primary index!

Thanks for your help.

Ye Chen
When using "order by", the result can no longer be a live result. However, you can user UpdateSQL to implement that. So you can use most of the conditional sub-clauses as well as modify the result.
Avatar of yc

ASKER

Hi, dwwang
 
Would you give me an example of UpdateSQL which using "order by".
 
Merry Christmas and Happy New Year!

Ye Chen

Hi, an example is too complex to provide here, you can see the help on TUpdateSQL component in Delphi, there are detailed explanations as well as examples.

The main idea is that your input to the query is cached, and when you call ApplyUpdates, system will run the SQL statement stored in the TUpdateSQL component to perform the updates. If this helps, leave a message :-)

Merry Christmas and Happy New Year!

Regards,
Wang
Avatar of yc

ASKER

Hi, dwwang
 
I had added the sqlupdate compontent to my application.
But it seems do not work.
 
I wander you send a simple example to my mailbox? (yc@1lansuite.com)

BTW: The points is increased to be 100. :)
 
Thanks very much.
 
Ye Chen
Avatar of yc

ASKER

Hi, dwwang

my E-mail address is yc@lansuite.com

wait you.

Y.C.
ASKER CERTIFIED SOLUTION
Avatar of dwwang
dwwang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yc

ASKER

Hi, dwwang

I hadn't installed the Local Interbase on my machine.
I am using Delphi 4.01

Please mail me the example which use TDBGrid, TQuery, TDatabase, TUpdateSQL, TDataSource and a Button to UpdateCache.

Thanks very much.

Ye Chen

Avatar of yc

ASKER

Adjusted points to 150