postgresql-interfaces / psqlodbc

Other
16 stars 15 forks source link

SQLGetData function can return an incorrect SQLSTATE #33

Closed omeuid closed 3 months ago

omeuid commented 4 months ago

Hi,

The ODBC API documentation of the SQLGetData function says:

If the data is NULL and StrLen_or_IndPtr was a null pointer, SQLGetData returns SQLSTATE 22002 (Indicator variable required but not supplied).

But the PostgreSQL ODBC driver returns a generic HY000 SQLSTATE.

As I understand, to fix the issue the following change could be made.

In the _copy_and_convertfield method from the convert.c file, replace the next fragment:

{
    SC_set_error(stmt, STMT_RETURN_NULL_WITHOUT_INDICATOR, "StrLen_or_IndPtr was a null pointer and NULL data was retrieved", func);
    return  SQL_ERROR;
}

by the next one:

{
    SC_set_error(stmt, STMT_RETURN_NULL_WITHOUT_INDICATOR, "StrLen_or_IndPtr was a null pointer and NULL data was retrieved", func);
    return  COPY_GENERAL_ERROR;
}

Regards, Carlos

Hunaid2000 commented 4 months ago

Yes, I agree with you. Actually in PGAPI_GetData function after copy_and_convert_field call that returns SQL_ERROR it goes in default case and overrides the error. So, copy_and_convert_field should return COPY_GENERAL_ERROR.

https://github.com/postgresql-interfaces/psqlodbc/blob/c5053678f09ac204816b7ca7d6624af0f4987e70/results.c#L1097-L1139

davecramer commented 4 months ago

@omeuid can you provide a Pull Request please ?