• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Query of Queries (QofQ) Escaped Character Problem

Contributor ,
Jul 31, 2007 Jul 31, 2007

Copy link to clipboard

Copied

Hello All,

I'm trying to run a query or queires (QofQ) and I'm doing a LIKE comparison that looks for bracket characters ([ ]) within a string, however ColdFusion is ignoring the brackets. How can I escape the bracket character? So far I have only been able to escape the percent sign based on the ColdFusion Live Docs. The error message I get when I run the query below is:

Invalid Escape Sequence. Valid sequence pairs for this escape character are: "\%", or "\_".

Here is the query:
<cfquery dbtype="query" name="getLogs">
SELECT *
FROM GetLogs
WHERE Description LIKE '%\[User:#UserID#\]%' ESCAPE '\'
</cfquery>

Thanks for your help!
TOPICS
Advanced techniques

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Aug 01, 2007 Aug 01, 2007
What about this?

WHERE Description LIKE '%[[]User:#UserID#]%'

Votes

Translate

Translate
Guide ,
Jul 31, 2007 Jul 31, 2007

Copy link to clipboard

Copied

Edit - Scratch that idea. It doesn't appear to work exactly as it should.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 01, 2007 Aug 01, 2007

Copy link to clipboard

Copied

oops... yeah that didn't work.

You suggested using double brackets [[ ]].

I think the solution lies in using ESCAPE '\' but for some reason it doesn't like that combination of \ and [ ]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 01, 2007 Aug 01, 2007

Copy link to clipboard

Copied

I didn't test it extensively but it seemed like the matches weren't quite correct. For instance if #UserID# = 99 I think the query results included

Test record 1: [User:99] ....blah
Test record 2: [User:9999] ....blah
Test record 3: [User:999]....blah

But it should only have included record 1. Then again maybe my brain was tired 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 01, 2007 Aug 01, 2007

Copy link to clipboard

Copied

You are correct. If you leave the brackets in the LIKE statement, it will return results as if the brackets weren't there at all.

Perhaps I need to figure out the ASCII character value of the bracket and include it that way i.e. #Char(?)# where the question mark would be the numerical value of that character.

My temporary solution has been to leave off the starting bracket:

<cfquery dbtype="query" name="getLogs">
SELECT *
FROM GetLogs
WHERE Description LIKE '%user:#UserID#]%'
</cfquery>

This has (so far) returned the results i'm looking for although its not as 100% accurate without that beginning [ in the LIKE statement.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 01, 2007 Aug 01, 2007

Copy link to clipboard

Copied

Edit - Duh. Yes square brackets [ ] are used to indicate a range of characters. That's why the results aren't quite what you'd expect.

http://livedocs.adobe.com/coldfusion/7/htmldocs/00001269.htm
"Square brackets ([ ]) represents any character in the range."

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 01, 2007 Aug 01, 2007

Copy link to clipboard

Copied

What about this?

WHERE Description LIKE '%[[]User:#UserID#]%'

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 01, 2007 Aug 01, 2007

Copy link to clipboard

Copied

LATEST
Thats the trick! The '[[]' method worked. Here is the final LIKE statement: Description LIKE '%[[]user:#UserID#]%'

Nice Job!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation