Forum: Ruby escaping in MSSQL script?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ea97ad3789541367331966f009f549cb?d=identicon&s=25 Chris McMahon (Guest)
on 2006-01-11 23:13
(Received via mailing list)
Hi...
Can anyone suggest the proper way to escape the backslashes in the
directory name in the following script?


d = c.run("ALTER DATABASE fooDB MODIFY FILE (NAME = foo_log, FILENAME =
'C:\\Program Files\Microsoft SQL
Server\MSSQL\fooPlus\fooPlus_log.LDF'")

The obvious solutions yield either "Incorrect syntax..." or "Invalid
escape character syntax" messages.

Thanks...
-CHris
430ea1cba106cc65b7687d66e9df4f06?d=identicon&s=25 David Vallner (Guest)
on 2006-01-11 23:31
(Received via mailing list)
Chris McMahon wrote:

>escape character syntax" messages.
>
>Thanks...
>-CHris
>
>
>
>
Four backslashes should work. Wildly guessing only.
Ea97ad3789541367331966f009f549cb?d=identicon&s=25 Chris McMahon (Guest)
on 2006-01-11 23:50
(Received via mailing list)
Good guess, but

'C:\\\\Program Files\\Microsoft
SQLServer\MSSQL\\fooPlus\\fooPlus_log.LDF'

yields

Incorrect syntax near 'C:\\Program Files\Microsoft SQL
Server\MSSQL\data\fooPlus\fooPlus_log.LDF'
D3574e6039c84c7d2972bd95aef3bb49?d=identicon&s=25 jeem (Guest)
on 2006-01-11 23:59
(Received via mailing list)
Shouldn't you have c:\\what\\ever or c:\what\ever?  It's not a URL :)
430ea1cba106cc65b7687d66e9df4f06?d=identicon&s=25 David Vallner (Guest)
on 2006-01-12 00:35
(Received via mailing list)
Chris McMahon wrote:

>
>
>
I meant four backslashes -everywhere-. Gets escaped to two backslashes
by Ruby, then to one backslash by MS SQL.

David Vallner
D05623be23ac664b917ddd66bb3ed4ae?d=identicon&s=25 Joby Bednar (Guest)
on 2006-01-12 01:21
(Received via mailing list)
d = c.run("...'c:\\\\blah..'..")

rather than using double quotes which processes escapes within, use
single quotes and use \' when you need single quotes within?

d = c.run('...\'c:\\blah..\'..')

-Joby
E6cd9eab032b40b10c621e186133ff53?d=identicon&s=25 moogs (Guest)
on 2006-01-12 01:27
(Received via mailing list)
Joby Bednar wrote:
> d = c.run("...'c:\\\\blah..'..")
>
> rather than using double quotes which processes escapes within, use
> single quotes and use \' when you need single quotes within?
>
> d = c.run('...\'c:\\blah..\'..')
> -Joby

you still need to escape backslashes even when using single-quoted
string
literals. (maybe you're referring to php?)

--moogs
430ea1cba106cc65b7687d66e9df4f06?d=identicon&s=25 David Vallner (Guest)
on 2006-01-12 03:10
(Received via mailing list)
moogs wrote:

>
> you still need to escape backslashes even when using single-quoted
> string literals. (maybe you're referring to php?)
>
> --moogs
>
Doesn't Ruby have a general delimiter wart for raw strings? I know
Python has, can't recall about Ruby.

David Vallner
This topic is locked and can not be replied to.