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

Annotation of /trunk/tntnet/dynamic/customerlist.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: 1918 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    
7     #include "common.h"
8 torben 74
9     #include <sstream>
10 torben 71 </%pre>
11    
12     <%config>
13     dburl;
14     </%config>
15    
16 torben 104 <&header title="Customers and installations">
17 torben 71 </&header>
18    
19     <h2>Customers and installations</h2>
20    
21     <{
22     tntdb::Connection conn;
23    
24 torben 195 conn = tntdb::connectCached(dburl); //letting exceptions flow up and to tntnet and let it display an error message
25 torben 71
26     std::string customer_sql = "SELECT id,name,address,phonenr,contactperson FROM customer ORDER BY name ASC";
27    
28     tntdb::Result res = conn.select(customer_sql);
29    
30     std::ostream& out = reply.out();
31    
32     if (res.size() != 0)
33     {
34     for (tntdb::Result::const_iterator it = res.begin(); it != res.end(); ++it)
35     {
36     tntdb::Row row = *it;
37 torben 74 int customerid = row.getInt(0);
38     out << "<table border=1 width='80%' cellspacing=0 align=center><tr><td>";
39 torben 71 out << "<b>" << row.getString(1) << "</b><br>\n\n";
40    
41    
42 torben 74 out << nl2br(trim(row.getString(2))) << "<br>\n";
43 torben 71
44 torben 74 out << "<i>Phone:</i> " << row.getString(3) << "<br>\n";
45     out << "<i>Contact:</i> " << row.getString(4) << "<br>\n";
46 torben 71
47 torben 74 out << "<br>\n";
48    
49    
50     std::stringstream sqlstream;
51     sqlstream << "SELECT id, description FROM installation ";
52     sqlstream << "WHERE customerid = " << customerid;
53 torben 104 sqlstream << " ORDER BY description ASC";
54 torben 74
55     tntdb::Result instres = conn.select(sqlstream.str());
56    
57     if (instres.size() > 0)
58     {
59     out << "Installations:\n";
60 torben 122 out << "<ol>\n";
61 torben 74 for (tntdb::Result::const_iterator instit = instres.begin(); instit != instres.end(); ++instit)
62     {
63     tntdb::Row instrow = *instit;
64     out << "<li><a href='installationdetails?id=" << instrow.getString(0) << "'>";
65     out << instrow.getString(1) << "</a></li>";
66     }
67     out << "</ol>\n";
68     }
69     else
70     {
71     out << "<i>No installations !</i>\n";
72     }
73    
74    
75    
76    
77    
78 torben 71 out << "</td></tr></table><br>\n";
79    
80     }
81     }
82     else
83     {
84     out << "<i>No customer records found!</i>";
85     }
86    
87     }>
88    
89     <&footer>
90     </&footer>

  ViewVC Help
Powered by ViewVC 1.1.20