Merge branch 'master' of git@localhost:sqlgg
[sqlgg.git] / test_pqxx / client_pqxx.cpp
blob406e3ba7cbb2ad3efbd942e5487b9ab2a06e5de6
1 #include <iostream>
2 #include <pqxx/pqxx>
4 using namespace std;
5 using namespace pqxx;
7 int main()
9 try
11 connection C("dbname=test");
12 cout << "Connected to " << C.dbname() << endl;
13 work W(C);
15 result R;
16 R = W.exec("DROP TABLE employee");
17 R = W.exec("CREATE TABLE employee (id SERIAL PRIMARY KEY, name TEXT, salary INT)");
19 C.prepare("ins","INSERT INTO employee (name,salary) VALUES($1,$2)")
20 ("varchar",prepare::treat_string)
21 ("varchar",prepare::treat_direct);
22 prepare::invocation* call = &W.prepared("ins");
23 call->operator()("john")(2).exec();
25 R = W.prepared("ins")("jack")(3).exec();
26 R = W.prepared("ins")("bob")(4).exec();
27 R = W.exec("SELECT name FROM employee");
29 cout << "Found " << R.size() << " employees:" << endl;
30 for (result::const_iterator r = R.begin();
31 r != R.end();
32 ++r)
34 cout << r[0].c_str() << endl;
37 cout << "Doubling all employees' salaries..." << endl;
38 W.exec("UPDATE employee SET salary=salary*2");
40 cout << "Making changes definite: ";
41 W.commit();
43 cout << "ok." << endl;
45 catch (const exception &e)
47 cerr << e.what() << endl;
48 return 1;
50 return 0;