|
moolb Newbie
Joined: 09 Dec 2006 Posts: 7
|
Posted: Fri Jul 06, 2007 9:34 pm
Mapquery with special characters |
Okay, so if a room is titled Moolb's Awkward Home, this will return nothing:
#echo %mapquery( "Name LIKE '%Moolb's Awkward Home%'")
Because of the ' character. If I am doing a manual search I know I can just do a search for Moolb''s Awkward Home and the room number will be returned.
However, if I'm trying to automate some things and I just have a variable called @roomName then I can not easily add that extra apostrophe in there.
I realize with a line or two of code I can take apart @roomName and detect if there is an apostrophe and fix it, but that seems like to much work.
Is there a way with the SQL syntax or any other way with Mapquery where I can tell the parser/whatever to ignore a special chatter like an apostrophe?
Anyway, thanks for any feedback that might come. |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Fri Jul 06, 2007 11:02 pm |
Personaly I use a user defined function to comment out the 's by doubling them up. Writing this off the top of my head.
#FUNC sqlf($param) {%replace($param,"'","''")}
example
#ECHO %mapquery("Name LIKE '%" + @sqlf("My Room Name") + "%'"
edit: Added in missing } |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Fri Jul 06, 2007 11:24 pm |
This does the trick for apostrophes, or commas.
Code: |
#show %mapquery(%concat("Name LIKE '%",%subchar("Moolb's Awkward Home","',","%%"),"%'")) |
|
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
moolb Newbie
Joined: 09 Dec 2006 Posts: 7
|
Posted: Mon Jul 09, 2007 9:30 pm |
Thanks Nexela, that worked great and was surprisingly easy. Didn't know about the replace command, thanks for the heads up :)
|
|
|
|
|
|