SOCI (SQL C++ wrapper) - PostgreSQL 不执行命令 (?)
SOCI (SQL C++ wrapper) - PostgreSQL doesn't execute commands (?)
当我知道如何编译一个简单的程序时,现在我有其他问题。。。我安装了PostgreSQL并创建了数据库和表:
1) createdb testDB 2)创建表城市(城市varchar(80),位置varchar(80));
还有我仍然非常简单的程序:
#include <iostream>
#include <soci.h>
#include <postgresql/soci-postgresql.h>
#include <string>
using namespace std;
int main(int argc, char **argv)
{
try
{
soci::session sql(soci::postgresql, "dbname=testDB");
string row = "";
sql << "select * from cities;", soci::into(row);
sql << "insert into cities values('London', 'UK')";
sql << "select * from cities;", soci::into(row);
cout << row << "n";
}
catch (soci::postgresql_soci_error const & e)
{
std::cerr << "PostgreSQL error: " << e.sqlstate() << " " << e.what() << std::endl;
}
catch (std::exception const & e)
{
std::cerr << "Some other error: " << e.what() << std::endl;
}
return 0;
}
这段代码只显示了testDB中已经存在的行,而没有显示刚刚插入的行。例如:在我的testDB中,在表城市中,我有:
波兰华沙德国柏林巴黎-法国
上面的代码告诉我:
华沙-波兰
但不显示:
德国柏林法国巴黎伦敦英国
请帮助:(
因此,在sql << "insert into cities values ('London', 'UK')";
之后添加提交解决这个问题。
相关文章:
- 使用QProcess执行命令,并将结果存储在QStringList中
- 如何在 Minecraft 服务器上执行命令
- 如何在C++中执行命令并获取命令的返回代码标准输出和标准
- 如何查看完整的CMD执行命令,包括参数和标志?
- CPP 中 z3 的编译和执行命令?
- 线程保持运行并执行命令
- 在 MinGW 和 MinGW-64 上执行命令后变量为空?
- popen() 将执行命令的输出写入 cout
- 如何在 Heroku 中的 Python 服务器上执行 "g++" 命令?
- 以普通用户身份执行命令
- 如何在生成之前在 cmake 中执行命令?
- 如何使用 c++ 在 cmd 中使用管理员权限执行命令
- 如何在Unix Shell中的后台执行命令
- 如何从连接的控制台执行命令
- 尝试在路由器上执行命令。C++ & libssh
- 在服务器上执行命令,然后将结果发送到Windows中的客户端
- 通过C编程打开终端并执行命令
- 在远程服务器上执行命令行命令
- 在Linux上使用c++执行命令时被阻止
- 使用popen执行命令