0
当我想出如何编译一个简单的程序时,现在我有其他问题了......我安装了PostgreSQL并创建了数据库和表格:SOCI(SQL C++ wrapper) - PostgreSQL不执行命令(?)
1)createdb testDB 2)创建表城市(city varchar(80),location 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,在表中的城市,我有:
波兰华沙 德国柏林 法国巴黎
和上面的代码显示了我:
波兰华沙
但未显示:
德国柏林 法国巴黎 英国伦敦
请帮助:(
如何在第二次选择之前提交? – ForEveR 2012-07-11 15:31:42
@ForEveR:嗯,这段代码:http://pastie.org/private/y89269ea8u3vhif0m1adcw显示我'华沙'两次...看一看:http://pastie.org/private/i1ejnzyenmvwgvjios2ja – 2012-07-11 15:40:23
@ForEveR:geez , 谢谢哥们 ! ^^它完美的工作:D我刚刚在'sql <<“插入到城市值('London','UK')”;'并且它现在正在工作:)中添加'sql.commit();' – 2012-07-11 15:50:52