Subject: [postgresql-interfaces/psqlodbc] PR #70: Fix PG_ErrorInfo and ER_ReturnError when error message is larger than 65535 bytes

From: "r33s3n6 (@r33s3n6)" <[email-masked]>
Date: Sat, 02 Nov 2024 08:39:39 +0000

Old driver truncated the server error message incorrectly.

## old implementation 
environ.c:147:
```c
error->errorsize = (Int2) errsize;
```
When `errsize` is larger than 32767, the errorsize is wrong.

environ.c:204:
```c
msglen = (SQLSMALLINT) strlen(msg);
```
`msglen` is truncated when msg is larger than 65535 bytes.

environ.c:224:
```c
RecNumber = 2 + (error->errorpos - 1) / error->recsize;
```
`errorpos` is used but never set.

## new implementaion
In `PG_ErrorInfo`, makes `errsize`, `errpos` UInt4.
```c
typedef struct
{
        UInt4	status;
	UInt4	errsize;
        UInt4	errpos;
        UInt2	recsize;
        char    sqlstate[6];
        char    __error_message[44];
}       PG_ErrorInfo;
```
Fix `ER_Construct` and `ER_Dup` .
In `ER_ReturnError`, makes `msglen`, `wrtlen`, `pcblen` UInt4, and set `errpos` correctly.
```c
UInt4		stapos, msglen, wrtlen, pcblen;
```
```c
msglen = error->errsize;
```
```c
error->errpos = stapos + wrtlen;
```

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Sat, 02 Nov 2024 10:11:23 +0000

Interesting. Did you run into this in a real situation ?

---

From: "r33s3n6 (@r33s3n6)" <[email-masked]>
Date: Sat, 02 Nov 2024 10:26:56 +0000

Yes, but I was not connecting to Postgres, but another database that gives a very long error message.