The Oracle database reads the data as follows:
The code is as follows:
Constructs a node struct area{long ID; Long parent_area_id; String Area_name; Std::vector<area> Children;} Read the data of a struct area from the area table according to the ID void id2findareatree (Session ses, area& area, int id) {Statement select (SES); Select << "SELECT ID, parent_area_id,area_name from area where id =:p ID", Into (Area.id), into (area.parent_area_id), Into (Area.area_name), use (ID), now;} Read tree data from the area table void Parent_id2findareatree (Session ses, std::vector<area>& varea, int parent_id) { Varea.clear (); typedef poco::tuple<long, long, string> area; typedef std::vector<area> is; is AR; Statement Select (SES); Select << "SELECT ID, parent_area_id,area_name from area where parent_area_id =:p id", to (AR), use (parent_id), now; Are::const_iterator it = Ar.begin (); for (; it! = Ar.end (); ++it) {area area; Area.id = it->get<0> (); area.parent_area_id = it->get<1> (); Area.area_name = it->get<2> (); Varea.push_back (area); }}</span><pre name= "code" class= "CPP" ><span style= "FONT-SIZE:14PX;" >//build tree structure (entry function) session is a tool for connecting Oracle in Poco libraries void Cdlg::createtreectrl (session SES, long ID, area& area, Htreeitem H Item) {id2findareatree (SES, area, id); Htreeitem Hcurritem = M_tree. InsertItem (Area.area_name.c_str (), 0, 0, HItem, tvi_last);std::vector<area> temp; Parent_id2findareatree (SES, temp, id); Std::vector<area>::iterator it; for (it = Temp.begin (); It! = Temp.end (); it++) {Area A; Createtreectrl (SES, it->id, A, hcurritem); if (!a.area_name.empty ()) {area.children.push_back (a);}}} </span>//Finally, in the initialization function, call the entry function area Area;try {odbc::connector::registerconnector (); Session ses ("ODBC", "uid= user name; pwd= password; database= database name; dsn= configured DSN "); Createtreectrl (SES, 1, area, 0); Odbc::connector::unregisterconnector (); } catch (Connectionfailedexception e) {}
Results such as:
Run, it's done! Feel useful friends, remember to praise Oh ~
C + + reads data from the database and displays the data on the Treectrl on the interface