Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Add Record in Grid with more than 1 table inside
Message
From
14/12/2001 09:25:09
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00368379
Message ID:
00594369
Views:
31
>Thank Cetin,
>
>Here some problem that i have.
>I have table with lots of record...
>When i try to search some record with "LOCATE FOR" it's taking a time to C the result...
>
>Can you give me the best way what should i use for searching a record, the best and the fastest way...
>
>Thanks,

Tut,
Searching a record is a huge topic. Only will cover basics. There are many commnands that search for a record directly or indirectly.
'locate for' is one of them. If you're comfortable with it use it. Speed depends on if you have supplied necessary indexes. With necessary indexes supplied VFP is the fastest desktop language known to return data. ie:
You want to search for a name where upper name is 'TUT ARIE' and name is composed of 2 fields - first_name,last_name. A typical expression would be :

locate for upper(first_name)+upper(last_name) == 'TUT ARIE'
or:
locate for upper(first_name)=='TUT' and upper(last_name) == 'ARIE'

(First pads with spaces to match first_name field size)

If you had indexes on last_name and first_name like this :
index on first_name tag fname
index on last_name tag lname

VFP would have no way to utilize an index and it'd take some time. But if you had indexes that match to your expression(s) then VFP uses them :
index on upper(first_name)+upper(last_name) tag personname
index on upper(first_name) tag fname
index on upper(last_name) tag lname

With these indexes both expressions now can use index and return you the result in milliseconds. You could then also use another fantastic search command seek :

if seek('TUT ARIE','mytable','personname')
* Do whatever when it exists
endif

Or you could combine command with another searcher :
select myTable
set order to tag fname
if seek('TUT','mytable','fname')
  scan for upper(last_name) = 'ARIE' and AnotherExpr ;
       WHILE upper(first_name) = 'TUT' 
&& Search ARIE and AnotherExpr from first found position 
&& up till it doesn't match
  *...
  endscan
endif
Check help on '..for...while, scope' usage, 'set exact', 'set near', 'set key' etc

Which one you'd choose greatly depends on what you'd do with it.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform