Reputation: 17
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);
}
this is my function to insert db and call it like that
InsertEmployeeRec(conn,"n");
At the end, i get the error:
glibc detected * /home/mert/workspace1/Project/Debug/Project: double free or corruption (!prev): 0x0000000001df4050 *
What might be the problem?
Upvotes: 0
Views: 93
Reputation: 125574
If there is more than one column in the Worker table you will need to declare them:
sSQL.append("INSERT INTO Worker (one_column, name, another_one) VALUES ('");
You only need to declare the columns without a default value.
Upvotes: 0