Package uk.ac.starlink.table.jdbc
Class SqlSyntax
java.lang.Object
uk.ac.starlink.table.jdbc.SqlSyntax
Summarises some aspects of the syntax of an SQL variant,
and provides some utilities based on that.
- Since:
- 7 Jun 2013
- Author:
- Mark Taylor
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]
Returns a list of words that are known to be reserved in a mixed bag of popular RDBMSs.Returns an alphabetical list of the reserved words known by this class, in normalised (upper case) form.boolean
isIdentifier
(String word) Indicates whether a given word is syntactically permitted to act as an identifier.boolean
isReserved
(String word) Indicates whether a given word is reserved.Returns a quoted version of a word.quoteIfNecessary
(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.
-
Field Details
-
SQL92_IDENTIFIER_REGEX
Standard regular expression for identifiers, as per SQL92. -
SQL92_RESERVED
SQL92 list of reserved words. This list was actually taken from ADQL 2.0 standard.
-
-
Constructor Details
-
SqlSyntax
Constructor.- Parameters:
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 embedded
-
-
Method Details
-
getReservedWords
Returns an alphabetical list of the reserved words known by this class, in normalised (upper case) form.- Returns:
- unmodifiable set of reserved words
-
isReserved
Indicates whether a given word is reserved. The result is not sensitive to the case of the supplied word.- Parameters:
word
- word to test- Returns:
- true iff reserved
-
isIdentifier
Indicates whether a given word is syntactically permitted to act as an identifier.- Parameters:
word
- word to test- Returns:
- true iff identifier
-
quoteIfNecessary
Returns a string which can be used within an SQL query to refer to an item with the name of a given word. If the given word can be used as it stands, it is returned as given. Otherwise (if it's reserved or syntactically unsuitable) a quoted version of the provided word is returned.- Parameters:
word
- word to use- Returns:
- quoted or unquoted version of
word
-
quote
Returns a quoted version of a 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.- Parameters:
word
- word to quote- Returns:
- quoted word
-
getParanoidReservedWords
Returns a list of words that are known to be reserved in a mixed bag of popular RDBMSs.- Returns:
- reserved word list
-