/[H9]/trunk/tntnet/dynamic/critical.ecpp
ViewVC logotype

Annotation of /trunk/tntnet/dynamic/critical.ecpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 195 - (hide annotations) (download)
Sat Dec 8 16:47:03 2007 UTC (16 years, 5 months ago) by torben
File size: 2094 byte(s)
Use persistant connections / connection pooling for faster db access

1 torben 71 <%pre>
2     #include <tntdb/connect.h>
3     #include <tntdb/connection.h>
4     #include <tntdb/result.h>
5     #include <tntdb/row.h>
6 torben 104
7 torben 71 </%pre>
8    
9 torben 68 <%config>
10     dburl;
11     </%config>
12    
13     <&header title="Critical systems">
14     </&header>
15 torben 104 <h2>Critical systems</h2>
16    
17 torben 71 <{
18 torben 68
19 torben 145 reply.setHeader("Refresh", "120");
20    
21 torben 195 tntdb::Connection conn = tntdb::connectCached(dburl);
22 torben 104
23    
24 torben 122 std::string query1;
25 torben 156 query1 += "SELECT c.name, i.description, i.id, i.commerror ";
26 torben 122 query1 += "FROM installation i INNER JOIN customer c ";
27     query1 += "ON i.customerid = c.id";
28 torben 111
29 torben 122
30     tntdb::Result inst_res = conn.select(query1);
31    
32    
33     std::string query2;
34 torben 156 query2 += "SELECT temperature,flamedetector,conveyorerror,powerfailure ";
35 torben 122 query2 += "FROM logtable ";
36     query2 += "WHERE installationnr = :v1 ";
37 torben 159 query2 += "ORDER BY messagenr DESC,logtime DESC ";
38 torben 122 query2 += "LIMIT 1";
39    
40 torben 156
41 torben 122 tntdb::Statement st = conn.prepare(query2);
42    
43     std::ostream& out = reply.out();
44    
45 torben 129 bool hasCritical = false;
46    
47 torben 126 for (unsigned i=0; i<inst_res.size(); i++)
48 torben 122 {
49     int id = inst_res[i].getInt(2);
50     st.clear();
51    
52     st.setInt("v1", id);
53     tntdb::Result res = st.select();
54    
55 torben 156 bool commerror = inst_res[i].getBool(3);
56     int temperature = 50;
57     bool flameDetector = true;
58     bool conveyorError = false;
59     bool powerFailure = false;
60    
61 torben 122 if (res.size() > 0)
62     {
63 torben 156 temperature = res[0].getInt(0);
64     flameDetector = res[0].getBool(1);
65     conveyorError = res[0].getBool(2);
66     powerFailure = res[0].getBool(3);
67     }
68 torben 122
69 torben 156 if (commerror || temperature > 90 || flameDetector == false || conveyorError || powerFailure)
70     {
71     out << "<a href='installationdetails?id=" << id << "'><b>" << inst_res[i].getString(0) << "</b> : " << inst_res[i].getString(1) << "<br></a>\n";
72     out << "<ul>";
73 torben 122
74 torben 156 if (temperature > 90)
75     out << "<li>High temperature</li>\n";
76 torben 122
77 torben 156 if (commerror)
78     out << "<li>Communication error</li>\n";
79 torben 122
80 torben 156 if (flameDetector == false)
81     out << "<li>No flames</li>\n";
82 torben 122
83 torben 156 if (conveyorError)
84     out << "<li>Conveyor error</li>\n";
85 torben 122
86 torben 156 if (powerFailure)
87     out << "<li>Power failure</li>\n";
88 torben 122
89 torben 156 out << "</ul>\n";
90 torben 122
91 torben 156 hasCritical = true;
92 torben 122 }
93     }
94    
95 torben 129 if (hasCritical == false)
96     {
97     out << "<i>No critical installations found</i>\n";
98     }
99    
100 torben 71 }>
101    
102 torben 68 <&footer>
103     </&footer>

  ViewVC Help
Powered by ViewVC 1.1.20