我正在尝试使用libpq PQexecParams()函数删除记录。查询已成功返回,但未从表中删除所需的行。以下是我的代码中的代码段供参考。我已经使用PQexecParams()进行选择并成功插入。你能帮忙吗,我错过了什么!
PGresult *res;
int meter_info_id;
printf ("Enter Meter Information Id");
scanf("%d", &meter_info_id);
char *stm_write_reg = "delete from write_reg_set where meter_id=$1";
int nparam = 1;
//set the values to use
const char *values[1] = {(char *)&meter_info_id};
//calculate the lengths of each of the values
int lengths[1] = {sizeof(meter_info_id)};
//state which parameters are binary
int binary[1] = {1};
res = PQexecParams(conn,
stm_write_reg,
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, "stm_write_reg failed: %s", PQerrorMessage(conn));
exit_nicely(conn,res);
}
PQclear(res);
答案 0 :(得分:0)
我发现了这个问题。 我不见了
meter_info_id = htonl(meter_info_id);
通过添加它,解决了问题。