microsoft / ODBC-Specification

Microsoft ODBC Specification
Other
121 stars 40 forks source link

Define a safe-cast function #40

Closed mikepizzo closed 8 years ago

mikepizzo commented 8 years ago

When working with variant and dynamic columns, it would be particularly useful to have a cast function that returned null, rather than an exception, when performing a cast.

Options: 1) Define a function, SAFECONVERT, similar to CONVERT but with the semantics that it returns null if the convert fails. Since this a function, like CONVERT it would be invoked with the function-escape:

  {fn SAFECONVERT(variant_column,SQL_INTEGER)}

2) If we wanted a slightly simpler way to invoke the safe cast, we could define a safe_cast escape clause that returns null if the cast fails:

ODBC-safe-cast-escape ::=      ODBC-esc-initiator safe_cast ( value-exp, data-type ) ODBC-esc-terminator

This could be (slightly more simply) invoked as:

  {safe_cast(varcol, SQL_INTEGER)}
mikepizzo commented 8 years ago

Syntax is not that much different, so for consistency defined SAFECONVERT function.