tr_user
tr_user

Reputation: 15

MariaDB removing backslashes from string in UPDATE query

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.

Upvotes: 0

Views: 1943

Answers (1)

esqew
esqew

Reputation: 44698

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;

Upvotes: 2

Related Questions