postgresql-interfaces/psqlodbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
[postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte)
10+ messages / 4 participants
[nested] [flat]

* [postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte)
@ 2025-03-18 05:44 "raddakal (@raddakal)" <[email protected]>
  0 siblings, 0 replies; 10+ messages in thread

From: raddakal (@raddakal) @ 2025-03-18 05:44 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>

When We execute the SELECT query on a table containing a TEXT column with one record of size 1048000 bytes, our ODBC application is able to retrieve one byte less than the actual data.

DDL and DML used in the test
------------------------------

postgres=# create table public.rantexttab(textcol text);
CREATE TABLE

postgres=# insert into public.rantexttab values(repeat('A', 1048000) || 'BB');
INSERT 0 1
postgres=# select length(textcol) from public.rantexttab;
 length  
---------
 1048002
(1 row)


Please note that We are using SQL_C_BINARY as the c type to receive the text column data.

We had allocated a buffer of 1048000 in our ODBC program and the size of teh actual data was 1048002, so 2 subsequent SQLGetData calls were made. In the first call, driver returned correctly 1048000 bytes and the in the second call  with the same buffer, driver returns two bytes the last byte contained a null (instead of teh actual last byte in the data).
 

When we did some more analysis, it seems multiple calls to SQLGetData is causing the issue (i.e., there seems to be some gap in the driver code when multiple calls to SQLGetData are made to retrieve the data of the same column in the result set).


Tried to shorten the test case, and instead of using the size of 1048002 bytes, we could reproduce the same issue using 12 bytes of data in TEXT column. When a buffer of size 10 bytes is used and 2 calls to SQLGetData being made, in the second call we could see the last byte was null instead of actual last byte in the column data.

In the shortened test case, the data used:

postgres=# select length(textcol) from public.rantexttab;
 length 
--------
     12
(1 row)

postgres=# SELECT textcol from public.rantexttab
postgres-# ;
   textcol    
--------------
 AAAAAAAAAABB
(1 row)




Standalone ODBC program output:
----------------------------------

bash-4.4$ ./a.out 
Connecting to database.
Connected to database.
Fetching results...
First Call to GetData: 
ind : 12
Data: AAAAAAAAAA

Second Call to GetData: 
ind : 2
Data: B
Free handles.


We can see that in the second call instead of getting BB, we get only B.



Thanks.

[pglob.cpp.txt](https://github.com/user-attachments/files/19307243/pglob.cpp.txt)

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte)
@ 2025-03-18 13:54 ` "raddakal (@raddakal)" <[email protected]>
  8 siblings, 0 replies; 10+ messages in thread

From: raddakal (@raddakal) @ 2025-03-18 13:54 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>

The same issue is seen with CHAR and VARCHAR type columns as well, along with the TEXT type column. The BYTEA type column does not have this issue.

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte)
@ 2025-03-21 00:14 ` "davecramer (@davecramer)" <[email protected]>
  8 siblings, 0 replies; 10+ messages in thread

From: davecramer (@davecramer) @ 2025-03-21 00:14 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>

cool, thanks for the report

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte)
@ 2025-03-24 19:47 ` "davecramer (@davecramer)" <[email protected]>
  8 siblings, 0 replies; 10+ messages in thread

From: davecramer (@davecramer) @ 2025-03-24 19:47 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>

Are you using the latest version?
I just ran your code with some slight changes to connect and the result was 
```
./pglob                                                                        
Connecting to database.
Connected to database.
Fetching results...
First Call to GetData: 
ind : 1048002
Data: AAAAAAAAAA��
Second Call to GetData: 
ind : 1047992
Data: AAAAAAAAAA��
Free handles.
```

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte)
@ 2025-06-16 05:53 ` "raddakal (@raddakal)" <[email protected]>
  8 siblings, 0 replies; 10+ messages in thread

From: raddakal (@raddakal) @ 2025-06-16 05:53 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>

Can you please confirm:
1) if you could reproduce the reported issue?
2) And the slight changes you have made could resolve the issue? If yes, kindly share the changes.


Thanks.

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte)
@ 2025-06-16 10:30 ` "davecramer (@davecramer)" <[email protected]>
  8 siblings, 0 replies; 10+ messages in thread

From: davecramer (@davecramer) @ 2025-06-16 10:30 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>

I cannot reproduce the issue.

```
create table public.rantexttab(textcol text);
CREATE TABLE
test=# insert into public.rantexttab values(repeat('A', 1048000) || 'BB');
INSERT 0 1
test=# select length(textcol) from public.rantexttab;
 length
---------
 1048002
(1 row)
```
```
diff pglob.cpp ~/Downloads/pglob.cpp.txt
48,52c48,51
<     ret = SQLConnect(hdlDbc,
<         (SQLCHAR*) "psqlodbc_test_dsn", SQL_NTS,
<         (SQLCHAR*) "test", SQL_NTS,
<         (SQLCHAR*)"test", SQL_NTS);
<
---
>     const char* dsnName = "pg16";
>     const char* userID = "postgres";
>     const char* passwd = "postgres";
>     ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName, SQL_NTS,(SQLCHAR*)userID,SQL_NTS, (SQLCHAR*)passwd, SQL_NTS);
```

Here is the output from my run
```
./pglob
Connecting to database.
Connected to database.
Fetching results...
First Call to GetData:
ind : 1048002
Data: AAAAAAAAAA�
Second Call to GetData:
ind : 1047992
Data: AAAAAAAAAA�
Free handles.
```

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte)
@ 2025-07-08 06:48 ` "Spark098 (@Spark098)" <[email protected]>
  8 siblings, 0 replies; 10+ messages in thread

From: Spark098 (@Spark098) @ 2025-07-08 06:48 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>

Hello @davecramer 

Can you please try with the shortened test case (as mentioned in the thread before) when we are using buffer of size 10 and inserting data of size 12 bytes of data in the TEXT column.
I could reproduce the issue. 
Native driver version is 16.00.0000

standalone output:

Connecting to database.
Connected to database.
Fetching results...
First Call to GetData:
ind : 12
Data: AAAAAAAAAA
Second Call to GetData:
ind : 2
Data: B
Free handles.


postgres=# select * from rantexttab;
   textcol
--------------
 AAAAAAAAAABB
(1 row)


^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte)
@ 2025-07-12 20:27 ` "davecramer (@davecramer)" <[email protected]>
  8 siblings, 0 replies; 10+ messages in thread

From: davecramer (@davecramer) @ 2025-07-12 20:27 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>

Please use the latest driver.


Dave Cramer


On Tue, 8 Jul 2025 at 02:48, Spark098 ***@***.***> wrote:

> *Spark098* left a comment (postgresql-interfaces/psqlodbc#98)
> <https://github.com/postgresql-interfaces/psqlodbc/issues/98#issuecomment-3047585425;
>
> Hello @davecramer <https://github.com/davecramer;
>
> Can you please try with the shortened test case (as mentioned in the
> thread before) when we are using buffer of size 10 and inserting data of
> size 12 bytes of data in the TEXT column.
> I could reproduce the issue.
> Native driver version is 16.00.0000
>
> standalone output:
>
> Connecting to database.
> Connected to database.
> Fetching results...
> First Call to GetData:
> ind : 12
> Data: AAAAAAAAAA
> Second Call to GetData:
> ind : 2
> Data: B
> Free handles.
> postgres=# select * from rantexttab;
> textcol
>
> AAAAAAAAAABB
> (1 row)
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/postgresql-interfaces/psqlodbc/issues/98#issuecomment-3047585425;,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AADDH5TZWI7H75C7277ZHB33HNSTNAVCNFSM6AAAAABZHG6QMS...;
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>


^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte)
@ 2025-08-25 16:53 ` "Spark098 (@Spark098)" <[email protected]>
  8 siblings, 0 replies; 10+ messages in thread

From: Spark098 (@Spark098) @ 2025-08-25 16:53 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>


I tried with the latest driver but still facing the same issue. (last byte is truncated)
can you please check ?

> Please use the latest driver.
> 
> 
> Dave Cramer
> […](#)



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte)
@ 2026-04-01 02:00 ` "logjing (@logjing)" <[email protected]>
  8 siblings, 0 replies; 10+ messages in thread

From: logjing (@logjing) @ 2026-04-01 02:00 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <[email protected]>

maybe it's solved by https://github.com/postgresql-interfaces/psqlodbc/pull/145

^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2026-04-01 02:00 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-03-18 05:44 [postgresql-interfaces/psqlodbc] issue #98: SELECT of a PostgreSQL CHAR/VARCHAR/TEXT Column Using multiple calls SQLGetData results in data truncation (last byte) "raddakal (@raddakal)" <[email protected]>
2025-03-18 13:54 ` "raddakal (@raddakal)" <[email protected]>
2025-03-21 00:14 ` "davecramer (@davecramer)" <[email protected]>
2025-03-24 19:47 ` "davecramer (@davecramer)" <[email protected]>
2025-06-16 05:53 ` "raddakal (@raddakal)" <[email protected]>
2025-06-16 10:30 ` "davecramer (@davecramer)" <[email protected]>
2025-07-08 06:48 ` "Spark098 (@Spark098)" <[email protected]>
2025-07-12 20:27 ` "davecramer (@davecramer)" <[email protected]>
2025-08-25 16:53 ` "Spark098 (@Spark098)" <[email protected]>
2026-04-01 02:00 ` "logjing (@logjing)" <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox