-
Notifications
You must be signed in to change notification settings - Fork 75
Description
Scripting variable names currently allows a-z A-Z 0-9 only. The standard sqlcmd tool is not as strict and .sql-files using underscore in variables fail with syntax error.
The relevant code is in parse.go function readVariableReference.
Take this example (the escaped dollar character is to prevent linux shell from variable substitution):
$ sqlcmd -U SA -v "FOOBAR"="testdb" -Q "create database \$(FOOBAR);"
$ sqlcmd -U SA -v "FOO_BAR"="testdb" -Q "create database \$(FOO_BAR);"
Sqlcmd: Error: Syntax error at line 1.
I haven't found any reference documentation on what characters the standard sqlcmd tool allows other than: https://docs.microsoft.com/en-us/sql/ssms/scripting/sqlcmd-use-with-scripting-variables?view=sql-server-ver15#guidelines-for-scripting-variable-names-and-values
It appears to be very lenient stating only these three guidelines:
- Variable names must not contain white space characters or quotation marks.
- Variable names must not have the same form as a variable expression, such as $(var).
- Scripting variables are case-insensitive
If compatibility with standard sqlcmd name rules are problematic at least consider adding underscore as an allowed character since it is frequently used at least when resolving scripting variables from environment variables.