Subject: [postgresql-interfaces/psqlodbc] issue #33: SQLGetData function can return an incorrect SQLSTATE

From: "omeuid (@omeuid)" <[email-masked]>
Date: Thu, 18 Jul 2024 06:15:01 +0000

Hi,

The ODBC API documentation of the [SQLGetData ](https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetdata-function#retrieving-data-with-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_convert_field_ 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

---

From: "Hunaid2000 (@Hunaid2000)" <[email-masked]>
Date: Thu, 18 Jul 2024 09:23:50 +0000

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

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Thu, 18 Jul 2024 10:30:15 +0000

@omeuid can you provide a Pull Request please ?