繁体   English   中英

SOCI(SQL C ++包装器) - 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')";之后添加提交sql << "insert into cities values ('London', 'UK')"; 解决这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM