C++ 插入数据库失败

C++ 插入数据库失败,c++,postgresql,C++,Postgresql,这是我的函数,插入db并这样调用它 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

这是我的函数,插入db并这样调用它

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);
}
最后,我得到一个错误:

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


可能有什么问题?

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

InsertEmployeeRec(conn,"n");

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

您正在调用
PQclear(res)两次。

当我删除第二个错误时,所有错误都消失了,但我没有插入到db@user2232205这与您发布的问题无关。如果你有新问题,我建议你将其中一个答案标记为已接受,然后发布一个新问题。祝你好运添加
返回
闭合连接(conn)sSQL.append("INSERT INTO Worker (one_column, name, another_one) VALUES ('");