Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Sylvia,
Here's a couple of hints about your code. I have spent much of this past year dealing with ancient code written by someone who was long gone.
There is no need to reference work area numbers. Just use USE MyFile IN 0, or SELECT 0 | USE MyFile.
Refer to the files by their alias. SELECT Customer. Then when you're further down in the app you don't have to try to remember "who'se on third."
Try SCAN ... ENDSCAN instead of DO WHILE NOT EOF(). Hacker's Guide says it can be up to twice as fast. Also, there is no need to have the Customer table in any particular order (if you put LastGet in some order when you're done.) SCAN is faster when the table is not ordered. Of course having the index on Customer speeds up the SQL, but it is not necessary to be in index order. (You can read about Rushmore technology.)
You can APPEND FROM a cursor (if you select into a cursor) by APPEND FROM DBF("MyCursor"). Nothing to clean up afterwards! You can also SELECT INTO an ARRAY and APPEND FROM ARRAY, but the fields will need to be in the correct order. (Read about this.)
Knowing some of these details helps me reach for the most efficient tool each time. When I was done optimizing a program that used to take 45 minutes, it ran in 3!!!
Happy programming!
>Thank you Cindy. I used your suggestion, and ended up with a working solution that looks like this:
>
>set escape on
>set safety off
>SELECT 1
>USE customer.dbf
>SET ORDER TO customer_i
>GO TOP
>SELECT 2
>USE orders.dbf
>INDEX ON order_date TAG order_date DESCENDING
>SELECT 3
>USE lastget.dbf
>zap
>
>SELECT 1
>DO WHILE NOT EOF()
> m_customer_id = customer_id
> SELECT TOP 3 Customer.customer_id, Orders.order_id, Orders.order_date;
> FROM tastrade!orders INNER JOIN tastrade!customer ;
> ON Orders.customer_id = Customer.customer_id;
> WHERE Orders.customer_id = M_customer_id;
> ORDER BY Customer.customer_id, Orders.order_date DESC;
> INTO TABLE tempget.dbf
> SELECT 3
> APPEND FROM tempget.dbf
> SELECT 1
> Skip 1 && Move down one record
>ENDDO
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement