Class MsDiffUtils

java.lang.Object
org.pgcodekeeper.core.MsDiffUtils

public class MsDiffUtils extends Object
Utility class for handling quoting and unquoting of identifiers and literals in Microsoft SQL.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    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 String
    Removes square brackets from an identifier if present.
    static boolean
    isValidId(String id, boolean allowKeywords, boolean allowCaps)
    Checks if a string is a valid Microsoft SQL identifier.
    static boolean
    isValidIdChar(char c)
    Checks if character is valid for Microsoft SQL identifiers.
    static boolean
    isValidIdChar(char c, boolean allowCaps, boolean allowDigits)
    Checks if character is valid for Microsoft SQL identifiers.
    static String
    Quotes an identifier using Microsoft SQL square bracket syntax.
    static String
    Unquotes a square bracket-quoted identifier.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • quoteName

      public static String quoteName(String name)
      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

      public static boolean isValidId(String id, boolean allowKeywords, boolean allowCaps)
      Checks if a string is a valid Microsoft SQL identifier.
      Parameters:
      id - the identifier to validate
      allowKeywords - whether to allow reserved keywords as identifiers
      allowCaps - 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 check
      allowCaps - whether to allow uppercase letters
      allowDigits - whether to allow digits
      Returns:
      true if character is valid for Microsoft SQL identifiers, false otherwise
    • getQuotedName

      public static String getQuotedName(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.
      Parameters:
      name - name
      Returns:
      quoted string if needed, otherwise not quoted string
    • unquoteQuotedName

      public static String unquoteQuotedName(String name)
      Unquotes a square bracket-quoted identifier.
      Parameters:
      name - the quoted identifier
      Returns:
      the unquoted identifier
    • getUnQuotedName

      public static String getUnQuotedName(String name)
      Removes square brackets from an identifier if present.
      Parameters:
      name - the identifier to process
      Returns:
      the identifier without surrounding brackets