mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-22 01:25:38 -05:00
Surfacing better error messages about SQLCMD var names (#22509)
* Surfacing better error messages about SQLCMD var names * correcting docstring * adding space to join char
This commit is contained in:
@@ -242,25 +242,24 @@ export function formatSqlCmdVariable(name: string): string {
|
||||
* Checks if it's a valid sqlcmd variable name
|
||||
* https://docs.microsoft.com/en-us/sql/ssms/scripting/sqlcmd-use-with-scripting-variables?redirectedfrom=MSDN&view=sql-server-ver15#guidelines-for-scripting-variable-names-and-values
|
||||
* @param name variable name to validate
|
||||
*/
|
||||
export function isValidSqlCmdVariableName(name: string | undefined): boolean {
|
||||
* @returns null if valid, otherwise an error message describing why input is invalid
|
||||
*/
|
||||
export function validateSqlCmdVariableName(name: string | undefined): string | null {
|
||||
// remove $() around named if it's there
|
||||
name = removeSqlCmdVariableFormatting(name);
|
||||
const cleanedName = removeSqlCmdVariableFormatting(name);
|
||||
|
||||
// can't contain whitespace
|
||||
if (!name || name.trim() === '' || name.includes(' ')) {
|
||||
return false;
|
||||
if (!cleanedName || cleanedName.trim() === '' || cleanedName.includes(' ')) {
|
||||
return constants.sqlcmdVariableNameCannotContainWhitespace(name ?? '');
|
||||
}
|
||||
|
||||
// can't contain these characters
|
||||
if (name.includes('$') || name.includes('@') || name.includes('#') || name.includes('"') || name.includes('\'') || name.includes('-')) {
|
||||
return false;
|
||||
if (constants.illegalSqlCmdChars.some(c => cleanedName?.includes(c))) {
|
||||
return constants.sqlcmdVariableNameCannotContainIllegalChars(name ?? '');
|
||||
}
|
||||
|
||||
// TODO: tsql parsing to check if it's a reserved keyword or invalid tsql https://github.com/microsoft/azuredatastudio/issues/12204
|
||||
// TODO: give more detail why variable name was invalid https://github.com/microsoft/azuredatastudio/issues/12231
|
||||
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user