Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert codes in sql
Message
From
03/05/2005 14:09:52
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01010484
Message ID:
01010563
Views:
18
Hello Khalid ...

i'll try to explain generally how to optimize your given code sample .. so you can understand it and improve performance yourself now and in the future.
Select 6
&& you should use the alias name of the table/cursor instead of the 
&& workarea number. This  makes code more readable by a performane hit of
&& some nanoseconds, you'll never will notice a difference in speed,
&& but readability/maintainability is HIGHLY improved

Replace dr With 0 All
Replace cr With 0 All
&& UPDATE yourCursorName SET dr = 0, SET cr = 0
&& is far faster since it will place only one lock at the table header
&& REPLACE will lock any record once, and since you've 2 replaces it will
&& lock each record twice.  
&& I use replace command only to REPLACE one or several fields on ONE record,
&& and if you use REPLACE command always this way
REPLACE field1 WITH someValue, field2 WITH someOtherValue
&& instead of several single REPLACE's ... 

Goto Top
Do While !Eof()
Replace dr With opdr
Replace cr With opcr
Enddo

&& there a special command in VFP named SCAN that exactly does the above ..
SCAN IN aliasName && will automatically issue a GO TOP IN aliasName
&& somecode ... 
ENDSCAN && will automatically issue a SKIP on the correct table/cursor

&& as already mentioned a SCAN (loop over every record in table) with only
&& REPLACE commands in it can be rewritten most 
&& of the time as an UPDATE SQL statement .. which should always be faster

&& since you change the dr & cr fields again I
&& don't see the intend on setting them to 0 at the beginning of the code
&& since they are overwritten again anyway ?!
Serg already answered the rest of the conversion to a SELECT & UPDATE query.

Regards
Christian
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform