SHARE
TWEET

Untitled

a guest Jul 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <ios>
  3. #include <iomanip>
  4.  
  5.  
  6. // temporary
  7. #include <thread>
  8. #include <mutex>
  9.  
  10. #include <pqxx/pqxx>
  11.  
  12. #include "database.hpp"
  13.  
  14. void print_query(pqxx::result res, std::ostream & os = std::cout)
  15. {
  16.     const size_t width {20};
  17.  
  18.     // shows the names of columns
  19.     for (size_t i {0}; i < res.begin().size(); ++i)
  20.     {
  21.         if (! res.begin()[static_cast<int>(i)].is_null())
  22.             os << std::setw(width) << res.begin()[static_cast<int>(i)].name() << " | ";
  23.         else
  24.             os << std::setw(width) << "Null" << " | ";
  25.     }
  26.     os << std::endl;
  27.  
  28.     // prints data
  29.     for (auto iter {res.begin()}; iter != res.end(); ++iter)
  30.     {
  31.         for (size_t col {0}; col < iter[static_cast<int>(col)].size(); ++col)
  32.         {
  33.             if (! iter[static_cast<int>(col)].is_null())
  34.                 os << std::setw(width) << iter[static_cast<int>(col)].as<std::string>() << " | ";
  35.             else
  36.                 os << std::setw(width) << "Null" << " | ";
  37.         }
  38.         os << std::endl;
  39.     }
  40.  
  41. }
  42.  
  43. struct guard // guard
  44. {
  45. public:
  46.     guard() {std::cout << "ctor guard\n";}
  47.     ~guard() {std::cout << "dtor guard\n";}
  48.  
  49. private:
  50.  
  51. };
  52.  
  53. void foo()
  54. {
  55.     guard g = {};
  56.     std::cout << "enter foo\n";
  57.     try {
  58.        std::cout << "enter foo() try\n";
  59.        throw 42;
  60.        std::cout << "exit foo() try\n";
  61.     } catch (...) {
  62.         std::cout << "enter foo() catch\n";
  63.         throw 42; // uncomment this
  64.         std::cout << "exit foo() catch\n";
  65.     }
  66. }
  67.  
  68. void bar()
  69. {
  70.     try {
  71.        std::cout << "enter bar() try\n";
  72.        foo();
  73.        std::cout << "exit bar() try\n";
  74.     } catch (...) {
  75.         std::cout << "enter bar catch\n";
  76.         throw 42; // uncomment this
  77.         std::cout << "exit bar() catch\n";
  78.     }
  79. }
  80.  
  81. int main(int, char *argv[])
  82. {
  83.    /*try { // uncomment this
  84.         std::cout << "enter main() try\n";
  85.         bar();
  86.         std::cout << "exit main() try\n";
  87.     } catch (...) {
  88.         std::cout << "enter main() catch\n";
  89.         std::cout << "exit main() catch\n";
  90.     }
  91.     */
  92.     bar();
  93.  
  94. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top