On Thu, Jun 22, 2006 at 08:52:04AM -0700, Kevin Jenkins wrote: > Previously I was getting a bad result when calling PQexecParams with > binary results because PostgreSQL stores its data big endian. So I > had to do ntohl on the result to get it to little endian. Clarification: PostgreSQL stores data in host byte order but returns it in network byte order if you request binary format. > My question is, do I also need to do htonl then, as in this scenario? > > outStr[0]="blah"; > outLengths[0]=htonl((int)strlen("blah")); > formats[0]=1; > PQexecParams(pgConn, query,1,0,outStr,outLengths,formats,1); Only the data needs byte order conversion; if you convert lengths then you'll probably get a database error or segmentation fault (assuming you're on a machine where host and network byte order differ). I tested the above and PQexecParams failed with ERROR: invalid byte sequence for encoding "SQL_ASCII": 0x00 A packet sniff of the connection showed a large amount of data being transferred (0x04000000 bytes instead of 0x00000004 bytes), so the length needs to be in host byte order. -- Michael Fuhr