EnquoteIdentifier(identifier, bAlwaysQuote, bCapitalize)
This method adds double quotes to the identifier if missing and returns the result.
Declaration
// C# public static string EnquoteIdentifier(string identifier, bool bAlwaysQuote = true, bool bCapitalize = true);
Parameters
-
identifier
The input identifier.
-
bAlwaysQuote
If
true
, then the returned identifier is always quoted. Iffalse
, then quotes will only be added for a simple identifier that is not already quoted if the case needs to be preserved. -
bCapitalize
If
true
, a simple identifier will be uppercased except when it is already double quoted. Iffalse
, it is case-sensitive, and case will be preserved with double quotes, if it contains a lowercase letter.
Return Value
The identifier is returned with double quotes, except for a simple identifier that is not already quoted in either of the following cases:
-
bAlwaysQuote
isfalse
andbCapitalize
istrue
. -
bAlwaysQuote
isfalse
,bCapitalize
isfalse
, and the identifier is uppercase.
Exceptions
ArgumentNullException - Value cannot be null. (Parameter 'identifier'
)
OracleException - Invalid identifier or literal.
Remarks
This method's purpose is to prevent SQL injection.
Simple SQL names are supported as identifiers. In other words, qualified SQL names are not supported. For example, SCHEMA.TABLE
would be a qualified SQL name.
A simple identifier that is not already quoted will only get quoted if bAlwaysQuote
is true
, or bCapitalize
is false
and it contains a lowercase letter. It will be uppercased if bCapitalize
is true
.
A quoted identifier is returned as is, but the identifier being quoted cannot contain double quotes or the null character.
Other identifiers can contain any characters, except double quotes and the null character. The identifier will be enclosed in double quotes.
Empty identifiers are not allowed.
Leading and trailing white space is not ignored nor trimmed when quoted.
Reserved words will always be quoted.
If validation of the identifier length and representation in the database character set is needed, then use the other EnquoteIdentifier
overload.