Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ios>
- #include <iomanip>
- // temporary
- #include <thread>
- #include <mutex>
- #include <pqxx/pqxx>
- #include "database.hpp"
- void print_query(pqxx::result res, std::ostream & os = std::cout)
- {
- const size_t width {20};
- // shows the names of columns
- for (size_t i {0}; i < res.begin().size(); ++i)
- {
- if (! res.begin()[static_cast<int>(i)].is_null())
- os << std::setw(width) << res.begin()[static_cast<int>(i)].name() << " | ";
- else
- os << std::setw(width) << "Null" << " | ";
- }
- os << std::endl;
- // prints data
- for (auto iter {res.begin()}; iter != res.end(); ++iter)
- {
- for (size_t col {0}; col < iter[static_cast<int>(col)].size(); ++col)
- {
- if (! iter[static_cast<int>(col)].is_null())
- os << std::setw(width) << iter[static_cast<int>(col)].as<std::string>() << " | ";
- else
- os << std::setw(width) << "Null" << " | ";
- }
- os << std::endl;
- }
- }
- struct guard // guard
- {
- public:
- guard() {std::cout << "ctor guard\n";}
- ~guard() {std::cout << "dtor guard\n";}
- private:
- };
- void foo()
- {
- guard g = {};
- std::cout << "enter foo\n";
- try {
- std::cout << "enter foo() try\n";
- throw 42;
- std::cout << "exit foo() try\n";
- } catch (...) {
- std::cout << "enter foo() catch\n";
- throw 42; // uncomment this
- std::cout << "exit foo() catch\n";
- }
- }
- void bar()
- {
- try {
- std::cout << "enter bar() try\n";
- foo();
- std::cout << "exit bar() try\n";
- } catch (...) {
- std::cout << "enter bar catch\n";
- throw 42; // uncomment this
- std::cout << "exit bar() catch\n";
- }
- }
- int main(int, char *argv[])
- {
- /*try { // uncomment this
- std::cout << "enter main() try\n";
- bar();
- std::cout << "exit main() try\n";
- } catch (...) {
- std::cout << "enter main() catch\n";
- std::cout << "exit main() catch\n";
- }
- */
- bar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement