Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seek using LIKE *mystring* 1

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

In SQL databases I use the LIKE operator to find a search string that is embeded in a string of a field value.

I have SET EXACT OFF (which works as: LIKE *mystring).

In standard Clipper\xHarbour how can I perform a match simliar to the SQL LIKE operator's LIKE *mystring* ?



Thanks,

Michael42
 
Hi, Michael42

Well, you can approximate it by something like:

locate for 'MYSTRING'$upper(<fieldname>)

or

set filter to 'MYSTRING'$upper(<fieldname>)
go top

where <fieldname> is the database field in which you are looking for an embedded mystring. Use upper() to make it case independent.

However, I can't think of a way to make it work on an index
though both options will retrieve matches in sequence by the active index.

Jock
 
Another alternative for LIKE is an often used Clipper function Soundex(), that creates a 4 or 5 character 'sounds like' code to create indexes with. This can come in handy when searching for a like-wise comparison. It is not a replacement though.
I'd use either the locate or filter solution, but it will be quite slow, in either case.
The filter is closest to LIKE in SQL as the result is a set of records that match the criteria.

When using xHarbour, have a look at the MySQL lib that's in the contrib folder.

HTH
TonHu
 
Thanks all for your comments.

Thanks,

Michael42
 
There are a couple of things on the Oasis that may be worth looking at. Look for WildSrch.zip and SCBFND.ZIP. The first one searches for data in .NTX files and then translates that to records so it's only good for those indexes.

Ian Boys
DTE Systems Ltd
 
Bozz,

Those are very nice routines - thanks!

-Michael42
 
If you are using the SIxCDX drivers, they have a WildSeek command and sx_WildSeek function which is what you are looking for, but I only know of it in SIxCDX.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top