May be I done a mistake, how can i please direct insert binary float in my table. I don't know if i done the things right. The code works but the values are not correct Thank you for reply
static void to_nbo(double in, double *out) {
uint64_t *i = (uint64_t *)∈
uint32_t *r = (uint32_t *)out;
/* convert input to network byte order */
r[0] = htonl((uint32_t)((*i) >> 32));
r[1] = htonl((uint32_t)*i);
}
const char command[] = "INSERT INTO car1 (id, price, sale)"
"VALUES($1::integer, $2::real, $3::real)";
int nParams = 3;
//const char *const paramValues[] = {"2.545","44.655"};
const Oid paramTypes[] = {23, 700, 700};
const int paramLengths[] = {sizeof(int), sizeof(int), sizeof(int)};
const int paramFormats[] = {1, 1, 1};
int resultFormat = 0;
int test = htonl(45);
double test2;
double test3;
to_nbo(75.585, &test2);
to_nbo(8.4785, &test3);
//char paramFloat[] ={0x41,0x40,0x00,0x00}; //12.0
//char paramFloat1[] ={0x42,0x32,(char) 0x9e, (char) 0xb8}; //44.655
//char paramFloat[] ={0x00,0x00, 0x40,0x41}; //12.0
//char paramFloat1[] ={(char) 0xb8,(char) 0x9e,0x32,0x42}; //44.655
//const char *const paramValues2[] = {paramFloat, paramFloat1};
const char *const paramValues2[] = {(const char*)&test, (const char*)&test2, (const char*)&test3};
/* PQexecParams INSERT */
res = PQexecParams(conn, command, nParams, paramTypes, paramValues2, paramLengths, paramFormats, resultFormat);
if (PQresultStatus(res) != PGRES_COMMAND_OK) {
std::cout << "PQexecParams failed: " << PQresultErrorMessage(res)
<< std::endl;
}