插入db失败

时间:2013-04-01 17:49:35

标签: c++ postgresql

void InsertEmployeeRec(PGconn *conn, char * fullname)
{
  // Append the SQL statment
  std::string sSQL;
  sSQL.append("INSERT INTO Worker VALUES ('");
  sSQL.append(fullname);
  sSQL.append("')");

  // Execute with sql statement
  PGresult *res = PQexec(conn, sSQL.c_str());

    if (PQresultStatus(res) != PGRES_COMMAND_OK)
    {
        printf("Insert employee record failed");
        PQclear(res);
        CloseConn(conn);
    }

  printf("Insert employee record - OK\n");

  // Clear result
  PQclear(res);
}

这是我插入数据库并将其称为

的函数
InsertEmployeeRec(conn,"n");

最后,我收到错误:

检测到glibc * / home / mert / workspace1 / Project / Debug / Project:double free或corruption(!prev):0x0000000001df4050 *

可能是什么问题?

2 个答案:

答案 0 :(得分:1)

您正在拨打PQclear(res);两次。

答案 1 :(得分:0)

如果Worker表中有多个列,则需要声明它们:

sSQL.append("INSERT INTO Worker (one_column, name, another_one) VALUES ('");

您只需声明没有默认值的列。

相关问题