public class SqlSyntax
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.regex.Pattern |
SQL92_IDENTIFIER_REGEX
Standard regular expression for identifiers, as per SQL92.
|
static java.lang.String[] |
SQL92_RESERVED
SQL92 list of reserved words.
|
Constructor and Description |
---|
SqlSyntax(java.lang.String[] reservedWords,
java.util.regex.Pattern identifierRegex,
char quoteChar)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String[] |
getParanoidReservedWords()
Returns a list of words that are known to be reserved in a mixed
bag of popular RDBMSs.
|
java.util.SortedSet<java.lang.String> |
getReservedWords()
Returns an alphabetical list of the reserved words known by this class,
in normalised (upper case) form.
|
boolean |
isIdentifier(java.lang.String word)
Indicates whether a given word is syntactically permitted to act as
an identifier.
|
boolean |
isReserved(java.lang.String word)
Indicates whether a given word is reserved.
|
java.lang.String |
quote(java.lang.String word)
Returns a quoted version of a word.
|
java.lang.String |
quoteIfNecessary(java.lang.String word)
Returns a string which can be used within an SQL query to refer to
an item with the name of a given word.
|
public static final java.util.regex.Pattern SQL92_IDENTIFIER_REGEX
public static final java.lang.String[] SQL92_RESERVED
public SqlSyntax(java.lang.String[] reservedWords, java.util.regex.Pattern identifierRegex, char quoteChar)
reservedWords
- list of words considered reserved for this dialectidentifierRegex
- regular expression for an identifier token
in this dialectquoteChar
- character which may be used to quote words in
this dialect (thus avoiding their usual parsing);
words are quoted with a copy of this character
at start and end, doubled if this character is
embeddedpublic java.util.SortedSet<java.lang.String> getReservedWords()
public boolean isReserved(java.lang.String word)
word
- word to testpublic boolean isIdentifier(java.lang.String word)
word
- word to testpublic java.lang.String quoteIfNecessary(java.lang.String word)
word
- word to useword
public java.lang.String quote(java.lang.String word)
Note that quoting words is not harmless - unlike
for instance shell syntax, quotes are not just stripped off
where present before processing, but instead in SQL92 and hence
ADQL they modify the interpretation of what's quoted.
This is something to do with the way case folding is handled,
and I (mbt) didn't know about it until Markus Demleitner
persuaded me it's actually true. As it happens MySQL behaves
contrary to the standard in this respect (quoting of column names -
but not table names?? - is harmless) but (for instance) PostgreSQL
does not. Therefore do not use this method indiscriminately,
use quoteIfNecessary
instead.
word
- word to quotepublic static java.lang.String[] getParanoidReservedWords()