Help with wildcard '% or %' or...?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Locked
cavenewt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 66
Joined: Fri Mar 15, 2013 3:54 pm
Location: Jackson Hole, Wyoming, USA

Help with wildcard '% or %' or...?

Post by cavenewt » Tue Aug 27, 2013 6:21 pm

Newbie question here. I searched the forum, I tried The Google, I searched in the dictionary. I cannot find an explanation of the wildcard character Elanor used in lesson 3.

Here it is straight out of the lesson PDF:

Code: Select all

put " WHERE firstname LIKE '%" & tSearchText & "%' OR lastname LIKE '%" & tSearchText & "%'" after tSQLQuery
We've got '% and then %' and then '% and a final %'. I can see they are alternating, but is the ' character part of the wildcard, or is the wildcard just % and the apostrophes are part of an embedded quote string (though I don't see how that would work)…?

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: Help with wildcard '% or %' or...?

Post by BvG » Tue Aug 27, 2013 6:25 pm

This code generates a SQL statement on the fly. so the end result is SQL, and % is a wildcard used in that.

if you remove the "after" part at the end, you'll see the proper string appear in your message box:

Code: Select all

put " WHERE firstname LIKE '%" & tSearchText & "%' OR lastname LIKE '%" & tSearchText & "%'"
you should see the following in the message box:

Code: Select all

WHERE firstname LIKE '%whatever tSearchText contains goes here%' OR lastname LIke '%tSearchText conents here%'
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

cavenewt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 66
Joined: Fri Mar 15, 2013 3:54 pm
Location: Jackson Hole, Wyoming, USA

Re: Help with wildcard '% or %' or...?

Post by cavenewt » Tue Aug 27, 2013 8:28 pm

Oh, so it is an embedded quote!

I am in the habit of using the messagebox for checking variables and things, thank you for pointing out that it can also be used in this fashion.

walkerl26
Posts: 25
Joined: Tue Nov 02, 2010 2:50 am

Re: Help with wildcard '% or %' or...?

Post by walkerl26 » Tue Aug 27, 2013 9:19 pm

I was a bit puzzled at the single/double-quote syntax too (it's been awhile since I did much SQL, and concatenating up query-strings is always a stupid mess in any language), so I just put a breakpoint in the script and looked at the final query-string. That let me visualize what was getting built so much better.

Copy & Pasting the command into the message-box is clever, though: would have let me test the query-building command in isolation, before the actual script was fully functional...

Of course the real fix is to stay clear of the whole thicket of RevDatabaseXxxxxxx calls and just use Andre Garzia's dbLIB package. Sure hope the new DB engine in LC is as simple and transparent as dbLib!

Larry

cavenewt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 66
Joined: Fri Mar 15, 2013 3:54 pm
Location: Jackson Hole, Wyoming, USA

Re: Help with wildcard '% or %' or...?

Post by cavenewt » Wed Aug 28, 2013 4:51 pm

walkerl26 wrote:Copy & Pasting the command into the message-box is clever, though: would have let me test the query-building command in isolation, before the actual script was fully functional...
Copy/paste not required, so it would also help in this instance. As I remember from HyperCard, simply telling LC to "put X" without a target will pop the result into the message box automatically. I will often stick a "put…" line temporarily into a script just to see what's going on, as the other poster suggested in this case. I realize there are other tools for debugging, but this is quick and easy.

Locked

Return to “Summer School 2013”