0

我有一个插入到数据库的函数。

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

  cout << sSQL;

  // 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");
}

当我用 cout 打印 sql 语句时,它会像这样打印:

INSERT INTO Worker (full_name) VALUES ('asd')

我认为这里没有问题。可能是什么原因?

4

0 回答 0