org.eclipse.datatools.sqltools.sqlbuilder.util
Class SQLIdentifier

java.lang.Object
  extended by org.eclipse.datatools.sqltools.sqlbuilder.util.SQLIdentifier

public class SQLIdentifier
extends java.lang.Object

The main methods of this class help handle ordinary and delimited SQL identifiers, and can be understood according to the origin of the identifier and their intended use:

Identifiers from DB2 catalogs:
Identifiers from user input:

Other methods provide supporting function.

The methods implement the following differences between platforms:

For definitions of an ordinary SQL identifier see the online documentation:

Version:
%I%, %G%
Author:
Thomas Sharp

Field Summary
static java.lang.String CLOUDSCAPE
          For identifying DatabaseDefinitions vendor names for IBM Cloudscape.
static java.lang.String DB2_ISERIES
          For identifying DatabaseDefinitions vendor names for DB2 for iSeries.
static java.lang.String DB2_LUW0
          For identifying DatabaseDefinitions vendor names for DB2 for workstation.
static java.lang.String DB2_ZSERIES
          For identifying DatabaseDefinitions vendor names for DB2 for zSeries.
static java.lang.String DERBY
          For identifying DatabaseDefinitions vendor names for Derby.
static int PLATFORM_390
          OS/390, z/OS.
static java.lang.String PLATFORM_390_KEY
          Hash key for OS/390, z/OS
static int PLATFORM_400
          OS/400, iSeries.
static java.lang.String PLATFORM_400_KEY
          Hash key for OS/400, iSeries.
static int PLATFORM_ALL
          LUWO, 390, 400, and Cloudscape
static int PLATFORM_ANY
          Any platform.
static int PLATFORM_CLOUDSCAPE
          Cloudscape.
static java.lang.String PLATFORM_CLOUDSCAPE_KEY
          Hash key for Cloudscape.
static int PLATFORM_DB2
          LUWO, z/OS, and iSeries
static int PLATFORM_DERBY
          Derby.
static int PLATFORM_INFORMIX
          Informix.
static int PLATFORM_LUWO
          LUWO: Linux, UNIX, Windows, and OS/2.
static java.lang.String PLATFORM_LUWO_KEY
          Hash key for LUWO: Linux, UNIX, Windows, and OS/2.
static int PLATFORM_ORACLE
          Oracle.
static int PLATFORM_OTHER
          Any other platform.
static java.lang.String PLATFORM_OTHER_KEY
          Hash key for any other platform.
static int PLATFORM_SQLSERVER
          SQL Server.
static int PLATFORM_SYBASE
          Sybase.
static int TRIM_ALL
          All of the above.
static int TRIM_BOTH
          Trim from the left and the right.
static int TRIM_INSIDE
          Trim inside the specified delimiter from the right.
static int TRIM_LEFT
          Trim from the left.
static int TRIM_RIGHT
          Trim from the right.
 
Method Summary
static boolean beginsWith(java.lang.String id, java.lang.String prefix, char delimiter)
          Returns true if the two SQL identifiers match to the length of prefix.
static boolean checkName(java.util.Enumeration e, java.lang.String identifier, char delimiter)
          Checks the passed uniqueName is in the passed Enumeration of names and returns true if found, false otherwise.
static java.lang.String concatIdentifier(java.lang.String id, java.lang.Object add, char delimiter)
          Returns a new identifier concatonating the toString of the object (before the closing delimiter if need be).
static java.lang.String convertAuthID(java.lang.String id, char delim, int platforms)
          Returns the input authorization ID in SQL format.
static java.lang.String convertAuthID(java.lang.String id, ISQLEditorConnectionInfo coninfo)
          Returns the input authorization ID in SQL format.
static java.lang.String convertDBID(java.lang.String id, char delimiter)
          Returns the input SQL identifier ready to be used in an SQL statement for DB2 UDB for LUWO.
static java.lang.String convertDBID(java.lang.String id, char delimiter, int platforms)
          Returns the input SQL identifier ready to be used in an SQL statement for LUWO, OS/390, or OS/400 or a combination of platforms.
static java.lang.String convertDBID(java.lang.String id, char delimiter, int platforms, boolean checkReserved)
          Returns the input SQL identifier ready to be used in an SQL statement for LUWO, OS/390, or OS/400 or a combination of platforms.
static java.lang.String convertUserInput(java.lang.String id, char delimiter)
          Returns the user-input SQL identifier as DB2 for LUWO would store it.
static java.lang.String convertUserInput(java.lang.String id, char delimiter, int platforms)
          Returns the input SQL identifier either converted to uppercase, if it is an ordinary identifier ignoring the case of each letter, or delimited, if it cannot be an ordinary identifier, for LUWO, OS/390, or OS/400 or a combination of platforms.
static boolean equals(java.lang.String ident1, java.lang.String ident2, char delimiter)
          Returns true if two SQL identifiers are "equal" for DB2 UDB for LUWO.
static boolean equals(java.lang.String ident1, java.lang.String ident2, char delimiter, int platforms)
          Returns true if two SQL identifiers in SQL format are "equal" for LUWO, OS/390, or OS/400 or a combination of platforms.
static boolean equals(java.lang.String id1, java.lang.String id2, ISQLEditorConnectionInfo coninfo)
          Returns true if two SQL identifiers in SQL format are "equal" for the given connection.
static long getCatalogLength(java.lang.String text, ISQLEditorConnectionInfo aConInfo)
          Determines the length in the database catalog of a given Java String.
static char getDelimiter(java.sql.Connection connection)
           
static java.lang.String getIdentifierQuoteString(ISQLEditorConnectionInfo connInfo)
          Returns the IdentifierQuoteString for a database via a database connection.
static int getPlatform(ISQLEditorConnectionInfo aConInfo)
          Returns the code for the DB2 platform represented by a given Connection object.
static long getUTF8Length(java.lang.String text)
          Determines the length in UTF-8 of a given Java String.
static int[] getVersion(ISQLEditorConnectionInfo aConInfo)
          Returns the version, release, and modification levels, as specified in the ISQLEditorConnectionInfo or DatabaseDefinition.
static java.util.List initReserved(java.lang.String vendor, java.lang.String version)
          Returns a List of SQL keyswords for the given vendor and version.
static boolean isDB2SpecialChar(char c)
          Returns true if the given character is a DB2 special character.
static boolean isDBIDOrdinary(java.lang.String id)
          Returns true if the given string is an ordinary identifier for DB2 UDB for LUWO; otherwise returns false.
static boolean isDBIDOrdinary(java.lang.String id, char delimiter, int platforms)
          Returns true if the given identifier from DB2 is an ordinary identifier for LUWO, OS/390, or OS/400 or a combination of platforms; otherwise returns false.
static boolean isDBIDOrdinary(java.lang.String id, int platforms)
          Returns true if the given identifier from DB2 is an ordinary identifier for LUWO, OS/390, or OS/400 or a combination of platforms; otherwise returns false.
static boolean isOrdinary390Char(char ch)
          Determines if the specified character is an ordinary character for OS/390.
static boolean isOrdinary400Char(char ch)
          Determines if the specified character is an ordinary character for OS/400.
static boolean isOrdinaryChar(char ch, int platforms)
          Determines if the specified character is an ordinary character for LUWO, OS/390, OS/400, or a combination of platforms, for user input.
static boolean isOrdinaryCloudscapeChar(char ch)
          Determines if the specified character is an ordinary character for IBM Cloudscape.
static boolean isOrdinaryDigit(char c)
          Returns true if the given char is in the range 0..9.
static boolean isOrdinaryLUWOChar(char ch)
          Determines if the specified character is an ordinary character for LUWO.
static boolean isOrdinaryOtherChar(char ch)
          Determines if the specified character is an ordinary character for a database whose ordinary characters are specified using setExtraOrdinaryChars(String).
static boolean isOrdinaryUpperChar(char ch, int platforms)
          Determines if the specified character is an ordinary character for LUWO, OS/390, OS/400, or a combination of platforms, for an identifier in DB2.
static boolean isReservedIdentifier(java.lang.String id, char delimiter)
          Returns true if the given SQL identifier is a reserved word for DB2 UDB for LUWO.
static boolean isReservedIdentifier(java.lang.String id, char delimiter, int platforms)
          Returns true if the given SQL ordinary identifier is a reserved word for DB2 UDB for LUWO, OS/390, OS/400, or a combination of platforms.
static boolean isReservedIdentifier(java.lang.String id, ISQLEditorConnectionInfo coninfo)
          Returns true if the given SQL ordinary identifier is a reserved word.
static boolean isReservedSchema(java.lang.String id, char delimiter)
          Returns true if the given SQL identifier is a reserved schema.
static boolean isUserInputOrdinary(java.lang.String id)
          Returns true if the given string is an ordinary identifier for DB2 UDB for LUWO ignoring the case of each letter; otherwise returns false.
static boolean isUserInputOrdinary(java.lang.String id, char delimiter, int platforms)
          Returns true if the given string as input by the user is an ordinary identifier for LUWO, OS/390, or OS/400 or a combination of platforms, ignoring the case of each letter; otherwise returns false.
static boolean isUserInputOrdinary(java.lang.String id, int platforms)
          Returns true if the given string is an ordinary identifier for LUWO, OS/390, or OS/400 or a combination of platforms, ignoring the case of each letter; otherwise returns false.
static void setExtraOrdinaryChars(java.sql.Connection connection)
          Sets the extra characters that you can use in an ordinary identifier (those beyond a-z, A-Z, 0-9 and _), between 35 and 383.
static java.lang.String toCatalogFormat(java.lang.String id, ISQLEditorConnectionInfo coninfo)
          Returns the input SQL identifier as the database at the given connection would store it in its catalog.
static java.lang.String toSQLFormat(java.lang.String id, ISQLEditorConnectionInfo coninfo)
          Returns the input SQL identifier ready to be used in an SQL statement for the given connection.
static java.lang.String trim(java.lang.String id, int side, char delimiter)
          Trims blanks (' '), but not other whitespace characters such as tabs, from the left, the right, and the right inside a delimiter.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLATFORM_ANY

public static final int PLATFORM_ANY
Any platform.

See Also:
Constant Field Values

PLATFORM_LUWO

public static final int PLATFORM_LUWO
LUWO: Linux, UNIX, Windows, and OS/2.

See Also:
Constant Field Values

PLATFORM_390

public static final int PLATFORM_390
OS/390, z/OS.

See Also:
Constant Field Values

PLATFORM_400

public static final int PLATFORM_400
OS/400, iSeries.

See Also:
Constant Field Values

PLATFORM_DB2

public static final int PLATFORM_DB2
LUWO, z/OS, and iSeries

See Also:
Constant Field Values

PLATFORM_CLOUDSCAPE

public static final int PLATFORM_CLOUDSCAPE
Cloudscape.

See Also:
Constant Field Values

PLATFORM_ALL

public static final int PLATFORM_ALL
LUWO, 390, 400, and Cloudscape

See Also:
Constant Field Values

PLATFORM_DERBY

public static final int PLATFORM_DERBY
Derby.

See Also:
Constant Field Values

PLATFORM_INFORMIX

public static final int PLATFORM_INFORMIX
Informix.

See Also:
Constant Field Values

PLATFORM_ORACLE

public static final int PLATFORM_ORACLE
Oracle.

See Also:
Constant Field Values

PLATFORM_SYBASE

public static final int PLATFORM_SYBASE
Sybase.

See Also:
Constant Field Values

PLATFORM_SQLSERVER

public static final int PLATFORM_SQLSERVER
SQL Server.

See Also:
Constant Field Values

PLATFORM_OTHER

public static final int PLATFORM_OTHER
Any other platform.

See Also:
Constant Field Values

PLATFORM_390_KEY

public static final java.lang.String PLATFORM_390_KEY
Hash key for OS/390, z/OS

See Also:
Constant Field Values

PLATFORM_400_KEY

public static final java.lang.String PLATFORM_400_KEY
Hash key for OS/400, iSeries.

See Also:
Constant Field Values

PLATFORM_LUWO_KEY

public static final java.lang.String PLATFORM_LUWO_KEY
Hash key for LUWO: Linux, UNIX, Windows, and OS/2.

See Also:
Constant Field Values

PLATFORM_CLOUDSCAPE_KEY

public static final java.lang.String PLATFORM_CLOUDSCAPE_KEY
Hash key for Cloudscape.

See Also:
Constant Field Values

PLATFORM_OTHER_KEY

public static final java.lang.String PLATFORM_OTHER_KEY
Hash key for any other platform.

See Also:
Constant Field Values

DB2_ZSERIES

public static final java.lang.String DB2_ZSERIES
For identifying DatabaseDefinitions vendor names for DB2 for zSeries.

See Also:
Constant Field Values

DB2_ISERIES

public static final java.lang.String DB2_ISERIES
For identifying DatabaseDefinitions vendor names for DB2 for iSeries.

See Also:
Constant Field Values

DB2_LUW0

public static final java.lang.String DB2_LUW0
For identifying DatabaseDefinitions vendor names for DB2 for workstation.

See Also:
Constant Field Values

CLOUDSCAPE

public static final java.lang.String CLOUDSCAPE
For identifying DatabaseDefinitions vendor names for IBM Cloudscape.

See Also:
Constant Field Values

DERBY

public static final java.lang.String DERBY
For identifying DatabaseDefinitions vendor names for Derby.

See Also:
Constant Field Values

TRIM_ALL

public static final int TRIM_ALL
All of the above.

See Also:
Constant Field Values

TRIM_BOTH

public static final int TRIM_BOTH
Trim from the left and the right.

See Also:
Constant Field Values

TRIM_INSIDE

public static final int TRIM_INSIDE
Trim inside the specified delimiter from the right.

See Also:
Constant Field Values

TRIM_LEFT

public static final int TRIM_LEFT
Trim from the left.

See Also:
Constant Field Values

TRIM_RIGHT

public static final int TRIM_RIGHT
Trim from the right.

See Also:
Constant Field Values
Method Detail

getIdentifierQuoteString

public static java.lang.String getIdentifierQuoteString(ISQLEditorConnectionInfo connInfo)
Returns the IdentifierQuoteString for a database via a database connection.

Parameters:
connInfo - Describes the database connection
Returns:
The IdentifierQuoteString

convertAuthID

public static java.lang.String convertAuthID(java.lang.String id,
                                             ISQLEditorConnectionInfo coninfo)
Returns the input authorization ID in SQL format. Folds to upper case if the ID would be upper-cased in catalog format.

Parameters:
id - An SQL identifier.
coninfo - Describes the database connnection.
Returns:
The authorization ID converted to a SQL identifier in SQL format
See Also:
convertAuthID(String, char, int)

convertAuthID

public static java.lang.String convertAuthID(java.lang.String id,
                                             char delim,
                                             int platforms)
Returns the input authorization ID in SQL format. Folds to upper case if the ID would be upper-cased in catalog format.

Parameters:
id - An SQL identifier.
delim - The delimiter defined as the escape character on the DB2 platform or platforms.
platforms - The sum of platform constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for OS/390
PLATFORM_400
DB2 UDB for OS/400
PLATFORM_CLOUDSCAPE
IBM Cloudscape
PLATFORM_ALL
DB2 UDB for LUWO, OS/390, and OS/400, and IBM Cloudscape
PLATFORM_OTHER
Any other platform
Returns:
The authorization ID converted to a SQL identifier in SQL format.

toCatalogFormat

public static java.lang.String toCatalogFormat(java.lang.String id,
                                               ISQLEditorConnectionInfo coninfo)
Returns the input SQL identifier as the database at the given connection would store it in its catalog.

Equivalent to convertUserInput(String id, char delimiter, int platforms).

Parameters:
id - An SQL identifier.
coninfo - Describes the database connnection.
Returns:
The converted SQL identifier.
See Also:
convertUserInput(String, char, int)

toSQLFormat

public static java.lang.String toSQLFormat(java.lang.String id,
                                           ISQLEditorConnectionInfo coninfo)
Returns the input SQL identifier ready to be used in an SQL statement for the given connection.

Equivalent to convertDBID(String id, char delimiter, int platforms).

Parameters:
id - An SQL identifier.
coninfo - Describes the database connnection.
Returns:
The converted SQL identifier.
See Also:
convertDBID(String, char, int)

beginsWith

public static boolean beginsWith(java.lang.String id,
                                 java.lang.String prefix,
                                 char delimiter)
Returns true if the two SQL identifiers match to the length of prefix. Handles delimiters for both id and prefix.

Parameters:
id - An SQL identifier
prefix - The beginning of an SQL identifier
delimiter - The delimiter defined as the escape character
Returns:
True if the two SQL identifiers match to the length of prefix.

checkName

public static boolean checkName(java.util.Enumeration e,
                                java.lang.String identifier,
                                char delimiter)
Checks the passed uniqueName is in the passed Enumeration of names and returns true if found, false otherwise.

Parameters:
names - Array of names
uniqueName - The name to be checked.
delimiter - The delimiter defined as the escape character
Returns:
True if found false otherwise.

concatIdentifier

public static java.lang.String concatIdentifier(java.lang.String id,
                                                java.lang.Object add,
                                                char delimiter)
Returns a new identifier concatonating the toString of the object (before the closing delimiter if need be). Assumes that the name is well formed, ending with a delimiter if it begins with one.

Parameters:
id - The starting identifier
add - The object to add
delimiter - The delimiter defined as the escape character
Returns:
The resulting identifier

convertDBID

public static java.lang.String convertDBID(java.lang.String id,
                                           char delimiter)
Returns the input SQL identifier ready to be used in an SQL statement for DB2 UDB for LUWO. If the identifier is not an ordinary identifier, the return is delimited; otherwise, the return is the original identifier. This method is used when retrieving an SQL identifier from DB2, where the delimiters have been dropped, so that any needed delimiters are restored.

(Formerly named db2String.)

This method does not guarantee that the identifier is valid; it might violate other rules for identifiers, such as exceeding the maximum length.

For LUWO, OS/390, or OS/400 or a combination of platforms, see convertDBID(String, char, int).

Parameters:
id - An SQL identifier.
delimiter - The delimiter defined as the escape character on the DB2 platform or platforms.
Returns:
The converted SQL identifier.
See Also:
convertDBID(String, char, int)

convertDBID

public static java.lang.String convertDBID(java.lang.String id,
                                           char delimiter,
                                           int platforms)
Returns the input SQL identifier ready to be used in an SQL statement for LUWO, OS/390, or OS/400 or a combination of platforms.

Returns:
convertDBID(String,char,int,true)

convertDBID

public static java.lang.String convertDBID(java.lang.String id,
                                           char delimiter,
                                           int platforms,
                                           boolean checkReserved)
Returns the input SQL identifier ready to be used in an SQL statement for LUWO, OS/390, or OS/400 or a combination of platforms. If the identifier is not an ordinary identifier, the return is delimited and any internal delimiters are doubled; otherwise, the return is the original identifier. This method is used when retrieving an SQL identifier from DB2, where the delimiters have been dropped, so that any needed delimiters are restored.

(Formerly named db2String.)

This method does not guarantee that the identifier is valid; it might violate other rules for identifiers, such as exceeding the maximum length.

Parameters:
id - An SQL identifier.
delimiter - The delimiter defined as the escape character on the DB2 platform or platforms.
platforms - The sum of platform constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for OS/390
PLATFORM_400
DB2 UDB for OS/400
PLATFORM_CLOUDSCAPE
IBM Cloudscape
PLATFORM_ALL
DB2 UDB for LUWO, OS/390, and OS/400, and IBM Cloudscape
PLATFORM_OTHER
Any other platform
checkReserved - whether or not identifier should be checked against list of reserved words when considering 'ordinaryness'. Default true.
Returns:
The converted SQL identifier for the specified platforms.

convertUserInput

public static java.lang.String convertUserInput(java.lang.String id,
                                                char delimiter)
Returns the user-input SQL identifier as DB2 for LUWO would store it. It is either converted to uppercase, if it is an ordinary identifier ignoring the case of each letter, or delimited, if it cannot be an ordinary identifier. If the user has begun and ended it with a delimiter, then new delimiters are not added.

(Formerly named handleDB2Identifier.)

This method does not guarantee that the identifier is valid; it might violate other rules for identifiers, such as exceeding the maximum length, or failing to double internal delimiters.

For LUWO, OS/390, or OS/400 or a combination of platforms, see convertUserInput(String, char, int).

Parameters:
id - An SQL identifier.
delimiter - The delimiter defined as the escape character on the DB2 platform or platforms.
Returns:
The converted SQL identifier.
See Also:
convertUserInput(String, char, int)

convertUserInput

public static java.lang.String convertUserInput(java.lang.String id,
                                                char delimiter,
                                                int platforms)
Returns the input SQL identifier either converted to uppercase, if it is an ordinary identifier ignoring the case of each letter, or delimited, if it cannot be an ordinary identifier, for LUWO, OS/390, or OS/400 or a combination of platforms.

(Formerly named handleDB2Identifier.)

This method does not guarantee that the identifier is valid; it might violate other rules for identifiers, such as exceeding the maximum length.

Parameters:
id - An SQL identifier.
delimiter - The delimiter defined as the escape character on the DB2 platform or platforms.
platforms - The sum of platform constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for OS/390
PLATFORM_400
DB2 UDB for OS/400
PLATFORM_CLOUDSCAPE
IBM Cloudscape
PLATFORM_ALL
DB2 UDB for LUWO, OS/390, and OS/400, and IBM Cloudscape
PLATFORM_OTHER
Any other platform
Returns:
The converted SQL identifier for the specified platforms.

equals

public static boolean equals(java.lang.String id1,
                             java.lang.String id2,
                             ISQLEditorConnectionInfo coninfo)
Returns true if two SQL identifiers in SQL format are "equal" for the given connection.

Parameters:
id1 - An SQL identifier in SQL format.
id2 - An SQL identifier in SQL format.
coninfo - Describes the database connnection.
Returns:
True if the two SQL identifiers are "equal."
See Also:
#equal(String, String, char, int)

equals

public static boolean equals(java.lang.String ident1,
                             java.lang.String ident2,
                             char delimiter)
Returns true if two SQL identifiers are "equal" for DB2 UDB for LUWO. Equality of SQL identifiers depends on whether they are delimited. If they are not delimited, they are automatically folded to upper case by DB2. This method assumes that a delimited identifier is properly formed, that is, that it has a closing delimiter, and that an ordinary identifier is valid, that is, that it doesn't include a delimiter.

Parameters:
ident1 - The first identifier
ident2 - The second identifier
delimiter - The delimiter defined as the escape character
Returns:
True if the two SQL identifiers are "equal."

equals

public static boolean equals(java.lang.String ident1,
                             java.lang.String ident2,
                             char delimiter,
                             int platforms)
Returns true if two SQL identifiers in SQL format are "equal" for LUWO, OS/390, or OS/400 or a combination of platforms. Equality of SQL identifiers depends on whether they are delimited. If they are not delimited, they are automatically folded to upper case by DB2. This method assumes that a delimited identifier is properly formed, that is, that it has a closing delimiter, and that an ordinary identifier is valid, that is, that it doesn't include a delimiter.

Parameters:
ident1 - The first identifier
ident2 - The second identifier
delsimiter - The delimiter defined as the escape character
platforms - The sum of platform constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for OS/390
PLATFORM_400
DB2 UDB for OS/400
PLATFORM_CLOUDSCAPE
IBM Cloudscape
PLATFORM_ALL
DB2 UDB for LUWO, OS/390, and OS/400, and IBM Cloudscape
PLATFORM_OTHER
Any other platform
Returns:
True if the two SQL identifiers are "equal."

getCatalogLength

public static long getCatalogLength(java.lang.String text,
                                    ISQLEditorConnectionInfo aConInfo)
Determines the length in the database catalog of a given Java String. Catalog length depends on whether the database is in UTF-8. This method assumes Unicode catalogs for z/OS V8 and LUWO V9 and later.


getUTF8Length

public static long getUTF8Length(java.lang.String text)
Determines the length in UTF-8 of a given Java String.

Each character in a Java String is has a numeric value. The following table defines the number of octets needed to represent this value by its numeric range. This table is derived from the description of UTF-8 at http://ietf.org/rfc/rfc2279.txt.

UCS-4 range (in hex)
Number of UTF-8 octets
0000 0001-0000 007F
1
0000 0080-0000 07FF
2
0000 0800-0000 FFFF
3
0001 0000-001F FFFF
4
0020 0000-03FF FFFF
5
0400 0000-7FFF FFFF
6

Terminology:

UCS
Universal Character Set
UTF
UCS Transformation Format, an 8-bit encoding form in which each unicode character is encoded using a variable number of "octets."

Parameters:
text - An arbitrary string or an identifier in catalog format.

getDelimiter

public static char getDelimiter(java.sql.Connection connection)
Parameters:
connection - A live Connection.
Returns:
The delimiter returned by the JDBC implementation, or a double quotation mark if we can't get the delimiter from the connection.

getPlatform

public static int getPlatform(ISQLEditorConnectionInfo aConInfo)
Returns the code for the DB2 platform represented by a given Connection object.

Parameters:
The - connection information object
Returns:
The platform code; one of the constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for OS/390 (and z/OS)
PLATFORM_400
DB2 UDB for OS/400 (and iSeries)
PLATFORM_CLOUDSCAPE
IBM Cloudscape and Derby
PLATFORM_ALL
DB2 UDB for LUWO, OS/390, and OS/400, and IBM Cloudscape
PLATFORM_OTHER
Any other platform

getVersion

public static int[] getVersion(ISQLEditorConnectionInfo aConInfo)
Returns the version, release, and modification levels, as specified in the ISQLEditorConnectionInfo or DatabaseDefinition.

Parameters:
The - connection information object
Returns:

isDB2SpecialChar

public static boolean isDB2SpecialChar(char c)
Returns true if the given character is a DB2 special character. A special character is any of the characters listed below:
' '
An ordinary blank character
'-'
minus sign
'"'
quotation mark or double-quote
'.'
period
'%'
percent
'/'
slash
'&'
ampersand
':'
colon
'\''
apostrophe or single quote
';'
semicolon
'('
left parenthesis
'<'
less than
')'
right parenthesis
'='
equals
'*'
asterisk
'>'
greater than
'+'
plus sign
'?'
question mark
','
comma
'_'
underline or underscore
'|'
vertical bar
'^'
caret
'!'
exclamation mark

Parameters:
c - A character.
Returns:
True if c is a DB2 special character.

isDBIDOrdinary

public static boolean isDBIDOrdinary(java.lang.String id)
Returns true if the given string is an ordinary identifier for DB2 UDB for LUWO; otherwise returns false.

(Formerly named isOrdinaryIdentifier.)

This method is used when retrieving an SQL identifier from DB2, where the delimiters have been dropped and lower-case characters folded to upper case.

This method assumes that the delimiter is '"' and the platform is LUWO. To specify the delimiter and the platform, see isDBIDOrdinary(String, int).

Parameters:
id - A candidate ordinary identifier.
Returns:
True if the id is an ordinary identifier for LUWO.
See Also:
isDBIDOrdinary(String, int), isDBIDOrdinary(String, int)

isDBIDOrdinary

public static boolean isDBIDOrdinary(java.lang.String id,
                                     int platforms)
Returns true if the given identifier from DB2 is an ordinary identifier for LUWO, OS/390, or OS/400 or a combination of platforms; otherwise returns false. For LUWO (at least), "IDENT" is ordinary, even though it is delimited.

(Formerly named isOrdinaryIdentifier.)

This method is used when retrieving an SQL identifier from DB2, where the delimiters have been dropped and lower-case characters folded to upper case.

Parameters:
id - A candidate ordinary identifier.
platforms - The sum of platform constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for OS/390
PLATFORM_400
DB2 UDB for OS/400
PLATFORM_CLOUDSCAPE
IBM Cloudscape
PLATFORM_ALL
DB2 UDB for LUWO, OS/390, and OS/400, and IBM Cloudscape
PLATFORM_OTHER
Any other platform
Returns:
True if the id is an ordinary identifier for the specified platforms.

isDBIDOrdinary

public static boolean isDBIDOrdinary(java.lang.String id,
                                     char delimiter,
                                     int platforms)
Returns true if the given identifier from DB2 is an ordinary identifier for LUWO, OS/390, or OS/400 or a combination of platforms; otherwise returns false. For LUWO (at least), "IDENT" is ordinary, even though it is delimited.

(Formerly named isOrdinaryIdentifier.)

This method is used when retrieving an SQL identifier from DB2, where the delimiters have been dropped and lower-case characters folded to upper case.

Parameters:
id - A candidate ordinary identifier.
delimiter - The delimiter defined as the escape character on the DB2 platform or platforms.
platforms - The sum of platform constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for OS/390
PLATFORM_400
DB2 UDB for OS/400
PLATFORM_CLOUDSCAPE
IBM Cloudscape
PLATFORM_ALL
DB2 UDB for LUWO, OS/390, and OS/400, and IBM Cloudscape
PLATFORM_OTHER
Any other platform
Returns:
True if the id is an ordinary identifier for the specified platforms.

isOrdinary390Char

public static boolean isOrdinary390Char(char ch)
Determines if the specified character is an ordinary character for OS/390. What are the shift-out and shift-in chars translated to in Unicode?

Parameters:
ch - A char.
Returns:
True if the given char is uppercase for the DB2 for OS/390.

isOrdinary400Char

public static boolean isOrdinary400Char(char ch)
Determines if the specified character is an ordinary character for OS/400.

Parameters:
ch - A char.
Returns:
True if the given char is uppercase for the DB2 for OS/400.

isOrdinaryChar

public static boolean isOrdinaryChar(char ch,
                                     int platforms)
Determines if the specified character is an ordinary character for LUWO, OS/390, OS/400, or a combination of platforms, for user input.

Parameters:
ch - A char.
platforms - The sum of platform constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for zSeries
PLATFORM_400
DB2 UDB for iSeries
PLATFORM_CLOUDSCAPE
IBM Cloudscape
PLATFORM_ALL
DB2 UDB for LUWO, zSeries, iSeries, and IBM Cloudscape
The platforms are ignored if you have set the extra characters using setExtraOrdinaryChars(String).
Returns:
True if the given char is an ordinary character for the DB2 platform or platforms.

isOrdinaryDigit

public static boolean isOrdinaryDigit(char c)
Returns true if the given char is in the range 0..9.

Parameters:
c - The char in question.
Returns:
True if c is in the range 0..9.

isOrdinaryLUWOChar

public static boolean isOrdinaryLUWOChar(char ch)
Determines if the specified character is an ordinary character for LUWO.

Parameters:
ch - A char.
Returns:
True if the given char is uppercase for DB2 for LUWO.

isOrdinaryCloudscapeChar

public static boolean isOrdinaryCloudscapeChar(char ch)
Determines if the specified character is an ordinary character for IBM Cloudscape.

Parameters:
ch - A char.
Returns:
True if the given char is uppercase for IBM Cloudscape.

isOrdinaryOtherChar

public static boolean isOrdinaryOtherChar(char ch)
Determines if the specified character is an ordinary character for a database whose ordinary characters are specified using setExtraOrdinaryChars(String).

Parameters:
ch - A char.
Returns:
True if the given char is allowed in an ordinary identifier.

isOrdinaryUpperChar

public static boolean isOrdinaryUpperChar(char ch,
                                          int platforms)
Determines if the specified character is an ordinary character for LUWO, OS/390, OS/400, or a combination of platforms, for an identifier in DB2.

Parameters:
ch - A char.
platforms - The sum of platform constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for OS/390
PLATFORM_400
DB2 UDB for OS/400
PLATFORM_CLOUDSCAPE
IBM Cloudscape
PLATFORM_ALL
DB2 UDB for LUWO, OS/390, and OS/400, and IBM Cloudscape
PLATFORM_OTHER
Any other platform
The platforms are ignored if you have set the extra characters using setExtraOrdinaryChars(String).
Returns:
True if the given char is an uppercase ordinary character for the DB2 platform or platforms.

isReservedIdentifier

public static boolean isReservedIdentifier(java.lang.String id,
                                           char delimiter)
Returns true if the given SQL identifier is a reserved word for DB2 UDB for LUWO. If an identifier is delimited but is exactly equal to a reserved schema within the delimiters, then it is reserved.

Parameters:
id - An SQL identifier.
delimiter - The delimiter defined as the escape character.
Returns:
True if the given identifier is reserved for LUWO.

isReservedIdentifier

public static boolean isReservedIdentifier(java.lang.String id,
                                           char delimiter,
                                           int platforms)
Returns true if the given SQL ordinary identifier is a reserved word for DB2 UDB for LUWO, OS/390, OS/400, or a combination of platforms. If an identifier is delimited but is exactly equal to a reserved schema within the delimiters, then it is a reserved word.

Parameters:
id - An SQL ordinary identifier.
delimiter - The delimiter defined as the escape character on the DB2 platform or platforms.
platforms - The sum of platform constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for OS/390
PLATFORM_400
DB2 UDB for OS/400
PLATFORM_CLOUDSCAPE
IBM Cloudscape
PLATFORM_ALL
DB2 UDB for LUWO, OS/390, and OS/400, and IBM Cloudscape
PLATFORM_OTHER
Any other platform
Returns:
True if the given identifier is reserved for the specified platforms.

isReservedIdentifier

public static boolean isReservedIdentifier(java.lang.String id,
                                           ISQLEditorConnectionInfo coninfo)
Returns true if the given SQL ordinary identifier is a reserved word. This method should be used only for PLATFORM_OTHER. For DB2 and IBM Cloudscape platforms, we have canonical Lists of keywords. See isReservedIdentifier(String id, char delimiter, int platforms).

Parameters:
id - An SQL identifier.
coninfo - Describes the database connnection.
Returns:
True if the id is a keyword, according to the DatabaseDefinition.

isReservedSchema

public static boolean isReservedSchema(java.lang.String id,
                                       char delimiter)
Returns true if the given SQL identifier is a reserved schema. If an identifier is delimited but is exactly equal to a reserved schema within the delimiters, then it is reserved.

Parameters:
id - A schema
delimiter - The delimiter defined as the escape character.
Returns:
True if the given identifier is a reserved schema.

isUserInputOrdinary

public static boolean isUserInputOrdinary(java.lang.String id)
Returns true if the given string is an ordinary identifier for DB2 UDB for LUWO ignoring the case of each letter; otherwise returns false. This method is used when processing an SQL identifier from user input, where delimiters may or may not be provided.

(Formerly named isInputOrdinary.)

This method does not guarantee that the identifier is valid; it might violate other rules for identifiers, such as exceeding the maximum length.

For LUWO, OS/390, or OS/400 or a combination of platforms, see isUserInputOrdinary(String, int).

Parameters:
id - A candidate ordinary identifier.
Returns:
True if the id is an ordinary identifier for LUWO.
See Also:
isUserInputOrdinary(String, int)

isUserInputOrdinary

public static boolean isUserInputOrdinary(java.lang.String id,
                                          char delimiter,
                                          int platforms)
Returns true if the given string as input by the user is an ordinary identifier for LUWO, OS/390, or OS/400 or a combination of platforms, ignoring the case of each letter; otherwise returns false. This method is used when processing an SQL identifier from user input, where delimiters may or may not be provided.

(Formerly named isInputOrdinary.)

This method does not guarantee that the identifier is valid; it might violate other rules for identifiers, such as exceeding the maximum length.

Parameters:
id - A candidate ordinary identifier.
delimiter - The delimiter defined as the escape character on the DB2 platform or platforms.
platforms - The sum of platform constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for OS/390
PLATFORM_400
DB2 UDB for OS/400
PLATFORM_CLOUDSCAPE
IBM Cloudscape
PLATFORM_ALL
DB2 UDB for LUWO, OS/390, and OS/400, and IBM Cloudscape
PLATFORM_OTHER
Any other platform
Returns:
True if the id is an ordinary identifier for the specified platforms.

isUserInputOrdinary

public static boolean isUserInputOrdinary(java.lang.String id,
                                          int platforms)
Returns true if the given string is an ordinary identifier for LUWO, OS/390, or OS/400 or a combination of platforms, ignoring the case of each letter; otherwise returns false. This method is used when processing an SQL identifier from user input, where delimiters may or may not be provided.

(Formerly named isInputOrdinary.)

This method assumes that the delimiter is '"'. To specify the delimiter, see isUserInputOrdinary(String, char, int).

This method does not guarantee that the identifier is valid; it might violate other rules for identifiers, such as exceeding the maximum length.

Parameters:
id - A candidate ordinary identifier.
platforms - The sum of platform constants:
PLATFORM_LUWO
DB2 UDB for Linux, UNIX, Windows, and OS/2
PLATFORM_390
DB2 UDB for OS/390
PLATFORM_400
DB2 UDB for OS/400
PLATFORM_CLOUDSCAPE
IBM Cloudscape
PLATFORM_ALL
DB2 UDB for LUWO, OS/390, and OS/400, and IBM Cloudscape
PLATFORM_OTHER
Any other platform
Returns:
True if the id is an ordinary identifier for the specified platforms.

setExtraOrdinaryChars

public static void setExtraOrdinaryChars(java.sql.Connection connection)
Sets the extra characters that you can use in an ordinary identifier (those beyond a-z, A-Z, 0-9 and _), between 35 and 383. You need this only for databases other than DB2 UDB on LUWO, 390, and 400. If this method is not called, this class uses more complete tables of the allowable characters than you can get from JDBC, but these are available only for the three DB2 UDB platforms.

Parameters:
connection - A live Connection. A null removes the otherOrdinaryFlags.
See Also:
DatabaseMetaData.getExtraNameCharacters().

trim

public static java.lang.String trim(java.lang.String id,
                                    int side,
                                    char delimiter)
Trims blanks (' '), but not other whitespace characters such as tabs, from the left, the right, and the right inside a delimiter. Different in behavior from java.lang.String.trim(), which trims trims all ASCII control characters having codes less than or equal to ' '.

Parameters:
id - An SQL identifier
side - A sum of:
TRIM_LEFT
Trim from the left.
TRIM_RIGHT
Trim from the right.
TRIM_INSIDE
Trim inside the specified delimiter from the right.
TRIM_ALL
All of the above.
delimiter - The delimiter defined as the escape character, used only if (side & TRIM_INSIDE) > 0.

initReserved

public static java.util.List initReserved(java.lang.String vendor,
                                          java.lang.String version)
Returns a List of SQL keyswords for the given vendor and version.

Parameters:
vendor - A vendor name in a DatabaseDefinition.
version - A version string in a DatabaseDefinition.
Returns:
A List of reserved words. Might be null.