libpq
을 사용하여 부동 소수점 숫자를 테이블에 삽입하고 있습니다. 이 오류가 발생했습니다 INSERT failed: ERROR: insufficient data left in message
. 여기 libpq를 사용하여 테이블에 부동 소수점 숫자 삽입
printf ("Enter write parameter_value");
scanf("%f", ¶meter_value);
char *stm = "INSERT INTO write_reg_set (parameter_value) VALUES ($1::double precision)";
int nparam = 1;
//set the values to use
const char *values[1] = {(char *)¶meter_value};
//calculate the lengths of each of the values
int lengths[1] = {sizeof(parameter_value)};
//state which parameters are binary
int binary[1] = {1};
PGresult *res = PQexecParams(conn,
stm,
nparam, //number of parameters
NULL, //ignore the Oid field
values, //values to substitute $1 and $2 and so on
lengths, //the lengths, in bytes, of each of the parameter values
binary, //whether the values are binary or not
0); //we want the result in text format
if (PQresultStatus(res) != PGRES_COMMAND_OK) {
fprintf(stderr, "INSERT failed: %s", PQerrorMessage(conn));
exit_nicely(conn,res);
}
PQclear(res);
첫 번째 포인트 : testlibpq2.c는 바이너리 및 텍스트 예제 모두에 대해 ergarding OID가 "백엔드가 매개 변수 유형을 추론합니다"라고 말합니다. Thatswhy 나는 그것을 생략했다. 귀하의 두 번째 포인트가 유효합니다. – Jam
당신은 그것을 전달하는 4 바이트가 두 배라고 추론하는 백엔드가 어떻게 생각하십니까? [문서] (https://www.postgresql.org/docs/current/static/libpq-exec.html#LIBPQ-PQEXECPARAMS)는 다음과 같이 말합니다 : * paramTypes가 NULL이거나 배열의 특정 요소가 0이면 서버는 ** 형식화되지 않은 리터럴 문자열 **. * (emphasis mine)과 동일한 방식으로 매개 변수 심볼에 대한 데이터 유형을 추론합니다. –