Advertisement
Guest User

Untitled

a guest
Feb 4th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. //Koncsik Milán - JXWFDH
  2. #include <algorithm>
  3. #include <string>
  4. #include <iostream>
  5. #include <sstream>
  6. #include "tree.hh"
  7. #include <pqxx/pqxx>
  8.  
  9.  
  10. using namespace std;
  11. using namespace pqxx;
  12.  
  13.  
  14. int main(int, char **)
  15. {
  16.        char * sql;
  17.        tree<string> tr;
  18.        tree<string>::iterator root, cname,loc;
  19.  
  20.  
  21.         //szintek létrehozása
  22.        root=tr.insert(tr.begin(), "root");
  23.        cname=tr.append_child(root, "cname");
  24.  
  25.         //végigmegy az 1. szinten
  26.        loc=find(tr.begin(), tr.end(), "root");
  27.        tree<string>::sibling_iterator sib=tr.begin(loc);
  28.  
  29.         //végigmegy a 2. szinten
  30.        tree<string>::iterator loc1;
  31.        loc1=find(tr.begin(),tr.end(),"cname");
  32.        tree<string>::sibling_iterator sib2=tr.begin(loc);
  33.  
  34.  
  35.        try
  36.           {
  37.             connection C("dbname = dbmkoncsik user = mkoncsik password = 123dbpass hostaddr = 195.70.37.11 port = 6081");
  38.             if (C.is_open()) {
  39.                cout << "Adatbázis: "<<C.dbname()<<" elérése sikeres. "<<endl;
  40.             } else {
  41.                cout << "Adatbázis elérése sikertelen." << endl;
  42.                return 1;
  43.             }
  44.             sql = "select * from places";
  45.             nontransaction N(C);
  46.             result R( N.exec( sql ));
  47.             for (result::const_iterator c = R.begin(); c != R.end(); ++c)
  48.             {
  49.             tr.insert_after(sib,c[2].as<string>());
  50.             sib2=tr.append_child(sib,c[3].as<string>());
  51.             tr.append_child(sib2,c[0].as<string>());
  52.             sib++;
  53.             }
  54.             C.disconnect ();
  55.          } catch (const std::exception &e) {
  56.             cerr << e.what() << std::endl;
  57.             return 1;
  58.          }
  59.  
  60.        loc=find(tr.begin(), tr.end(), "root");
  61.        tree<string>::iterator sib3=tr.begin(loc);
  62.        tree<string>::iterator end3=tr.end(loc);
  63.        while(sib3!=end3)
  64.        {
  65.          for(int i=0; i<tr.depth(sib3)-1; ++i)
  66.             cout << '\t';
  67.          cout << (*sib3) << endl;
  68.          ++sib3;
  69.          }
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement