Package org.pgcodekeeper.core
Class MsDiffUtils
java.lang.Object
org.pgcodekeeper.core.MsDiffUtils
Utility class for handling quoting and unquoting of identifiers and literals in Microsoft SQL.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetQuotedName(String name) If name contains only lower case characters and digits and is not keyword, it is returned not quoted, otherwise the string is returned quoted.static StringgetUnQuotedName(String name) Removes square brackets from an identifier if present.static booleanChecks if a string is a valid Microsoft SQL identifier.static booleanisValidIdChar(char c) Checks if character is valid for Microsoft SQL identifiers.static booleanisValidIdChar(char c, boolean allowCaps, boolean allowDigits) Checks if character is valid for Microsoft SQL identifiers.static StringQuotes an identifier using Microsoft SQL square bracket syntax.static StringunquoteQuotedName(String name) Unquotes a square bracket-quoted identifier.
-
Method Details
-
quoteName
Quotes an identifier using Microsoft SQL square bracket syntax. Escapes any existing square brackets in the name.- Parameters:
name- the identifier to quote- Returns:
- the quoted identifier
-
isValidId
Checks if a string is a valid Microsoft SQL identifier.- Parameters:
id- the identifier to validateallowKeywords- whether to allow reserved keywords as identifiersallowCaps- whether to allow uppercase letters- Returns:
- true if the identifier is valid, false otherwise
-
isValidIdChar
public static boolean isValidIdChar(char c) Checks if character is valid for Microsoft SQL identifiers.- Parameters:
c- the character to check- Returns:
- true if character is valid for Microsoft SQL identifiers, false otherwise
-
isValidIdChar
public static boolean isValidIdChar(char c, boolean allowCaps, boolean allowDigits) Checks if character is valid for Microsoft SQL identifiers.- Parameters:
c- the character to checkallowCaps- whether to allow uppercase lettersallowDigits- whether to allow digits- Returns:
- true if character is valid for Microsoft SQL identifiers, false otherwise
-
getQuotedName
If name contains only lower case characters and digits and is not keyword, it is returned not quoted, otherwise the string is returned quoted.- Parameters:
name- name- Returns:
- quoted string if needed, otherwise not quoted string
-
unquoteQuotedName
Unquotes a square bracket-quoted identifier.- Parameters:
name- the quoted identifier- Returns:
- the unquoted identifier
-
getUnQuotedName
Removes square brackets from an identifier if present.- Parameters:
name- the identifier to process- Returns:
- the identifier without surrounding brackets
-