cancel
Showing results for 
Search instead for 
Did you mean: 

Backslash in a procedure?

0 Kudos
2,432

I have a procedure where I have a UNC path as IN parameter. The IN paramater is handled as a varchar. I write '\\\\test\\temp\\filetest.txt'. But the path is not working in the procedure because all bakslash disappear except one? In the procedure, the path will be '\\test\\temp\\filetest.txt'? Why, and how do I solve the problem?

Accepted Solutions (1)

Accepted Solutions (1)

MarkCulp
Participant

Backslashes are used to escape special characters (e.g. \\n represents a newline character). When a backslash precedes a character (or character sequence) that is not a valid escaped character then the backslash is left alone.

If you intend for a backslash to not be an escape sequence in a string you need to double up the backslash.

You can read more about escape sequences in SQL strings in the documentation.

HTH

0 Kudos

IN to the procedure is '\\\\test\\temp\\filetest.txt'. Four backslashes first and two between. That will retun '\\test\\temp\\filetest.txt' in the procedure.

So you mean that I should write '\\\\\\test\\\\temp\\\\filetest.txt' IN to the procedure? Six backslashes first and four between.

VolkerBarth
Contributor
0 Kudos

Four backslashes first and two between. That will retun '\\test\\temp\\filetest.txt' in the procedure.

That's unusual, it should be used as

 '\\\\test\\temp\\filetest.txt' 

.

Do you use EXECUTE IMMEDIATE within the procedure? - If so, note that this may mean you have to "double" the doubled backslashes again or use the WITH ESCAPES OFF clause, see the cited doc page.

graeme_perrow
Advisor
Advisor
0 Kudos

It may also depend on how you call the procedure. For example, if you're calling dbisql -c ... call myproc('\\\\\\\\test\\\\temp\\\\filetest.txt') from a command shell, the command shell itself may use the same escaping. You may need to double the backslashes twice, i.e. 8 at the beginning and 4 as directory separators.

Breck_Carter
Participant

...and sometimes you can get away with using a single forward slash to represent a single back slash in a SQL Anywhere string literal. The word "sonetimes" is a warning that sometimes you are NOT coding a SQL Anywhere string literal but a Windows command string literal so your results depend on the context.

And watch out for Ba'al...

Answers (0)