I was looking for a way to retrieve bytea data from a result without copying it. I tried to use fieldstream using libpqxx-2.6.8 but I got escaped data.
I don't know it it's a bug (I hope so). If it is not, how do I retrieve bytea data without using much more than bytea data size of memory?
This is roughly code I used:
result R;
...
pqxx::fieldstream file_data(R.at(0)["file_data"]);
#define CACHESIZE (0x7fff) /* minimum POSIX limit for read cache size */
char data_cache[CACHESIZE];
ofstream out;
out.exceptions(ofstream::failbit | ofstream::badbit);
out.open("filename", ios::binary);
while ( file_data.good() && out.good() ) {
file_data.read(data_cache, CACHESIZE);
out.write(data_cache, file_data.gcount());
}
out.close();