1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#!/bin/sh
cat <<EOF >import.cpp
#include <iostream>
#include <pqxx/pqxx>
int main()
{
try
{
pqxx::connection C;
std::cout << "Connected to " << C.dbname() << std::endl;
pqxx::work W(C);
pqxx::result R = W.exec("SELECT name FROM employee");
std::cout << "Found " << R.size() << "employees:" << std::endl;
for (auto row: R)
std::cout << row[0].c_str() << std::endl;
std::cout << "Doubling all employees' salaries..." << std::endl;
W.exec("UPDATE employee SET salary = salary*2");
std::cout << "Making changes definite: ";
W.commit();
std::cout << "OK." << std::endl;
}
catch (const std::exception &e)
{
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}
EOF
/usr/bin/g++ import.cpp -lpq -lpqxx -o test-import
|