Reputation: 85
I am trying to insert values to a postgresql table using libpq (in Binary Format).
Below is my query
insert into client_data (serverid,ipaddress,portid) values ($1,$2,$3)
The data type for table fields are as follows
serverid -> smallint (INT2OID)
ipaddress -> varchar (VARCHAROID)
portid -> integer (INT4OID)
When I'm executing PQexecParams(), I am getting below error (from PQerrorMessage())
ERROR: invalid byte sequence for encoding "UTF8": 0x00
On debugging I found that paramValues for portid is getting error, which is as below
int val = boost::endian::native_to_big(1);
paramValues[3] = (char*)&val; // here is the possible issue
when I'm casting address of val to char pointer and the value pointed by char pointer is evaluated as NULL.
What could be the solution? one way is to insert data as char* and setting ParamFormats to 0 for all.
Upvotes: 0
Views: 268
Reputation: 85
It's my bad. For ipaddress I was passing wrong paramLenghth. I am reading paramaters values from different buffer and insread of passing strlen(ipaddress), I was passinh size of buffer.
Upvotes: 1