I've an issue with a very basic query using MariaDB 10.3. I'm updating thousands of path in a database with this code:
UPDATE il1_il8_localisation i SET i.`IL_17_CODE_PHOTO_1`="..\IPB\Photos\Foto1_261_ 3837.jpg" WHERE i.`IQ_1_NUMERO_DU_QUESTIONNAIRE`= 261;
and it fills the column IL_17_CODE_PHOTO_1 with the string
..IPBPhotosFoto1_ 261_ 3837.jpg instead of ..\IPB\Photos\Foto1_ 261_ 3837.jpg
I tried to change data sturcture from varchar(120) to TEXT with no results.
MariaDB uses the backslash character (\) as an escape character. From the linked article:
Backslash (\), if not used as an escape character, must always be escaped. When followed by a character that is not [a valid escape sequence], backslashes will simply be ignored.
Replace each single backslash with a double backslash (to escape the escape character):
UPDATE il1_il8_localisation i SET i.IL_17_CODE_PHOTO_1="..\\IPB\\Photos\\Foto1_ 261_ 3837.jpg" WHERE i.IQ_1_NUMERO_DU_QUESTIONNAIRE= 261;
Related
So, I am doing a small function to strip all the weird chars from a string, eg. #$& will be replaced just for a " "
The chars I am trying to remove are the following, defined into a string:
xChars = r"#$%()'^*\;:/|+_.–°ªº"
However I kepp getting the warning:
Anomalous backslash in string: '\;'. String constant might be missing an r prefix
However, when i used the r prefix eg. r"\" python rules out some of the special chars i want to replace. It doesnt produce an error it just thinks that those chars are ok or something and it rules them out.
Any ideas on how to fix this ?
Normally backslashes escape characters, therefore the compiler isn´t sure if the backslash has to be escaped. Maybe try using a double backslash to escape the backslash itself like: xChars = r"#$%()'^*\\;:/|+_.–°ªº"
To declare a character or a string on R, one can use both following ways:
x <- 'Some string'
x <- "Some string"
Both work, but is there any difference ?
From ?"'":
Details
Three types of quotes are part of the syntax of R: single and double
quotation marks and the backtick (or back quote, `). In addition,
backslash is used to escape the following character inside character
constants.
Character constants
Single and double quotes delimit character constants. They can be used
interchangeably but double quotes are preferred (and character
constants are printed using double quotes), so single quotes are
normally only used to delimit character constants containing double
quotes.
Backslash is used to start an escape sequence inside character
constants. Escaping a character not in the following table is an
error.
Single quotes need to be escaped by backslash in single-quoted
strings, and double quotes in double-quoted strings.
No. These are identical.
......
I am using rewrite module to allow double quotes in string
[_0-9a-z-‘!##$%^*()!~`\22\42.]
But it gives the following error.
The expression "^([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-‘!##$%^*()!~`\22\42.]+)" contains an escape sequence that is not valid.
The \22 and \42 are not valid escape sequences. You need to specify the hex notation if you plan to match those characters:
[_0-9a-z-‘!##$%^*()!~`\u0022\u0042.]
Or
[_0-9a-z-‘!##$%^*()!~`\x22\x42.]
Windows copies path with backslash \, which R does not accept. So, I wanted to write a function which would convert \ to /. For example:
chartr0 <- function(foo) chartr('\','\\/',foo)
Then use chartr0 as...
source(chartr0('E:\RStuff\test.r'))
But chartr0 is not working. I guess, I am unable to escape /. I guess escaping / may be important in many other occasions.
Also, is it possible to avoid the use chartr0 every time, but convert all path automatically by creating an environment in R which calls chartr0 or use some kind of temporary use like using options
From R 4.0.0 you can use r"(...)" to write a path as raw string constant, which avoids the need for escaping:
r"(E:\RStuff\test.r)"
# [1] "E:\\RStuff\\test.r"
There is a new syntax for specifying raw character constants similar to the one used in C++: r"(...)" with ... any character sequence not containing the sequence )". This makes it easier to write strings that contain backslashes or both single and double quotes. For more details see ?Quotes.
Your fundamental problem is that R will signal an error condition as soon as it sees a single back-slash before any character other than a few lower-case letters, backslashes themselves, quotes or some conventions for entering octal, hex or Unicode sequences. That is because the interpreter sees the back-slash as a message to "escape" the usual translation of characters and do something else. If you want a single back-slash in your character element you need to type 2 backslashes. That will create one backslash:
nchar("\\")
#[1] 1
The "Character vectors" section of _Intro_to_R_ says:
"Character strings are entered using either matching double (") or single (') quotes, but are printed using double quotes (or sometimes without quotes). They use C-style escape sequences, using \ as the escape character, so \ is entered and printed as \, and inside double quotes " is entered as \". Other useful escape sequences are \n, newline, \t, tab and \b, backspace—see ?Quotes for a full list."
?Quotes
chartr0 <- function(foo) chartr('\\','/',foo)
chartr0('E:\\RStuff\\test.r')
You cannot write E:\Rxxxx, because R believes R is escaped.
The problem is that every single forward slash and backslash in your code is escaped incorrectly, resulting in either an invalid string or the wrong string being used. You need to read up on which characters need to be escaped and how. Take a look at the list of escape sequences in the link below. Anything not listed there (such as the forward slash) is treated literally and does not require any escaping.
http://cran.r-project.org/doc/manuals/R-lang.html#Literal-constants
I have a restful webservice which receives some structured data which is put straight into a database.
The data is send from an OS using wget. I am just wondering whether I actually need to URL encode the data and if so why? Please note that it is no problem to do it but it might be uneccessary in this scenario.
If your data has characters that aren't allowed in urls, you should url encode it.
The following characters are either reserved (like &) or just present the possibility of confusing code. If your data contains these characters, urlencode it. Remember if you are using any extended ascii characters, unicode characters or non-printable characters you should url-encode your data.
Dollar ("$")
Ampersand ("&")
Plus ("+")
Comma (",")
Forward slash/Virgule ("/")
Colon (":")
Semi-colon (";")
Equals ("=")
Question mark ("?")
'At' symbol ("#")
Space
Quotation marks
'Less Than' symbol ("<")
'Greater Than' symbol (">")
'Pound' character ("#")
Percent character ("%")
Left Curly Brace ("{")
Right Curly Brace ("}")
Vertical Bar/Pipe ("|")
Backslash ("\")
Caret ("^")
Tilde ("~")
Left Square Bracket ("[")
Right Square Bracket ("]")
Grave Accent ("`")
More info can be found here: http://www.blooberry.com/indexdot/html/topics/urlencoding.htm