Skip to content

PostgreSQL and BYTEA column type #3045

@lrec313

Description

@lrec313

I have found a bug when using a Poco::Data::Statement to read multiples rows of a table with a column data type of "BYTEA" in a PostgreSQL database.

I have created a table with a column of type BYTEA and loaded several rows (example using 'psql'):

test=# create table tbin (id serial primary key, data bytea);
CREATE TABLE
test=# insert into tbin (data) values ('\x111111'), ('\x222222'), ('\x333333');
INSERT 0 3
test=# select * from tbin;
 id |   data   
----+----------
  1 | \x111111
  2 | \x222222
  3 | \x333333
(3 filas)

When I try to read it using:

Statement stm(session);
stm << "SELECT * FROM tbin"s, now;

RecordSet rs(stm);
for (bool more = rs.moveFirst(); more; more = rs.moveNext())
{
	std::cout << rs["id"].toString() << " ";
	BLOB data = rs["data"];
	for (auto it = data.begin(); it != data.end(); ++it)
		std::cout << std::hex << unsigned(*it);
	std::cout << std::endl;
}

I got:

1 111111222222333333
2 111111222222333333
3 111111222222333333

The three 'data' values has been concatenated.

Unfortunately, I have not been able to find in the code why this happens :-(

If someone proposes a patch I can recompile poco library and test it.

Best regards

Luis Recuerda

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions