Escaping special characters in an MDX Query - mdx

I'm building a BI dashboard for my client. Our data is stored in an analysis server cube. Overall things work great, but a smartalec tester decided to create a merchant with the name `~!##$%^&*()_+-=[]{}|;':"<>?,./ The name shows up just fine as a part of a query result, but if the user trys to drill in to the merchant we of course blow up b/c the \ { ; [ " are all part of MDX. Is there a way to escape these characters? I've tried putting a \ in front, or doubling the character. I've searched all over, but not turn up anything.
TIA

You must use the [] notation for your names and escape (only) the right bracket. Here is an example declaring a calculated measure with the name to escape (notice the ]] ):
with member [`~!##$%^&*()_+-=[]]{}|;':"<>?,./] as 42
select [`~!##$%^&*()_+-=[]]{}|;':"<>?,./] on 0 from [cube]

Could you try use [ ] brackets? I think it should help. But you should also "escape" your own brackets.
MSDN
If the body of the identifier contains only a left bracket ([), no
additional handling is required. If the body of the identifier
contains a right bracket (]), you must specify two right brackets
(]]).

Related

Regex to find period in square brackets

I am parsing some SQL statements and have found places where the SELECT statement may be:
SELECT [tblCustomer].[FirstName], [tblCustomer.LastName], [tblOrder].[Order_No]
and as you see the second column has a . inside the square brackets. This is acceptable in Access SQL but not SQL Server. I'm trying to build a RegEx to identify when there is a . inside square brackets and replace it with ].[
I've tried: \[.+?\](?![\.]) which will get me a period inside square brackets but it doesn't stop searching when it finds the closing bracket.
I'm using ECMAScript to be compatible with VBA and I don't have concerns about nested brackets.
Example: https://regex101.com/r/Inxhdg/1/
You can use
Search for: (\[\w+)\.(?=\w+])
Replace with: $1].[
See the regex demo. Details:
(\[\w+) - Group 1 ($1): [ and then any one or more letters, digits, or underscores
\. - a dot
(?=\w+]) - a positive lookahead that requires one or more letters, digits or underscores and then a ] char immediately to the right of the current location.

How to include apostrophe in character set for REGEXP_SUBSTR()

The IBM i implementation of regex uses apostrophes (instead of e.g. slashes) to delimit a regex string, i.e.:
... where REGEXP_SUBSTR(MYFIELD,'myregex_expression')
If I try to use an apostrophe inside a [group] within the expression, it always errors - presumably thinking I am giving a closing quote. I have tried:
- escaping it: \'
- doubling it: '' (and tripling)
No joy. I cannot find anything relevant in the IBM SQL manual or by google search.
I really need this to, for instance, allow names like O'Leary.
Thanks to Wiktor Stribizew for the answer in his comment.
There are a couple of "gotchas" for anyone who might land on this question with the same problem. The first is that you have to give the (presumably Unicode) hex value rather than the EBCDIC value that you would use, e.g. in ordinary interactive SQL on the IBM i. So in this case it really is \x27 and not \x7D for an apostrophe. Presumably this is because the REGEXP_ ... functions are working through Unicode even for EBCDIC data.
The second thing is that it would seem that the hex value cannot be the last one in the set. So this works:
^[A-Z0-9_\+\x27-]+ ... etc.
But this doesn't
^[A-Z0-9_\+-\x27]+ ... etc.
I don't know how to highlight text within a code sample, so I draw your attention to the fact that the hyphen is last in the first sample and second-to-last in the second sample.
If anyone knows why it has to not be last, I'd be interested to know. [edit: see Wiktor's answer for the reason]
btw, using double quotes as the string delimiter with an apostrophe in the set didn't work in this context.
A single quote can be defined with the \x27 notation:
^[A-Z0-9_+\x27-]+
^^^^
Note that when you use a hyphen in the character class/bracket expression, when used in between some chars it forms a range between those symbols. When you used ^[A-Z0-9_\+-\x27]+ you defined a range between + and ', which is an invalid range as the + comes after ' in the Unicode table.

In bigquery sql are curly braces allowed as part of a column alias

I'm trying to do something like this
SELECT epi_week {week}, state
FROM
lookerdata:cdc.project_tycho_reports
LIMIT 10
Error: Encountered " "{" "{ "" at line 1, column 17. Was expecting: EOF>
It seems that curly braces are not legal syntax. I've tried escaping or using quotes without success.
Is there a way around this? We use the braces as an indication for post-processing string replacement to support multiple languages.
Is there a way around this?
No way unfortunatelly.
Field name must contain only letters, numbers, and underscores, start with a letter or underscore, and be at most 128 characters long.
As an option - you might want to come up with another name convention for post-processing

Does mIRC Scripting have an escape character?

I'm trying to write a simple multi-line Alias that says several predefined strings of characters in mIRC. The problem is that the strings can contain:
{
}
|
which are all used in the scripting language to group sections of code/commands. So I was wondering if there was an escape character I could use.
In lack of that, is there a method, or alternative way to be able to "say" multiple lines of these strings, so that this:
alias test1 {
/msg # samplestring}contains_chars|
/msg # _that|break_continuity}{
}
Outputs this on typing /test1 on a channel:
<MyName> samplestring}contains_chars|
<MyName> _that|break_continuity}{
It doesn't have to use the /msg command specifically, either, as long as the output is the same.
So basically:
Is there an escape character of sorts I can use to differentiate code from a string in mIRC scripting?
Is there a way to tell a script to evaluate all characters in a string as a literal? Think " " quotes in languages like Java.
Is the above even possible using only mIRC scripting?
"In lack of that, is there a method, or alternative way to be able to "say" multiple lines of these strings, so that this:..."
I think you have to have to use msg # every time when you want to message a channel. Alterativelty you can use the /say command to message the active window.
Regarding the other 3 questions:
Yes, for example you can use $chr(123) instead of a {, $chr(125) instead of a } and $chr(124) instead of a | (pipe). For a full list of numbers you can go to http://www.atwebresults.com/ascii-codes.php?type=2. The code for a dot is 46 so $chr(46) will represent a dot.
I don't think there is any 'simple' way to do this. To print identifiers as plain text you have to add a ! after the $. For example '$!time' will return the plain text '$time' as $time will return the actual value of $time.
Yes.

How do I escape the # character in Cognos?

I have created a pass-through Query Item in Cognos 8 Framework Manager that requires the # character as part of the query. Unfortunately this gets interpreted by Cognos as the opening of a macro.
How do I escape the # (number sign/sharp) character in a Query Item?
There does't seem to be any "official" way in the documentation, but this seems to work.
#"#"#
#'#'# works too, unless it appears in a literal SQL string in your query, so it's safer to use #"#"#.
A single backslash \ should delimit it, I know it delimits square brackets [].