插入db失败
Insert db fails
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 - OKn");
// Clear result
PQclear(res);
}
这是我插入数据库的函数,像这样调用
InsertEmployeeRec(conn,"n");
最后,我得到了错误:
glibc检测到*/home/mert/workspace/project/debug/project: double free or corruption (!prev): 0x0000000001df4050 *
可能是什么问题?
您呼叫PQclear(res);
两次
如果Worker表中有多个列,则需要声明它们:
sSQL.append("INSERT INTO Worker (one_column, name, another_one) VALUES ('");
您只需要声明没有默认值的列。
相关文章:
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 视图中的参数推导失败:take_while
- 链接到自行创建的dll失败
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- gcc和c++17的过载解析失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 从父数组测试用例构造二叉树失败
- LibGit2 SSH身份验证失败
- 如何让LLDB在成功时退出,在失败时等待
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 生成MRPT库时cmake配置失败
- Sybase DB 错误:数据库驱动程序错误.发送失败
- 插入db失败