microsoft / ODBC-Specification

Microsoft ODBC Specification
Other
121 stars 40 forks source link

What do drivers report for strings and exact numerics with no defined length/precision/scale limit? #3

Closed mikepizzo closed 7 years ago

mikepizzo commented 8 years ago

If the driver returns max length, the application may allocate inappropriate space or always use SQLGetData (which is less efficient).

With ODBC 4.0, if SQL_SQL_ATTR_LENGTH_EXCEPTION is SQL_LE_REPORT, the driver can report length exceptions at fetch time that allow the application to fetch data larger than the allocated size. So if the driver doesn't know, it might be better off guessing a conservative length and letting the application handle exceptions.

Should we have a way for the driver to signal that a returned max length is an estimate? For ODBC 3.x, should it continue to report max length?

lpillar commented 7 years ago

Isn't this already captured by the spec? For variable length columns, SQLFetch and friends should return SQL_MORE_DATA iff there's more data, and the length shouldn't be a factor in determining whether additional steps should be taken. The str_len_or_ind buffer should contain SQL_NO_TOTAL for unknown sizes, and any other value should be correct. If a driver always returns max length for the sake of convenience, that's going to have an inevitable performance hit: it would be better to either return a real value or just admit that it's not known.

mikepizzo commented 7 years ago

No change for 3.x. It probably has to report a reasonable maximum length or the client will have to deal with truncation.

No demonstrated need for 4.x to return that a length is an estimate; clients should be prepared via SQL_ATTR_LENGTH_EXCEPTION. If we have a need for such a flag we could add it later.