EnquoteLiteral(literal)

This method adds single quotes if required, and return the result.

Declaration

// C#
public static string EnquoteLiteral(string literal);

Parameters

  • literal

    The input literal.

Return Value

The literal is returned with single quotes.

Exceptions

ArgumentNullException - Value cannot be null. (Parameter 'identifier')

OracleException - Invalid identifier or literal.

Remarks

This method's purpose is to prevent SQL injection.

Any single quote in the literal is replaced with two single quotes for the purposes of escaping, or overloading. For example, the input string, scott's, becomes 'scott''s' in the return value.

Empty literals are allowed.

Leading and trailing white space is not ignored nor trimmed when quoted.

If validation using the database character set is required, then use the other EnquoteLiteral overload.