2017-02-19 12 views
0

libpq PQexecParams() 함수를 사용하여 레코드를 삭제하려고합니다. 쿼리가 성공적으로 반환되었지만 필수 행은 테이블에서 삭제되지 않습니다. 여기 내 코드에서 발췌 한 내용을 참조하십시오. 나는 PQexecParams()를 select와 insert에 성공적으로 사용했다. 도와 주실 수 있습니까, 제가 무엇을 놓치셨습니까!libpq 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

나는이 문제를 발견했다. 내가 누락되었습니다.

meter_info_id = htonl(meter_info_id); 

추가하여 문제를 해결했습니다.