Question

When i figured out how to compile a simple program, now I have other problem ... I installed PostgreSQL and created database and table:

1) createdb testDB 2) create table cities (city varchar(80), location varchar(80));

And my still very simple program :

#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;

}

This code shows me only rows I already have in my testDB and doesn't show a row that I've just inserted. For example: in my testDB, in table cities, I have:

Warsaw Poland Berlin Germany Paris France

and above code shows me:

Warsaw Poland

but doesn't show:

Berlin Germany Paris France London UK

Please, help:(

Was it helpful?

Solution

So, adding commit after sql << "insert into cities values ('London', 'UK')"; solve this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top