InfluxDB how to escape square brackets "[" - influxdb

I am querying influx D.B. as shown below,
select * from measurement where '/cda/stats/#name' =~ /cda\/stats.*/ limit 5;
Above query is working fine, but when i try to specify square brackets in the query string it is not working, for e.g. "/cda/stats/[name='set']
select * from mgmgrand where '/cda/stats/#name' =~ /cda\/stats[name='set'].*/ limit 5;
Not sure how to escape square brackets in the above query.
Back slash "\" is not working with square brackets.

I tested this in influx DB and found a weird solution (I don't know why it works).
If your identifer is unquoted changing single quotes to double quotes, replacing '/cda/stats/#name' with "/cda/stats/#name" seems to fix it.
select * from mgmgrand where "/cda/stats/#name" =~ /\[/
//matches the value /cda/stats/[name='set']
Without changing the quotes it works fine for value without [ , but doesnt work when trying to match a [ character.
select * from mgmgrand where '/cda/stats/#name' =~ /cda/
//matches the value /cda/stats/[name='set']
select * from val1 where '/cda/stats/#name' =~ /\[/
//does not give an output
If you use a quoted identifier replacing '/cda/stats/#name' with "'/cda/stats/#name'" or "\"/cda/stats/#name\"" fixes it.

Related

Update a column name that starts with a number in a dbf-file with oledb

I'm trying to update a column named value in a dbf-file. Since value is a reserved word I need to add the tablename to the query. So this works:
UPDATE "C:\TEMP\TEST_PARAM.DBF" SET TEST_PARAM.value='new value' WHERE Id='Some ID';
But now I have the problem that many of my dbf-files start with numbers in the filenames and following does not work:
UPDATE "C:\TEMP\0016_PARAM.DBF" SET 0016_PARAM.value='new value' WHERE Id='Some ID';
I've tried enclosing the table_name in single quotes, double quotes, [,... but nothing of that works. Is there something else I could try?
You don't say what language you're doing this in, but here we go in C#. The same approach should work in any language.
You need to open the DBF under an alias, and you need to be able to send multiple commands through OLEDB.
This should work.
* -- Open the dbf in the first available work area under the alias 'param'.
* -- Now you don't have to worry about the zeroes.
OleDbCommand myCommand = new OleDbCommand(#"execscript([use 'C:\TEMP\0016_PARAM.DBF' in 0 alias param])", myConnection);
var result = myExecuteNonQuery();
* -- Now do the update, referring to the alias, not the DBF filename.
myCommand = new OleDbCommand(#"execscript([update param set param.value='new' where id='some id'])", myConnection);
result = myCommand.ExecuteNonQuery();
Regarding the square brackets, Visual FoxPro has three default string delimiters, namely the usual single and double quotes, but also square brackets.
So we're using the double quotes for the C# string. The Visual Foxpro command we're running via ExecScript needs quotes too, around 'new' and 'some id', so that's using single quotes. But we need to pass that command to Execscript as a string, so that string is using the brackets.

Convert string to multiline/raw string in LUA

Is there a way to convert a quoted string to a multiline string?
Something like "This string \66 here" to [[This string \66 here]] since I would like to ignore the interpretation of escaped characters.
Lua 5.3 Reference Manual 3.1: Lexical Conventions
Literal strings can also be defined using a long format enclosed by
long brackets. We define an opening long bracket of level n as an
opening square bracket followed by n equal signs followed by another
opening square bracket. So, an opening long bracket of level 0 is
written as [[, an opening long bracket of level 1 is written as [=[,
and so on. A closing long bracket is defined similarly; for instance,
a closing long bracket of level 4 is written as ]====]. A long literal
starts with an opening long bracket of any level and ends at the first
closing long bracket of the same level. It can contain any text except
a closing bracket of the same level. Literals in this bracketed form
can run for several lines, do not interpret any escape sequences, and
ignore long brackets of any other level. Any kind of end-of-line
sequence (carriage return, newline, carriage return followed by
newline, or newline followed by carriage return) is converted to a
simple newline.
For convenience, when the opening long bracket is immediately followed
by a newline, the newline is not included in the string.
That's all you need to know about long strings.
It does not make much sense to convert a string that has been defined using quotes "some string" to a string like [[some string]] as both quotes and square brackets are not actually part of that string and the string itself is the same.
The only difference would be a leading newline which is ignored in square brackets or escape sequences which are not interpreted.
Quotes and square brackets are only part of the string if you have nested strings. In this case conversion also doesn't make much sense because you cannot nest strings with quotes like strings with brackets.
Maybe your whole approach is a bit off?
Do you look for something like this?
local db = "google"
local tbl = "accounts"
local where = "field = 'VALUE' AND TRUE"
local order = "id DESC"
local query = string.format([[
SELECT *
FROM `%s`.`%s`
WHERE %s
ORDER BY %s
]], db, tbl, where, order)

Validation using Regular Expressions in iOS

I'm implementing validation for username field using Regular Expression(Regex) in iOS. I don't want username to start with the word "guest". I tried below code but it's not working.
[txtUserName addRegx:#"^(guest)" withMsg:#"Username Can't start with the word guest"];
Ideas?
You can try to use this Regex:
^(?!guest).*$
Explanation:
^ assert position at start of the string
(?!guest) Negative Lookahead - Assert that it is impossible to match the regex below
guest matches the characters guest literally (case sensitive)
.* matches any character (except newline)
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
$ assert position at end of the string
EDIT:
To make it case insensitive you can try this:
^(?i:(?!guest)).*$
You have to remove the ( ) like the following:
[txtUserName addRegx:#"^guest" withMsg:#"Username Can't start with the word guest"];

String queries in BreezeJS that contain single or double quotes return error

I have a text input for a search field where the string is then passed to an EntityQuery. When ever the query includes a single quote I get a message like the following:
There is an unterminated string literal at position 39 in 'substringof(O'Malley,FirstName) eq true'.
It even happens when just hard coding the query like this:
var query = breeze.EntityQuery
.from("Users")
.expand("GroupUsers.Group")
.where("lastName", "contains","O'Malley")
.skip(skipAmt)
.take(pageSize)
.inlineCount(true);
I've tried escaping the single quote by doing double single quotes or doing \' and it still comes back with an error. This also happens similarly with double quotes. What is the proper way to escape the string literal characters?
I can't repro this. You should be able to escape a single ' by simply doubling it. For example, the following query works without a problem on v 1.2.8.
var q = EntityQuery.from("Employees")
.where("lastName", "contains", "O''Malley");
Does the problem still occur if you 'simplify' the query down to just the where 'clause'?

Funny CSV format help

I've been given a large file with a funny CSV format to parse into a database.
The separator character is a semicolon (;). If one of the fields contains a semicolon it is "escaped" by wrapping it in doublequotes, like this ";".
I have been assured that there will never be two adjacent fields with trailing/ leading doublequotes, so this format should technically be ok.
Now, for parsing it in VBScript I was thinking of
Replacing each instance of ";" with a GUID,
Splitting the line into an array by semicolon,
Running back through the array, replacing the GUIDs with ";"
It seems to be the quickest way. Is there a better way? I guess I could use substrings but this method seems to be acceptable...
Your method sounds fine with the caveat that there's absolutely no possibility that your GUID will occur in the text itself.
On approach I've used for this type of data before is to just split on the semi-colons regardless then, if two adjacent fields end and start with a quote, combine them.
For example:
Pax;is;a;good;guy";" so;says;his;wife.
becomes:
0 Pax
1 is
2 a
3 good
4 guy"
5 " so
6 says
7 his
8 wife.
Then, when you discover that fields 4 and 5 end and start (respectively) with a quote, you combine them by replacing the field 4 closing quote with a semicolon and removing the field 5 opening quote (and joining them of course).
0 Pax
1 is
2 a
3 good
4 guy; so
5 says
6 his
7 wife.
In pseudo-code, given:
input: A string, first character is input[0]; last
character is input[length]. Further, assume one dummy
character, input[length+1]. It can be anything except
; and ". This string is one line of the "CSV" file.
length: positive integer, number of characters in input
Do this:
set start = 0
if input[0] = ';':
you have a blank field in the beginning; do whatever with it
set start = 2
endif
for each c between 1 and length:
next iteration unless string[c] = ';'
if input[c-1] ≠ '"' or input[c+1] ≠ '"': // test for escape sequence ";"
found field consting of half-open range [start,c); do whatever
with it. Note that in the case of empty fields, start≥c, leaving
an empty range
set start = c+1
endif
end foreach
Untested, of course. Debugging code like this is always fun….
The special case of input[0] is to make sure we don't ever look at input[-1]. If you can make input[-1] safe, then you can get rid of that special case. You can also put a dummy character in input[0] and then start your data—and your parsing—from input[1].
One option would be to find instances of the regex:
[^"];[^"]
and then break the string apart with substring:
List<string> ret = new List<string>();
Regex r = new Regex(#"[^""];[^""]");
Match m;
while((m = r.Match(line)).Success)
{
ret.Add(line.Substring(0,m.Index + 1);
line = line.Substring(m.Index + 2);
}
(Sorry about the C#, I don't known VBScript)
Using quotes is normal for .csv files. If you have quotes in the field then you may see opening and closing and the embedded quote all strung together two or three in a row.
If you're using SQL Server you could try using T-SQL to handle everything for you.
SELECT * INTO MyTable FROM OPENDATASOURCE('Microsoft.JET.OLEDB.4.0',
'Data Source=F:\MyDirectory;Extended Properties="text;HDR=No"')...
[MyCsvFile#csv]
That will create and populate "MyTable". Read more on this subject here on SO.
I would recommend using RegEx to break up the strings.
Find every ';' that is not a part of
";" and change it to something else
that does not appear in your fields.
Then go through and replace ";" with ;
Now you have your fields with the correct data.
Most importers can swap out separator characters pretty easily.
This is basically your GUID idea. Just make sure the GUID is unique to your file before you start and you will be fine. I tend to start using 'Z'. After enough 'Z's, you will be unique (sometimes as few as 1-3 will do).
Jacob

Resources