Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Koncsik Milán - JXWFDH
- #include <algorithm>
- #include <string>
- #include <iostream>
- #include <sstream>
- #include "tree.hh"
- #include <pqxx/pqxx>
- using namespace std;
- using namespace pqxx;
- int main(int, char **)
- {
- char * sql;
- tree<string> tr;
- tree<string>::iterator root, cname,loc;
- //szintek létrehozása
- root=tr.insert(tr.begin(), "root");
- cname=tr.append_child(root, "cname");
- //végigmegy az 1. szinten
- loc=find(tr.begin(), tr.end(), "root");
- tree<string>::sibling_iterator sib=tr.begin(loc);
- //végigmegy a 2. szinten
- tree<string>::iterator loc1;
- loc1=find(tr.begin(),tr.end(),"cname");
- tree<string>::sibling_iterator sib2=tr.begin(loc);
- try
- {
- connection C("dbname = dbmkoncsik user = mkoncsik password = 123dbpass hostaddr = 195.70.37.11 port = 6081");
- if (C.is_open()) {
- cout << "Adatbázis: "<<C.dbname()<<" elérése sikeres. "<<endl;
- } else {
- cout << "Adatbázis elérése sikertelen." << endl;
- return 1;
- }
- sql = "select * from places";
- nontransaction N(C);
- result R( N.exec( sql ));
- for (result::const_iterator c = R.begin(); c != R.end(); ++c)
- {
- tr.insert_after(sib,c[2].as<string>());
- sib2=tr.append_child(sib,c[3].as<string>());
- tr.append_child(sib2,c[0].as<string>());
- sib++;
- }
- C.disconnect ();
- } catch (const std::exception &e) {
- cerr << e.what() << std::endl;
- return 1;
- }
- loc=find(tr.begin(), tr.end(), "root");
- tree<string>::iterator sib3=tr.begin(loc);
- tree<string>::iterator end3=tr.end(loc);
- while(sib3!=end3)
- {
- for(int i=0; i<tr.depth(sib3)-1; ++i)
- cout << '\t';
- cout << (*sib3) << endl;
- ++sib3;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement